这个地址讲述了nginx是如何静态编译openssl的:http://blog.csdn.net/hujkay/article/details/23476557
编译nginx的时候,首先会静态编译openssl,并且执行auto/lib/openssl/make 脚本来进行openssl 编译的配置。
要想能够gdb调试nginx下的openssl代码需要修改
1. auto/cc/conf ngx_compile_opt="-c" 加上 -g 选项变为 ngx_compile_opt="-c -g",这么修改之后nginx就可以使用gdb调试了
2. auto/lib/openssl/make 把&& ./config --prefix=$ngx_prefix no-shared $OPENSSL_OPT \\改为&& ./config --prefix=$ngx_prefix no-shared $OPENSSL_OPT-d\\
这么修改之后auto/lib/openssl/make脚本在进行openssl编译配置的时候(执行openssl的conf脚本)会加上允许gdb调试选项,最终在gcc编译openssl的时候,会加上-g选项
我的环境是kali linux,编译openssl gcc 加上-g选项之后,会报如下错误:
/usr/bin/ld: cannot find -lefence
通过如下命令解决这个错误
ln -s /usr/lib/i386-linux-gnu/gstreamer-0.10/libgstefence.so /usr/lib/libefence.so
然后执行make&make install
然后执行gdb调试nginx,效果如下:
(gdb) directory /home/smb/workspace/openssl-1.0.1e/ssl
Source directories searched: /home/smb/workspace/openssl-1.0.1e/ssl:/home/smb/workspace/nginx-1.4.7/src:$cdir:$cwd
<strong><span style="color:#ff6666;">(gdb) b d1_pkt.c:dtls1_read_bytes
Breakpoint 4 at 0x80ee2f9: file d1_pkt.c, line 753.</span></strong>
(gdb)
这样就可以调试openssl了:)