c++linuxgdbpostmortem-debugging

Finding the pointer to a singleton postmortem in GDB (C++)


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?


Solution

  • 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.