This is an archive of the discontinued LLVM Phabricator instance.

[intel-pt] Fix existing support in LLDB
ClosedPublic

Authored by wallace on Mar 26 2020, 11:17 AM.

Details

Summary

https://reviews.llvm.org/D33035 added in 2017 basic support for intel-pt. I plan to improve it and use it to support reverse debugging.

I fixed a couple of issues and now this plugin works again:

  1. pythonlib needed to be linked against it for the SB framework. Linking was failing because of this
  2. the decoding functionality was broken because it lacked handling for instruction events. It seems old versions of libipt, the actual decoding library, didn't require these, but modern version require it (you can read more here https://github.com/intel/libipt/blob/master/doc/howto_libipt.md). These events signal overflows of the internal PT buffer in the CPU, enable/disable events of tracing, async cpu events, interrupts, etc.

I ended up refactoring a little bit the code to reduce code duplication.

In another diff I'll implement some basic tests.

This is a simple execution of the library:

(lldb) target create "/data/users/wallace/rr-project/a.out"
Current executable set to '/data/users/wallace/rr-project/a.out' (x86_64).
(lldb) plugin load liblldbIntelFeatures.so
(lldb) b main
Breakpoint 1: where = a.out`main + 8 at test.cpp:10, address = 0x00000000004007fa
(lldb) b test.cpp:14
Breakpoint 2: where = a.out`main + 50 at test.cpp:14, address = 0x0000000000400824
(lldb) r
Process 902754 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x00000000004007fa a.out`main at test.cpp:10
   7    }
   8   
   9    int main() {
-> 10     int z = 0;
   11     for(int i = 0; i < 10000; i++)
   12       z += fun(z);
   13  

Process 902754 launched: '/data/users/wallace/rr-project/a.out' (x86_64)
(lldb) processor-trace start all
(lldb) c
Process 902754 resuming
Process 902754 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 2.1
    frame #0: 0x0000000000400824 a.out`main at test.cpp:14
   11     for(int i = 0; i < 10000; i++)
   12       z += fun(z);
   13  
-> 14     cout << z<< endl;
   15     return 0;
   16   }

(lldb) processor-trace show-instr-log
thread #1: tid=902754
    0x7ffff72299b9 <+9>: addq   $0x8, %rsp
    0x7ffff72299bd <+13>: retq   
    0x4007ed <+16>: addl   $0x1, %eax
    0x4007f0 <+19>: leave  
    0x4007f1 <+20>: retq   
    0x400814 <+34>: addl   %eax, -0x4(%rbp)
    0x400817 <+37>: addl   $0x1, -0x8(%rbp)
    0x40081b <+41>: cmpl   $0x270f, -0x8(%rbp)       ; imm = 0x270F 
    0x400822 <+48>: jle    0x40080a                  ; <+24> at test.cpp:12
    0x400822 <+48>: jle    0x40080a                  ; <+24> at test.cpp:12

Diff Detail

Event Timeline

wallace created this revision.Mar 26 2020, 11:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 26 2020, 11:17 AM
wallace retitled this revision from [intel-pt] fix python building to [intel-pt] Fix existing support in LLDB.Mar 26 2020, 11:39 AM
wallace edited the summary of this revision. (Show Details)
wallace added reviewers: clayborg, aadsm, kusmour.

Looks fine to me, but the original author should probably approve this

wallace updated this revision to Diff 252936.Mar 26 2020, 12:14 PM

update commit message

His last activity was in Jun 2017. I hope he's still around.

aadsm accepted this revision.Mar 30 2020, 1:10 PM
This revision is now accepted and ready to land.Mar 30 2020, 1:10 PM
wallace updated this revision to Diff 253684.Mar 30 2020, 1:29 PM

merge the commits of this diff

labath accepted this revision.Mar 31 2020, 12:18 AM
This revision was automatically updated to reflect the committed changes.