I've recently discovered one too little-known feature of gdb: you can script it with python. It's even in the documentation, and there are nice tutorials available which I invite you to read. The two main cool things you can do in python, is define new commands, and new convenience functions. Unfortunately, as you can read in this article, defining a new command requires a lot of boilerplate (and it's the same for convenience functions). Since I wanted to write a few commands, I couldn't be bothered to copy-paste that boilerplate, so I ended up writing a nice magical class that makes registering a function easier. You can find that here. With this new weapon in hand, I wrote new commands to be able to follow what happens in a GstAdapter. Basically, I wanted to be able to track the position in the original file of each byte that was going out of a given adapter. So I wrote some code to be called by gdb commands when some operations on a GstAdapter are done, doing the necessary calculations and storing, and voilà: I can print, with gdb, the file position of the data obtained with each call to gst_adapter_peek(). All the code and the gdb script can be found over there. As you can see, a gdb script is still needed. I haven't yet really tried to play with breakpoints in python, but I have a feeling this is not totally trivial, if at all possible. The other great limitation is speed. It feels like the calls to python stuff from gdb are very costly, and, in the case of GStreamer, don't expect smooth playing if you use some gdb command implemented in python for every buffer transmitted. Conclusion: it's got limits, but overall, this ability to enhance gdb with python allows you to do things you couldn't do easily otherwise, like store data in complex structures for your debugging, and prototype easily some debugging actions you want to do, where the only alternative is to write it in C and include it in the application/library you are debugging.

No comment

Post a comment

All comments are held for moderation; basic HTML formatting accepted.

Name: (required)
E-mail: (required, not published)
Website: (optional)


09 November 2010