This is an archive of the discontinued LLVM Phabricator instance.

[intel-pt] Pretty print the instruction list
AbandonedPublic

Authored by wallace on Sep 15 2020, 4:50 PM.

Details

Summary

Depends on D87589.

In 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 addresses.

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>]

Diff Detail

Event Timeline

wallace created this revision.Sep 15 2020, 4:50 PM
Herald added a project: Restricted Project. · View Herald Transcript
wallace requested review of this revision.Sep 15 2020, 4:50 PM
wallace updated this revision to Diff 292060.Sep 15 2020, 4:59 PM

remove whitespace changes

wallace edited the summary of this revision. (Show Details)Sep 19 2020, 10:10 PM
wallace planned changes to this revision.Oct 9 2020, 12:15 AM
wallace abandoned this revision.Oct 23 2020, 12:45 PM