1、nginx调试只能重新在部署的时候进行设置在nginx之后添加 –with-debug选项
#开启-g选项 并且去掉Gcc优化
./configure --with-debug --with-cc-opt='-g -O0'
2、编译加安装 ,默认在/usr/local/nginx目录下
make && make install
3、设置配置文件
error_log logs/error.log debug;
4、代码中加入自己的调试,就可以在err_log文件中看到加入的代码。
ngx_log_debug(NGX_LOG_DEBUG, log, 0,"[jsh] 11111");
2、gdb调试,参照上面加上-g选项,编译出可执行文件。
方法一:直接法
gdb --args ./objs/nginx -c /usr/local/nginx/conf/nginx.cof
#或者
gdb ./objs/nginx
set args -c /usr/local/nginx/conf/nginx.conf
**方法二:通过进程ID间接法**
-------------
./nginx
ps aux | grep nginx #查看进程id
gdb -p 进程号
或是
先启动 gdb 再 attach 进程号
方法三: core 文件
./nginx
ps aux | grep nginx #查看进程id
#看到nginx启动了一个master进程(18237)和一个worker进程(18238)
# 在./objs文件夹中
gcore 18237 # 会生成 core.18237文件
#关掉nginx进程
./nginx -s stop(或者直接使用kill)
gdb ./nginx core.18237
下面是代码打印出核心模块的命令。
(gdb) set print pretty on #设置打印结构体的格式,
(gdb) p ngx_core_commands #打印出核心模块的命令
$7 = {{
name = {
len = 6,
data = 0x80f90f7 "daemon"
},
type = 16843264,
set = 0x806e6dc <ngx_conf_set_flag_slot>,
conf = 0,
offset = 0,
post = 0x0
}, {
name = {
len = 14,
data = 0x80f90fe "master_process"
},
type = 16843264,
set = 0x806e6dc <ngx_conf_set_flag_slot>,
conf = 0,
offset = 4,
post = 0x0
}, {