gdb动态挂运行程序并调试

213 篇文章 0 订阅
/*
 * 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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值