I'm using GDB to analyze a core dump of a C program. Is it possible to print the size of a struct in the program?
Asked
Active
Viewed 4.0k times
2 Answers
56
These should all work in GDB (assuming you compiled with -g
):
print sizeof(var)
print sizeof(Type)

Employed Russian
- 199,314
- 34
- 295
- 362
-
Just wanted to confirm: This gives the size of the type for the target program and not for gdb, right? The two could be compiled for different architectures. – Daniel Walker Nov 09 '22 at 16:10
-
1@DanielWalker Correct: neither `var` nor `Type` may even _exist_ in GDB. – Employed Russian Nov 09 '22 at 17:02
0
have u tried "sizeof"?
the complier may do the byte alignment automatically by default,so this size may be greater than you think

Stan
- 142
- 4