20

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.

1
  • 4
    Not sure if it will work, but you could try print *((Obj*)address). It works sometimes for me. Commented Mar 21, 2011 at 18:26

1 Answer 1

25

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

print *(class MyClass*)pointer_var

Sign up to request clarification or add additional context in comments.

7 Comments

Well I tried printing it that way (gdb) p (class MyClass *)m_pointer But I get No struct type named MyClass It seems like gdb do not know of my class.
@Yordan You of course need to cast to the structure you want to print.
@Let_Me_Be What do you mean? Is not what the (class MyClass *) part does.
@Let_Me_Be Now I got what you are thinking. Well I am using the correct name of my class of course. :) I am just sticking with your MyClass example. Still gdb can not find my class, most probably because it is from a shared library. Any idea on that one?
7 years late but - try without class - e.g. p *(MyClass *) <value>
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.