Re: finding sizeof structure using gdb
- From: "junky_fellow@xxxxxxxxxxx" <junky_fellow@xxxxxxxxxxx>
- Date: Mon, 28 Jan 2008 03:46:00 -0800 (PST)
On Jan 28, 2:54 pm, fnegroni <f.e.negr...@xxxxxxxxxxxxxx> wrote:
I think the command you are looking for is:
print _expr_
where _expr_ is the expression you want to evaluate at runtime.
You can place a breakpoint anywhere in your program where you want to
evaluate an expression, and type 'print' followed by the expression
such as 'sizeof (struct_type)'
To find out the offset of a member it necessitates some casts:
Say you have a struct defined as:
struct kelp_file {
FILE *f;
char *name;
};
and at some point an object of type struct kelp_file called k comes
into visibility.
Use gdb to print offset of name compared to start of structure:
print (size_t)&(k.name) - (size_t)(&k)
Thanks Guys, that was really helpful.
Can you please also tell me how to typecast a memory address to a
particular structure type and print the values of various membes of
that structure.
For eg. Say I have some "structure x" at address 0xffff1000
Now, I want to typecast this memory address 0xffff1000 with the
"structure x" and print the contents of all the members in "structure
x". Can it be done in GDB Or I have to dump the contents of memory and
manually interpret the value of each member ?
.
- Follow-Ups:
- Re: finding sizeof structure using gdb
- From: fnegroni
- Re: finding sizeof structure using gdb
- References:
- finding sizeof structure using gdb
- From: junky_fellow@xxxxxxxxxxx
- Re: finding sizeof structure using gdb
- From: fnegroni
- finding sizeof structure using gdb
- Prev by Date: Re: Replacing read() by a debugging function
- Next by Date: Re: finding sizeof structure using gdb
- Previous by thread: Re: finding sizeof structure using gdb
- Next by thread: Re: finding sizeof structure using gdb
- Index(es):
Relevant Pages
|
|