首页 > 其他分享 >【gdb】为exec调用设置catchpoint

【gdb】为exec调用设置catchpoint

时间:2023-10-16 19:24:24浏览次数:62  
标签:exec demo catchpoint gdb ls root

为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

标签:exec,demo,catchpoint,gdb,ls,root
From: https://www.cnblogs.com/sunbines/p/17768153.html

相关文章

  • 【gdb】为vfork调用设置catchpoint
    为vfork调用设置catchpoint1.例子:#include<stdio.h>#include<stdlib.h>#include<sys/types.h>#include<unistd.h>intmain(void){pid_tpid;pid=vfork();if(pid<0){exit(1);}elseif(pid>0){exi......
  • 【gdb】同时调试父进程和子进程
    同时调试父进程和子进程1.   参考资料1.gdb手册2.同时调试父进程和子进程......
  • 【gdb】设置读观察点
    设置读观察点1.例子#include<stdio.h>#include<pthread.h>#include<unistd.h>inta=0;void*thread1_func(void*p_arg){while(1){a++;sleep(10);}}void*thread2_func(void*p_arg){while(1){a++;sleep(10......
  • 【gdb】设置读写观察点
    设置读写观察点1.例子:#include<stdio.h>#include<pthread.h>#include<unistd.h>inta=0;void*thread1_func(void*p_arg){while(1){a++;sleep(10);}}void*thread2_func(void*p_arg){while(1){a++;sleep(1......
  • 【gdb】
      #include<stdio.h>#include<pthread.h>#include<unistd.h>inta=0;void*thread1_func(void*p_arg){while(1){a++;sleep(10);}}void*thread2_func(void*p_arg){while(1){a++;sleep(10);}}......
  • 【gdb】输出信息多时不会暂停输出
    输出信息多时不会暂停输出有时当gdb输出信息较多时,gdb会暂停输出,并会打印“---Type<return>tocontinue,orq<return>toquit---”这样的提示信息,如下面所示:81process26391020xff04af84in__lwp_park()from/usr/lib/libc.so.180process25735660xff04......
  • 【gdb】设置观察点
    设置观察点1.例子#include<stdio.h>#include<pthread.h>#include<unistd.h>inta=0;void*thread1_func(void*p_arg){ while(1) { a++; sleep(10); }}intmain(intargc,char*argv[]){ pthread_tt1; pthread_create(&t1,NUL......
  • 【gdb】显示gdb版本信息
    显示gdb版本信息使用gdb时,如果想查看gdb版本信息,可以使用“showversion”命令:(gdb)showversionGNUgdb(GDB)7.7.1Copyright(C)2014FreeSoftwareFoundation,Inc.LicenseGPLv3+:GNUGPLversion3orlater<http://gnu.org/licenses/gpl.html>Thisisfreesof......
  • 【gdb】启动时不显示提示信息
    启动时不显示提示信息$gdbGNUgdb(GDB)7.7.50.20140228-cvsCopyright(C)2014FreeSoftwareFoundation,Inc.LicenseGPLv3+:GNUGPLversion3orlater<http://gnu.org/licenses/gpl.html>Thisisfreesoftware:youarefreetochangeandredistributeit.The......
  • 【gdb】gdb退出时不显示提示信息
    gdb退出时不显示提示信息gdb在退出时会提示:Adebuggingsessionisactive.Inferior1[process29686]willbekilled.Quitanyway?(yorn)n如果不想显示这个信息,则可以在gdb中使用如下命令把提示信息关掉:(gdb)setconfirmoff也可以把这个命令加到.gdbi......