Но у меня больше не будет возможности устанавливать точки останова в программе b
Хитрость заключается в том, чтобы установить точку останова в дочернем элементе как задержанную точку останова.Когда дочерний элемент execl()
d, GDB установит в нем точку останова.Пример:
// a.c
#include <unistd.h>
int main()
{
if (0 == fork()) execl("./b.out", "b.out", (char*)0);
return 0;
}
// b.c
int foo() { return 0; }
int main() { return foo(); }
gcc -g a.c; gcc -g b.c -o b.out
gdb -nx -q ./a.out
Reading symbols from /tmp/a.out...done.
(gdb) b foo
Function "foo" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (foo) pending.
Точка останова находится на рассмотрении, поскольку foo()
в a.out
(* b.out
) foo()
.
(gdb) set follow-fork-mode child
(gdb) run
Starting program: /tmp/a.out
[New process 18759]
process 18759 is executing new program: /tmp/b.out
[Switching to process 18759]
Breakpoint 1, foo () at b.c:1
1 int foo() { return 0; }
(gdb) bt
#0 foo () at b.c:1
#1 0x00000000004004dd in main () at b.c:3
(gdb) quit
нет.