1

I want to get backtrace of the stack in process A by process B I know I can use gdb --pid pid_of_A , then use info stack to get backtrace of the stack in process A.

But, I want to implement it by code, not use gdb. I read gdb source code to understand how gdb do it, but gdb is to complex to understand.

Can you help to do it ?

Vincent
  • 11
  • 3

1 Answers1

0

You should use libgdb. With libgdb you can programmatically execute gdb commands just like someone doing an interactive gdb session.

Here is the main function to use:

struct gdb_str_output gdb_execute_for_strings (char *cmd)

This executes the command in cmd (e.g. backtrace) and returns a structure containing the output of the command.

Craig S. Anderson
  • 6,966
  • 4
  • 33
  • 46
  • Can you give me a simple complete example, Thanks – Vincent Jul 07 '15 at 12:20
  • `libgdb` is an aborted attempt from 1993. It was tried again in 1999 as `libgdb2`, but didn't get much traction either. https://sourceware.org/ml/gdb-patches/2009-03/msg00676.html – Employed Russian Jul 07 '15 at 14:25