1

Provided app2 is triggered by app1 in which there is something like system("./app2"). app1 also does a lot of preparation such as creating dirs, files, configuration... for app2 running.

How can I gdb app2 from the first line of its main()?

What I tried as below doesn't work.

gdb app2
  b main
  shell ./app1
HonanLi
  • 89
  • 11

1 Answers1

1

system("./app2");

There are a few ways to achieve this:

  1. If app1 doesn't close stdin, stdout, stderr, you could modify app1 to do this instead: `system("gdb ./app2")
  2. You could modify app2 to wait for debugger to be attached, as e.g. this answer shows. Then run app1, and use gdb -p $child_pid from another window.
  3. If app1 doesn't fork any children prior to app2, you could use (gdb) set follow-fork child and have GDB automatically start debugging app2 after app1 forks it.
Employed Russian
  • 199,314
  • 34
  • 295
  • 362