View Full Version : viewing declared struct objects using gdb

07-20-2003, 03:01 PM
lets say I have a program resembling:

#include <stdio.h>
struct blah
int id;
char* user;

int main()
struct blah mystrct;
mystrct.id = 1;
mystrct.user = "hi there\n";
return 0;

And I am trying to debug this with GDB, how could I view the variable
mystrct.user or mystrc.id
assuming I have a breakpoint at fprintf.
when typing print mystrct or mystrct.user it says cannot view struct objects or something.
Would I have to pick apart the stack?


07-20-2003, 06:46 PM

Turns out that the part I was trying to debug wouldn't have helped anyway, I did this stupid thing earlier which caused a seg-fault:

fp = fopen("somefile.txt","rw");

ooh boy, that was fun, I thought the whole time it was with a struct's string and a buffer overflow...
I can't believe I made that mistake either, but thanks for the help, I'll use that when I need to. But, I couldn't find out how to display members of a struct. Oh well-