[lldb-dev] Function tracing

jingham at apple.com jingham at apple.com
Mon Feb 23 11:08:01 PST 2015


> On Feb 22, 2015, at 7:42 PM, Bruce Mitchener <bruce.mitchener at gmail.com> wrote:
> 
> I'd like to have a command (Python script?) that allows me to trace function calls and exits.
> 
> One possible implementation seems that I could:
> 
> 	• Set up a breakpoint on function entry.
> 	• Run some code to log the arguments passed to the function.
> 	• Use SBThread::StepOut() to get to where the function has been exited.
> 
> This leaves me with a number of questions though:
> 
> 	• Is this a good or even valid approach?

Sure, this should work.  I presume that you're doing this for functions for which you have debug info:?  Otherwise getting return values when you step out is going to be tricky...


> 	• Is all of this safe against re-entry? What happens if I'm trying X and X gets invoked again (during the thread plan execution)?

The most straightforward way to do this would be to write something that just drives the event loop a la:

http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/process_events.py

Then recursion won't bother you.  The step plans stack, so if you do your "step-out" and before the step out completes you hit the breakpoint again, that's okay, the first step-out plan is still on the plan stack.  Do your "step-out" for the second breakpoint hit, and when that completes, "continue" and the original step-out plan will then get a chance to complete.  And since plans are per thread, doing this on multiple threads won't cause any problems either.

> 	• How do I get the return value for the function that I've just exited via StepOut?

The thread has "SBThread::GetStopReturnValue()".  Any time a stop on that thread generates a return value that lldb can figure out (which is only for "step-out" at present) it will stuff it in the thread's return value.  You need to get it before you continue that thread.

> 	• What happens if X has been inlined? Will this work still for all entries and exits?

We don't know how to get return values for inlined functions.  Step out often works, but not always since the line-tables for inlined functions are often unreliable.  You can check whether you are an inlined block with the SB API.  Since you can't get the return value in this case, it might be easier to log the hit, and note that you can't get a return value and continue...

> 	• I also saw SBThreadPlan was added since I last looked into this. Does anything use this? (I didn't see any uses in-tree.)

This was a toy I was starting to play with.  You could definitely use it for the same purposes, and I'd love to have somebody try this out.  But if you have real work to get done, you might want to stick with the more tried method of running the event loop from outside the thread plans.

Jim



> 
> Thanks!
> 
>  - Bruce
> 
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev





More information about the lldb-dev mailing list