[Lldb-commits] [PATCH] D87730: [intel-pt] Pretty print the instruction list

walter erquinigo via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 15 16:50:33 PDT 2020


wallace created this revision.
wallace added a reviewer: clayborg.
Herald added subscribers: lldb-commits, dang.
Herald added a reviewer: JDevlieghere.
Herald added a project: LLDB.
wallace requested review of this revision.

Depends on D87589 <https://reviews.llvm.org/D87589>.

In D87589 <https://reviews.llvm.org/D87589> I added the basic instruction decoding functionality and the Dump action was printing the raw strings. I'm now pretty printing the instructions, with an output like the following:

  pid: '1234', tid: '1981309'
    a.out`main
    [57] 0x400549 <+13>: movl   %eax, -0x4(%rbp)
    a.out`bar()
    [56] 0x40053b <+46>: retq
    [55] 0x40053a <+45>: leave
    [54] 0x400537 <+42>: movl   -0x4(%rbp), %eax
    [53] 0x400535 <+40>: jle    0x400525                  ; <+24> at main.cpp:7
    [52] 0x400531 <+36>: cmpl   $0x3, -0x8(%rbp)
    [51] 0x40052d <+32>: addl   $0x1, -0x8(%rbp)
    [50] 0x40052a <+29>: addl   %eax, -0x4(%rbp)
    a.out`foo()
    [49] 0x400567 <+15>: retq
    [48] 0x400566 <+14>: popq   %rbp
    [47] 0x400563 <+11>: movl   -0x4(%rbp), %eax
    [46] 0x40055c <+4>: movl   $0x2a, -0x4(%rbp)
    [45] 0x400559 <+1>: movq   %rsp, %rbp
    [44] 0x400558 <+0>: pushq  %rbp

There's also a --raw flag that prints simply the instructions.

An important remark is that the decoder can fail to decode some instructions, which we are printing, for example:

pid: '1234', tid: '3842849'

  [4] 0x400529 <+28>: cmpl   $0x3, -0x8(%rbp)
  [3] error -13. 'no memory mapped at this address'
  [2] 0x40052d <+32>: jle    0x400521  

As an implementation note, I'm using lldb's Disassembler. I couldn't move the entire printing logic to the disassembler because it assumes that all instuctions printed are valid, which conflicts with what the intel-pt decoder outputs.

Finally, the instruction dumping command is as follows:

  trace dump -i [-rv] [-c <count>] [-o <offset>] [-t <thread-id>]


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87730

Files:
  lldb/include/lldb/Core/Disassembler.h
  lldb/include/lldb/Target/Trace.h
  lldb/source/Commands/CommandObjectTrace.cpp
  lldb/source/Commands/Options.td
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/test/API/commands/trace/TestTraceDump.py
  lldb/test/API/commands/trace/intelpt-trace-multi-function/a.out
  lldb/test/API/commands/trace/intelpt-trace-multi-function/main.cpp
  lldb/test/API/commands/trace/intelpt-trace-multi-function/multi-function.trace
  lldb/test/API/commands/trace/intelpt-trace-multi-function/other.cpp
  lldb/test/API/commands/trace/intelpt-trace-multi-function/other.h
  lldb/test/API/commands/trace/intelpt-trace-multi-function/trace.json

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87730.292059.patch
Type: text/x-patch
Size: 17266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200915/b58952eb/attachment-0001.bin>


More information about the lldb-commits mailing list