質問

I am doing a postmortem analysis of a crashed program. I am on Linux (Ubuntu 12.04, x86), the code is written in C++. The Program is using some singletons that may contain valuable information. Is it possible to find the pointer to the instance of a singleton if it was created like this:

SingletonType& SingletonType::getInstance(){
    static SingletonType* instance = new SingletonType();
    return *instance;
}

And if its is possible, how is it done in GDB?

役に立ちましたか?

解決

Run gdb with the core file, and run the command

disassemble  SingletonType::getInstance

On my test-program I found a mov 0x<addr>, %eax instruction near the end of the method. A print *(*(SingletonType**) <0xaddr>) should print the contents of your singleton structure.

他のヒント

show modules1 should probably tell you the base addresses, and instance, being statically allocated, should be visible in some kind of objdump/nm report. Yeah hairy maths.

The alternative would be to disassemble SingletonType::getInstance() and see what effective address gets loaded in the initialization/return path.


1 Mmm can't find the exact match I was remembering. info sharedlibrary would get you most info.

this is what I do, while inside the core with gdb:

(gdb) info var instance

this will list all the addresses of all the singletons instances, among which you will find the one of SingletonType

0x86aa960 SingletonType::getInstance()::instance

Now that I have the address you can print the your instance' pointed memory:

(gdb) p *((SingletonType*)0x86aa960)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top