gdb动态挂运行程序并调试

来源:互联网 发布:南京大学 软件学院 编辑:程序博客网 时间:2024/06/14 08:20
/* * gdb动态挂运行程序并调试 * 编译程序: * gcc gdb_attach2.c -o gdb_attach2 -g *  * 运行程序: * ./gdb_attach2 * * 查看程序进程代号: * ps ax | grep gdb_attach2 * 3973 pts/0    S+     0:00 ./gdb_attach2 * * 启用gdb挂载程序: * gdb gdb_attach2 3973 * * 在目标位置设置断点 * b gdb_attach2.c:44 * Breakpoint 1 at 0x40052f: file gdb_attach2.c, line 44. * * 设置断点执行指令 * (gdb) command 1 * Type commands for breakpoint(s) 1, one per line. * End with a line saying just "end". * >p i * >c * >end * * 设置gdb环境 * set height 0 * * 继续运行程序 * (gdb) c  * * 退出gdb程序 * CTRL-C * quit */#include<stdio.h>#include<stdlib.h>#include<unistd.h>int fun(int cnt){int i;for(i=0;i<cnt;++i){printf("in fun i=%d\n",i);sleep(1);}return 0;}int main(){fun(1000);return 0;}

0 0
原创粉丝点击