How to do it for a c code..? Is it possible..? I read this post. I also want to do similar things but i am not able to use the given updated script at link GDB-Python scripting: any samples iterating through C/C++ struct fields
I followed the following steps to test : my source code name was : test.c and pretty.py
gcc -g test.c
gdb test
(gdb) source pretty.py
(gdb) run
(gdb) print <stcruct object>
How to use this script?
That script implements a new GDB command, wzd which takes a C structure as argument. You can tell from the Python doc string after
class PrintGList
You were expecting the script to implement a GDB pretty printer for a custom data type and change what gets printed when you use GDB's print command but that's not how the script is hooked up.
The class name
PrintGList
suggests that code originated from a script that printed the linked lists in the glib library. Copy and paste coding strikes again ;) I've fixed a few minor bugs and cleaned up the code below (wzd.py):Test program (struct-read.c):
Sample GDB session: