Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb interpret memory address as an object

Tags:

c++

linux

gdb

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.

like image 208
Yordan Pavlov Avatar asked Mar 21 '11 18:03

Yordan Pavlov


People also ask

How to use examine in GDB?

You can use the command x (for “examine”) to examine memory in any of several formats, independently of your program's data types. Use the x command to examine memory.

What does P do in GDB?

The usual way to examine data in your program is with the print command (abbreviated p ), or its synonym inspect . It evaluates and prints the value of an expression of the language your program is written in (see section Using GDB with Different Languages). exp is an expression (in the source language).

What does incomplete type mean in GDB?

but no definition for struct foo itself, gdb will say: (gdb) ptype foo $1 = <incomplete type> “Incomplete type” is C terminology for data types that are not completely specified.


1 Answers

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

print *(class MyClass*)pointer_var

like image 193
Šimon Tóth Avatar answered Nov 07 '22 10:11

Šimon Tóth