使用GDB调试Nginx

1 | 源码编译安装Nginx

cd /home/codes/
wget  http://nginx.org/download/nginx-1.16.1.tar.gz
tar zxvf nginx-1.16.1.tar.gz && cd nginx-1.16.1
./configure --prefix=/application/nginx-1.16.1/ --with-debug --with-cc-opt='-O0 -g'
make && make install

其中 --with-cc-opt='-O0 -g' 是不对编译进行优化和打开调试开关,-O0 -O1 -O2 -O3 -Os的作用请自行搜索

2 | 使用gdb调试

/application/nginx-1.16.1/sbin/nginx
#查看worker的pid
ps -ef | grep nginx
gdb -p 1706
#b src/http/ngx_http_core_module.c:1740 #需要根据nginx的版本查询ngx_http_send_header的行数打断点,其实也可以按照以下方式进行打断点
b ngx_http_send_header
p *r #r是ngx_http_request_s

运行结果

ngx_http_request_s结构体


struct ngx_http_request_s {
   
    uint32_t                          signature;         /* "HTTP" */

    ngx_connection_t                 *connection;

    void                            **ctx;
    void                            **main_conf;
    void                            **srv_conf;
    void                            **loc_conf;

    ngx_http_event_handler_pt         read_event_handler;
    ngx_http_event_handler_pt         write_event_handler;

#if (NGX_HTTP_CACHE)
    ngx_http_cache_t                 *cache;
#endif

    ngx_http_upstream_t              *upstream;
    ngx_array_t                      *upstream_states;
                                         /* of ngx_http_upstream_state_t */

    ngx_pool_t                       *pool;
    ngx_buf_t                        *header_in;

    ngx_http_headers_in_t             headers_in;
    ngx_http_headers_out_t            headers_out;

    ngx_http_request_body_t          *request_body;

    time_t                            lingering_time;
    time_t                            start_sec;
    ngx_msec_t                        start_msec;

    ngx_uint_t                        method;
    ngx_uint_t                        http_version;

    ngx_str_t                         request_line;
    ngx_str_t                         uri;
    ngx_str_t         
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值