LLDB From Python
The main debugger, lldb, comes with Python built in! […] it appears you can actually have a Python script run when a breakpoint gets hit. The current stack frame and breakpoint location are passed to your function.
I tend to instrument my code because I really dislike clicking around in the debugger. This seems to have a lot of potential for making debugging faster.
Update (2012-08-15): Clark Goble:
What you could do to make the above function a tad more useful is keep a global counter that is incremented in every call to the Python function and then increment the column in Numbers by the same amount. That’ll give you a nice spreadsheet listing variables and their value according to time. More than a slight bit more readable than trying to traverse the output of numerous NSLog calls. You could even write a script that reads the values in say the first column down, treating them as variable names, and then print their values.
Update (2012-08-16): Clark Goble:
When you print things from your Python scripts the first time off a break not everything will print. At first I thought Python-lldb weren’t seeing all the variables. However everything gets copied to the spreadsheet properly. So it’s really a bug in Xcode where all the text output isn’t getting displayed correctly. This is useful to know if you start relying on lldb and scripting. Interestingly the second time you run your script on a single breakpoint the problem disappears. Until you advance your position in code whereupon it all begins again. Undoubtedly a small bug that will be fixed in a future Xcode version.
1 Comment RSS · Twitter
I've got a Python/lldb script that does that working right now. It just needs to get cleaned up. I'm just trying to exercise discipline and spend time learning Cocoa rather than playing around in lldb without a real good justification. (I just like Python) On the other hand it'll make debugging my C++ easier - perhaps I'll even do it in Xcode rather than Visual Studio now.