135 lines · python
1import lldb2from intelpt_testcase import *3from lldbsuite.test.lldbtest import *4from lldbsuite.test import lldbutil5from lldbsuite.test.decorators import *6 7 8class TestTraceEvents(TraceIntelPTTestCaseBase):9 @testSBAPIAndCommands10 def testCPUEvents(self):11 trace_description_file_path = os.path.join(12 self.getSourceDir(),13 "intelpt-multi-core-trace",14 "trace_missing_threads.json",15 )16 self.traceLoad(17 traceDescriptionFilePath=trace_description_file_path, substrs=["intel-pt"]18 )19 20 self.expect(21 "thread trace dump instructions 3 -e --forward -c 5",22 substrs=[23 """thread #3: tid = 349749624 0: (event) HW clock tick [40450075477621505]25 1: (event) CPU core changed [new CPU=51]26 2: (event) HW clock tick [40450075477657246]27 3: (event) trace synchronization point [offset = 0x0x1331]28 m.out`foo() + 65 at multi_thread.cpp:12:21"""29 ],30 )31 32 self.expect(33 "thread trace dump instructions 3 -e --forward -c 5 -J",34 substrs=[35 """{36 "id": 0,37 "event": "HW clock tick",38 "hwClock": 4045007547762150539 },40 {41 "id": 1,42 "event": "CPU core changed",43 "cpuId": 5144 }"""45 ],46 )47 48 @skipIfNoIntelPT49 @testSBAPIAndCommands50 def testPauseEvents(self):51 """52 Everytime the target stops running on the CPU, a 'disabled' event will53 be emitted, which is represented by the TraceCursor API as a 'paused'54 event.55 """56 self.expect(57 "target create "58 + os.path.join(self.getSourceDir(), "intelpt-trace-multi-file", "a.out")59 )60 self.expect("b 12")61 self.expect("r")62 self.traceStartThread()63 self.expect("n")64 self.expect("n")65 self.expect("si")66 self.expect("si")67 self.expect("si")68 # We ensure that the paused events are printed correctly forward69 self.expect(70 "thread trace dump instructions -e -f",71 patterns=[72 rf"""thread #1: tid = .*73 0: \(event\) trace synchronization point \[offset \= 0x0xec0\]74 1: \(event\) hardware disabled tracing75 a.out`main \+ 23 at main.cpp:1276 2: {ADDRESS_REGEX} movl .*77 3: \(event\) software disabled tracing78 4: {ADDRESS_REGEX} addl .*79 5: {ADDRESS_REGEX} movl .*80 6: \(event\) software disabled tracing81 a.out`main \+ 34 \[inlined\] inline_function\(\) at main.cpp:482 7: {ADDRESS_REGEX} movl .*83 a.out`main \+ 41 \[inlined\] inline_function\(\) \+ 7 at main.cpp:584 8: {ADDRESS_REGEX} movl .*85 9: {ADDRESS_REGEX} addl .*86 10: {ADDRESS_REGEX} movl .*87 a.out`main \+ 52 \[inlined\] inline_function\(\) \+ 18 at main.cpp:688 11: {ADDRESS_REGEX} movl .*89 a.out`main \+ 55 at main.cpp:1490 12: {ADDRESS_REGEX} movl .*91 13: {ADDRESS_REGEX} addl .*92 14: {ADDRESS_REGEX} movl .*93 15: \(event\) software disabled tracing94 a.out`main \+ 63 at main.cpp:1695 16: {ADDRESS_REGEX} callq .* ; symbol stub for: foo\(\)96 17: \(event\) software disabled tracing97 a.out`symbol stub for: foo\(\)98 18: {ADDRESS_REGEX} jmpq"""99 ],100 )101 102 # We ensure that the paused events are printed correctly backward103 self.expect(104 "thread trace dump instructions -e --id 18",105 patterns=[106 rf"""thread #1: tid = .*107 a.out`symbol stub for: foo\(\)108 18: {ADDRESS_REGEX} jmpq .*109 17: \(event\) software disabled tracing110 a.out`main \+ 63 at main.cpp:16111 16: {ADDRESS_REGEX} callq .* ; symbol stub for: foo\(\)112 15: \(event\) software disabled tracing113 a.out`main \+ 60 at main.cpp:14114 14: {ADDRESS_REGEX} movl .*115 13: {ADDRESS_REGEX} addl .*116 12: {ADDRESS_REGEX} movl .*117 a.out`main \+ 52 \[inlined\] inline_function\(\) \+ 18 at main.cpp:6118 11: {ADDRESS_REGEX} movl .*119 a.out`main \+ 49 \[inlined\] inline_function\(\) \+ 15 at main.cpp:5120 10: {ADDRESS_REGEX} movl .*121 9: {ADDRESS_REGEX} addl .*122 8: {ADDRESS_REGEX} movl .*123 a.out`main \+ 34 \[inlined\] inline_function\(\) at main.cpp:4124 7: {ADDRESS_REGEX} movl .*125 6: \(event\) software disabled tracing126 a.out`main \+ 31 at main.cpp:12127 5: {ADDRESS_REGEX} movl .*128 4: {ADDRESS_REGEX} addl .*129 3: \(event\) software disabled tracing130 2: {ADDRESS_REGEX} movl .*131 1: \(event\) hardware disabled tracing132 0: \(event\) trace synchronization point \[offset \= 0x0xec0\]"""133 ],134 )135