Making function calls within gdb.
Posted by peeterjoot on August 31, 2009
Here’s a quick debugging tidbit for the day, somewhat obscure, but it is a cool one and can be useful (I used it today)
Gdb has a particularily nice feature of being able to call arbitrary functions on the gdb command line, and print their output (if any)
(gdb) p getpid()
$8 = 6649
(gdb) p this->SAL_DumpMyStateToAFile()
[New Thread 47323035986240 (LWP 32200)]
$9 = void
You may have to move up and down your stack frames to find the context required to make the call, or to get the parameters you need in scope. You have to think about (or exploit) the side effects of the functions you call.
Somewhat like modification of variables in the debugger, this capability allows you to shoot yourself fairly easily, and but that’s part of the power.
I don’t recall if many other debuggers had this functionality. I have a vague recollection that the sun workshop’s dbx did too, but I could be wrong.