This is an archive of the discontinued LLVM Phabricator instance.

[trace] Add SBTraceCursor bindings
ClosedPublic

Authored by jj10306 on Aug 1 2022, 12:43 PM.

Details

Summary

Add bindings for the TraceCursor to allow for programatic traversal of
traces.
This diff adds bindings for all public TraceCursor methods except
GetHwClock and also adds SBTrace::CreateNewCursor. A new unittest
has been added to TestTraceLoad.py that uses the new SBTraceCursor API
to test that the sequential and random access APIs of the TraceCursor
are equivalent.

This diff depends on D130925.

Test Plan:
ninja lldb-dotest && ./bin/lldb-dotest -p TestTraceLoad

Diff Detail

Event Timeline

jj10306 created this revision.Aug 1 2022, 12:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 12:43 PM
Herald added a subscriber: mgorny. · View Herald Transcript
jj10306 requested review of this revision.Aug 1 2022, 12:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 12:43 PM
JDevlieghere added inline comments.Aug 1 2022, 12:48 PM
lldb/include/lldb/API/SBTraceCursor.h
2–3

Broken ASCII art

lldb/source/API/SBTrace.cpp
47

There should be a newline after LLDB_INSTRUMENT_VA to match the output of lldb-instr.

wallace requested changes to this revision.Aug 1 2022, 1:12 PM

pretty nice!! Just some few minor changes and good to go

lldb/bindings/interface/SBTraceCursor.i
2–8

the first and last lines should have 80 cols

62

add an IsValid method. It's common in the SB API to offer such method as an alternative to heck the error object.

lldb/include/lldb/API/SBTrace.h
38–39
lldb/include/lldb/API/SBTraceCursor.h
2–3

fix this

167

The event eTraceEventNone was deleted, so don't mention it here.

182–183

yes, you should. And you can set it to -1

lldb/source/API/SBTrace.cpp
48–51

you should have one error for invalid thread and one for invalid trace

lldb/source/API/SBTraceCursor.cpp
18–19

no need to mention this. You can just create a invalid SBTraceCursor. Don't forget to add the IsValid method

64–65

You should instead create a new public enumeration TraceCursorSeekType. That will simplify the code

120–121

yes, define a LLDB_INVALID_CPU_ID and don't return an error here

lldb/test/API/commands/trace/TestTraceLoad.py
342–346

add one more test that simply walks through a few items expecting some hardcoded values. That kind of test are easier to fix when something minor breaks. The other kind of tests, like the one you just wrote above, are more complicated to fix but they are much stronger test. Both kinds of tests are useful

This revision now requires changes to proceed.Aug 1 2022, 1:12 PM
jj10306 marked 13 inline comments as done.Aug 2 2022, 7:30 AM
jj10306 added inline comments.
lldb/include/lldb/API/SBTraceCursor.h
167

thanks - this is copypasta from TraceCursor.h, so I'll go ahead and fix this here and there

lldb/source/API/SBTrace.cpp
47

thanks for catching this!

lldb/source/API/SBTraceCursor.cpp
18–19

oops I added this as a reference when I was exploring adding the bindings before changing to using SP and forgot to delete it. will remove - thanks!

64–65

I was leaning towards this while adding the bindings, so yea will do.

jj10306 updated this revision to Diff 449289.Aug 2 2022, 7:30 AM
jj10306 marked 4 inline comments as done.
  1. address comments
  2. rebase
  3. minor changes to DecodedThread::GetInstructionLoadAddress and DecodedThread::GetErrorByIndex
jj10306 added inline comments.Aug 2 2022, 8:52 AM
lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
198

what's the best return value if this is called and the item isn't an event?
ideally we could return something similar to LLDB_INVALID_ADDRESS, but since this is an enum we would need to add a new variant that represents the "invalid" case. Perhaps we could bring back the eTraceEventNone variant that was recently removed?
wdyt?

wallace added inline comments.Aug 2 2022, 12:30 PM
lldb/bindings/interface/SBTraceCursor.i
57

+1

lldb/include/lldb/API/SBTraceCursor.h
22

+1

lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
198

I was thinking about that and I think a better contract is to expect users not to use a getter that is unrelated to the current trace type. If we don't add strict expectations, then consumers might create buggy code without realizing.

230–231

like this. It might be better just to fail or return garbage and that will let the user know that they are doing something they shouldn't.

Besides that, in c++ it's easy to look for nullptr when getting char *, but in python, this might be converted eventually to an actual empty str, and that might hide some possible bugs.

jj10306 updated this revision to Diff 449461.Aug 2 2022, 3:31 PM
jj10306 marked 4 inline comments as done.

Revert changes to DecodedThread trace item getter API's

wallace accepted this revision.Aug 2 2022, 4:37 PM

yaay

This revision is now accepted and ready to land.Aug 2 2022, 4:37 PM
This revision was automatically updated to reflect the committed changes.