This is an archive of the discontinued LLVM Phabricator instance.

Add comments to LLDB-MI disassembly.
ClosedPublic

Authored by ki.stfu on Apr 10 2015, 3:01 AM.

Details

Summary

This patch adds the comments which are included in LLDB disassembly, but are currently missing in MI, e.g.

^done,asm_insns=[...,{address="0x00000000004004ff",func-name="main",offset="18",size="2",inst="jmp 0x40050b ; <+30> at main.c:7"}]

instead of

^done,asm_insns=[...,{address="0x00000000004004ff",func-name="main",offset="18",size="2",inst="jmp 0x40050b"}]

Thanks, Ewan

Patch from ewan@codeplay.com

Diff Detail

Repository
rL LLVM

Event Timeline

EwanCrawford retitled this revision from to Add comments to LLDB-MI disassembly. .
EwanCrawford updated this object.
EwanCrawford edited the test plan for this revision. (Show Details)
EwanCrawford added a reviewer: ki.stfu.
EwanCrawford set the repository for this revision to rL LLVM.
EwanCrawford added subscribers: deepak2427, Unknown Object (MLST).
ki.stfu requested changes to this revision.Apr 10 2015, 8:05 AM
ki.stfu edited edge metadata.

Looks like you want to implement the -data-disassemble command for mode=1 (see https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Data-Manipulation.html).

I against to add a comment into the "inst" field. I think you should use the mode=1 (or 3) option to get the "line" and "file" fields. It will look like the following:

(gdb)
-data-disassemble -f basics.c -l 32 -n 3 -- 1
^done,asm_insns=[
src_and_asm_line={line="31",
file="../../../src/gdb/testsuite/gdb.mi/basics.c",
fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
line_asm_insn=[{address="0x000107bc",
func-name="main",offset="0",inst="save  %sp, -112, %sp"}]},
src_and_asm_line={line="32",
file="../../../src/gdb/testsuite/gdb.mi/basics.c",
fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
line_asm_insn=[{address="0x000107c0",
func-name="main",offset="4",inst="mov  2, %o0"},
{address="0x000107c4",func-name="main",offset="8",
inst="sethi  %hi(0x11800), %o2"}]}]
(gdb)
This revision now requires changes to proceed.Apr 10 2015, 8:05 AM
ted added a subscriber: ted.EditedApr 10 2015, 1:35 PM

The comment isn't there to get line and file; it's there to get symbolic branch targets.

Disassembling with the patch looks like this:

-data-disassemble --thread 1 -s 0x5164 -e 0x5165 -- 1
^done,asm_insns=[src_and_asm_line={line="34",file="factorial.c",line_asm_insn=[{address="0x00005164",func-name="main",offset="0",size="4",inst="{ call 0x52a0 }        ; printf"}]}]

Without the patch it looks like this:

-data-disassemble --thread 1 -s 0x5164 -e 0x5165 -- 1
^done,asm_insns=[src_and_asm_line={line="34",file="factorial.c",line_asm_insn=[{address="0x00005164",func-name="main",offset="0",size="4",inst="{ call 0x52a0 }"}]}]
In D8964#154945, @ted wrote:

The comment isn't there to get line and file; it's there to get symbolic branch targets.

If so then create a separate field named "comment" and use it for comments. Also, update the MIExtensions.txt please.

ted added a comment.EditedApr 10 2015, 2:54 PM
In D8964#154945, @ted wrote:

The comment isn't there to get line and file; it's there to get symbolic branch targets.

If so then create a separate field named "comment" and use it for comments. Also, update the MIExtensions.txt please.

It's not really an MI extension - disassembly of change-of-flow instructions isn't listed in the gdb-mi docs, but gdb prints the symbol out following the jump target. It looks like this:

{address="0x1d04c55c",func-name="wait_for_int",offset="48",inst="5cffe0ec     if !p0 jump 0x1d04c534 <wait_for_int+8>"}
In D8964#154998, @ted wrote:

It's not really an MI extension - disassembly of change-of-flow instructions isn't listed in the gdb-mi docs, but gdb prints the symbol out following the jump target. It looks like this:

{address="0x1d04c55c",func-name="wait_for_int",offset="48",inst="5cffe0ec     if !p0 jump 0x1d04c534 <wait_for_int+8>"}

On OS X the -data-disassemble commands shows the following:

{address="0x0000000100000f0e",func-name="main",offset="225",size="2",inst="movb $0x0, %al"},{address="0x0000000100000f10",func-name="main",offset="227",size="5",inst="callq 0x100000f36"},{address="0x0000000100000f15",func-name="main",offset="232",size="3",inst="movl %eax, -0x54(%rbp)"}

With your patch the output is:

{address="0x0000000100000ee0",func-name="main",offset="179",size="5",inst="callq 0x100000f36		; symbol stub for: printf"}

But these spaces annoy me. I really don't want to use the '\t' char in lldb-mi output. May be we can use the following format?

416      strComment = CMIUtilString::Format("<%s>", pStrComment);

or

416      strComment = CMIUtilString::Format("; %s", pStrComment);

And the output will be the following:

{address="0x0000000100000f0e",func-name="main",offset="225",size="2",inst="movb $0x0, %al"},{address="0x0000000100000f10",func-name="main",offset="227",size="5",inst="callq 0x100000f36; symbol stub for: printf"},{address="0x0000000100000f15",func-name="main",offset="232",size="3",inst="movl %eax, -0x54(%rbp)"}
tools/lldb-mi/MICmdCmdData.cpp
416 ↗(On Diff #23582)

here

ted added a comment.Apr 13 2015, 8:28 AM

The spaces bother me too. Ewan, please remove them.

EwanCrawford edited edge metadata.

Thanks for the feedback, I've removed the spaces as requested.
Sorry for the delayed update.

ki.stfu accepted this revision.Apr 15 2015, 7:07 AM
ki.stfu edited edge metadata.

Should I commit it for you?

This revision is now accepted and ready to land.Apr 15 2015, 7:07 AM

That would be great thanks.

ki.stfu commandeered this revision.Apr 15 2015, 9:18 AM
ki.stfu edited reviewers, added: EwanCrawford; removed: ki.stfu.
This revision now requires review to proceed.Apr 15 2015, 9:18 AM
ki.stfu updated this revision to Diff 23779.Apr 15 2015, 9:19 AM
ki.stfu retitled this revision from Add comments to LLDB-MI disassembly. to Add comments to LLDB-MI disassembly..

Rebase against ToT

ki.stfu updated this object.Apr 15 2015, 9:20 AM
This revision was automatically updated to reflect the committed changes.