Search code examples
c++gdbcoredumpgdbserver

Anyway for my c++ application to communicate with GDB?


I would like read a core-dump file dumped with gcore.
However, I would like to read a coredump file in my c++ application, not with gdb terminal command.
For instance, I have a executable program 'testEx' and it is killed by some reason then 'testEx' left a core dump.
I am creating a C++ application 'readGDB' to analyze core dump created by 'testEx'.
Any c++ library and example to read a core file?


Solution

  • Any c++ library and example to read a core file?

    Reading the core is trivial: you just open and read it.

    What's not trivial is understanding what the contents means. A core file is an ELF file, so it has a lot of internal structure, and libraries such as libelf can help you read specific sections of the core.

    But that's still long way away from what GDB does: to really understand the contents, you also need to implement symbol management, stack unwinding, and many more things. In short, you will have to re-implement half of GDB.

    So why not just use GDB? You can talk to GDB from your application, and make it give you the answers you are seeking. GDB has a special machine interface mode for just that purpose.