【gdb】为exec调用设置catchpoint

发布时间 2023-10-16 19:17:21作者: 苏格拉底的落泪

为exec调用设置catchpoint

1. 例子:

#include <unistd.h>

int main(void) {
    execl("/bin/ls", "ls", NULL);
    return 0;
}

使用gdb调试程序时,可以用“catch exec”命令为exec系列系统调用设置catchpoint,以上面程序为例:

[root@node01 demo]# gcc demo.c -g
[root@node01 demo]# gdb a.out -q
Reading symbols from /root/demo/a.out...done.
(gdb) catch exec
Catchpoint 1 (exec)
(gdb) r
Starting program: /root/demo/a.out 
process 3232124 is executing new program: /usr/bin/ls

Catchpoint 1 (exec'd /usr/bin/ls), 0x00007ffff7ddc140 in _start () from /lib64/ld-linux-x86-64.so.2
Missing separate debuginfos, use: debuginfo-install coreutils-8.22-24.el7_9.2.x86_64
(gdb) bt
#0  0x00007ffff7ddc140 in _start () from /lib64/ld-linux-x86-64.so.2
#1  0x0000000000000001 in ?? ()
#2  0x00007fffffffe7df in ?? ()
#3  0x0000000000000000 in ?? ()
(gdb)

 

参考资料

1. gdb手册

2. 为exec调用设置catchpoint