前篇:
由于gdb需要gcc的时候加上-g参数,这样生成的文件才能使用gdb调试,因此我们要对源码做一下小改动
修改auto/cc/conf文件
ngx_compile_opt="-c"
变为
ngx_compile_opt="-c -g"
步奏:假设core文件为core.1111,可执行文件为nginx
1、执行命令 gdb core.1111
如果有错误,提示core.1234 : not in executable format: File format not recognized,则执行第二步,否则跳过
2、file ./sbin/nginx
提示 Reading symbols from test...done.
3、l ,显示程序行
4、b 5
Breakpoint 1 at 0x804ac5a: file src/core/nginx.c, line 5.
//设置断点
5、r (run)
运行程序,会在停在5行。如果没有断点会程序会直接运行完,如下
run
The program being debugged has been started already.
Start it from the beginning? (y or n) yes
6、s(step)/n(next)
下一步,用s(step),如果有函数,会进入函数
如果用n(next) 就不会进入函数中,只会运行当前调用函数的行
7、p a[0]
print 打印值
8、bt 查看栈
其它命令,以后添加。