Search code examples
clinuxsystems-programming

gdb like printing of a pointer to a struct


I need a way to have gdb like output for a pointer to a structure which shows all the fields and its addresses and the corresponding values. Is there a clean way to do this instead of printing it member by member. I cannot use any other external tool like pstruct or libgdb. I want to do it from within our C program. I do have gdb on the system and can use it. Thanks for your time.


Solution

  • Your options are:

    a) Read the debug symbols from binary and interpret them in the same way as GDB does to determine what the structure members are, and pass that info to a generalized printing routine.

    b) Compile metadata about your structures into your C program, either manually or with a custom build stage.

    c) Print member by member.