Friday, December 12, 2008
We’ve covered many of the features of python-gdb: Writing new commands Convenience functions Pretty-printing Auto-loading of Python code Scripting gdb from Python Bringing up a GUI In fact, that is probably all of the user-visible things right now. There are classes and methods in the Python API to gdb that we have not covered, but [...]
Wednesday, December 10, 2008
Last time I promised something flashy in this post. What could be flashier than a GUI? Here’s some code to get you started: from threading import Thread import gtk def printit (): print “Hello hacker” class TestGtkThread (Thread): def destroy (self, *args): self.window.hide() def hello (self, *args): gdb.post_event (printit) def run (self): gtk.gdk.threads_init() self.window = [...]
Tuesday, December 9, 2008
So far we’ve concentrated on way to use Python to extend gdb: writing new commands, writing new functions, and customized pretty-printing. In this post I want to look at gdb from a different angle: as a library. I’ve long thought it would be pretty useful to be able to use gdb as a kind of [...]
In the previous entry we covered the basics of pretty-printing: how printers are found, the use of the to_string method to customize display of a value, and the usefulness of autoloading. This is sufficient for simple objects, but there are a few additions which are helpful with more complex data types. This post will explain [...]
Thursday, December 4, 2008
Consider this simple C++ program: #include <string> std::string str = “hello world”; int main () { return 0; } Compile it and start it under gdb. Look what happens when you print the string: (gdb) print str $1 = {static npos = 4294967295, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No [...]
Wednesday, December 3, 2008
I think the idea of backtrace filters (the topic of the previous post) is a pretty cool one. And, as I mentioned before, extending gdb with application-specific behavior is a compelling use for the Python scripting capability. Remembering to source these snippets is a bit of a pain. You could, of course, stick a command [...]
Tuesday, December 2, 2008
You’ll want to update and rebuild your python-gdb before trying this example — I found a bug today. We’ve learned some of the basics of scripting gdb in Python. Now let’s do something really useful. Many projects provide a customized backtrace-like gdb command, implemented using “define“. This is very common for interpreters — Python provides [...]
It has been a few days, and we’ve pushed a few changes. So, you should update your gdb and rebuild it before continuing with the examples. In addition to ordinary commands, gdb has “set/show” commands, which are basically a way to manipulate various global variables that control aspects of gdb’s behavior. The Python API to [...]
Sunday, November 30, 2008
In the previous installment we found out how to write new gdb commands in Python. Now we’ll see how to write new functions, so your Python code can be called during expression evaluation. This will make gdb’s command language even more powerful. A longstanding oddity of gdb is that its command language is unreflective. That [...]
Saturday, November 29, 2008
If you’re like me, you’ve probably wished you could write new commands in gdb. Sure, there is the define command — which I’ve used heavily — but it has some annoying limitations. For example, you can’t make new sub-commands using define. Also, arguments to define are parsed oddly; you can’t have an argument that has [...]