C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-20-2003, 03:01 PM   #1
Comment your source code!
 
Lynux-Penguin's Avatar
 
Join Date: Apr 2002
Posts: 533
viewing declared struct objects using gdb

lets say I have a program resembling:
Code:
#include <stdio.h>
struct blah
{
	int id;
	char* user;
};

int main()
{
	struct blah mystrct;
	mystrct.id = 1;
	mystrct.user = "hi there\n";
	fprintf(stdout,mystrct.user);
	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?

-LC
__________________
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
Lynux-Penguin is offline   Reply With Quote
Old 07-20-2003, 06:46 PM   #2
Comment your source code!
 
Lynux-Penguin's Avatar
 
Join Date: Apr 2002
Posts: 533
err
hehehe-
^_^

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:

Code:
fp = fopen("somefile.txt","rw");
fprintf(fp,"blah");
fclose(fp);
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-

-LC
__________________
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib

Last edited by Lynux-Penguin; 07-20-2003 at 06:49 PM.
Lynux-Penguin is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for constructive criticism wd_kendrick C Programming 16 05-28-2008 09:42 AM
Global Variables Taka C Programming 34 11-02-2007 03:25 AM
Looking for a way to store listbox data Welder C Programming 20 11-01-2007 11:48 PM
Help please im stuck ItsMeHere C Programming 7 06-15-2006 04:07 AM
Nested loop frustration caroundw5h C Programming 14 03-15-2004 09:45 PM


All times are GMT -6. The time now is 03:59 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22