Yordan Pavlov
Yordan Pavlov

Reputation: 1333

gdb interpret memory address as an object

I am investigating a crash, based on the available core dump. The application crashing is a C++ program, built with gcc and running on RH5. The backtrace seems valid till the #1 frame. There trying to print an object I get <invalid address>, <error reading variable> Since I have the address of the object from the #2 frame is it a valid presumption that I can somehow 'dump' the memory in which the object is allocated and still collect some info. Furthermore, instead of trying to guess how the object is aligned, can I force gdb to print the address as if it is an object, even though it detects some error. My idea is that maybe the object has already been deleted, but just maybe the memory is still there and I can print some member variable.

Please comment on is that possible, and if so, how it should be done in gdb terms. 10x.

Upvotes: 19

Views: 23181

Answers (1)

Šimon T&#243;th
Šimon T&#243;th

Reputation: 36423

Well, if you have an address you can always do:

print *(class MyClass*)pointer_var

Upvotes: 24

Related Questions