简体   繁体   中英

How to get an object from memory address in GDB by python

I have a core file and I have the binary(C++). The question is, while using gdb to analyze the core file, if I tried to print a pointer, it will print out the memory address. Once I tried to print the orignial context of that pointer, it says:

You can't do that without a process to debug.

Here is an example:

(gdb) p objPtr
(gdb) $1 = {px = 0x12345678}
(gdb) p *objPtr
(gdb) You can't do this without a process to debug.

In fact, this makes sense because the core file is not a process of that binary. But the core file is supposed to store the state when the binary crash, I think there should be a way to get the original context from, we say, a pointer.

I have done some research on writing a Python script to deal with this. But at the first place, if we are not able to do such p *ptr in gdb, how could my Python script get the object from that memory address?

Any reference or github project would help.

Update:

I discovered that I could do a:

(gdb) p *ptr.px

to fix the problem I have above.

But now my question becomes how to get the .px thing in Python script if I wish to write a script helping debug in GDB.

Actually find the answer by myself. Since the objPtr is a pointer in my example, calling something like *objPtr is considered calling a function/method of that pointer. The correct way is to p *objPtr.px .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM