Linux gdb 将内存地址解释为对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5381836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gdb interpret memory address as an object
提问by Yordan Pavlov
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.
我正在根据可用的核心转储调查崩溃。崩溃的应用程序是一个 C++ 程序,使用 gcc 构建并在 RH5 上运行。回溯似乎有效,直到 #1 帧。那里试图打印我得到的对象
<invalid address>, <error reading variable>
因为我有来自 #2 帧的对象的地址,这是一个有效的假设,我可以以某种方式“转储”分配对象的内存并仍然收集一些信息。此外,我可以强制 gdb 打印地址,就像它是一个对象一样,而不是试图猜测对象是如何对齐的,即使它检测到一些错误。我的想法是,也许对象已经被删除了,但也许内存还在,我可以打印一些成员变量。
Please comment on is that possible, and if so, how it should be done in gdb terms. 10x.
请评论这是否可能,如果是,应该如何在 gdb 术语中完成。10 倍。
回答by ?imon Tóth
Well, if you have an address you can always do:
好吧,如果您有地址,则可以随时执行以下操作:
print *(class MyClass*)pointer_var
print *(class MyClass*)pointer_var