linux程序调试

strace -f -F -o strace.txt /data1/waf/sbin/nginx -c /data1/waf/conf/nginx.conf


如果想让系统在信号中断造成的错误时产生core文件, 我们需要在shell中按如下设置:
#设置core大小为无限
ulimit -c unlimited
#设置文件大小为无限
ulimit unlimited
gdb /data1/waf/sbin/nginx core.21169

编译nginx程序-g: 产生调试工具所用的调试符号信息(如果所编译的程序想要调试就需要加-g),-O, -O2,-O3: 优化编译连接 是执行的更迅速 -O的优化<-O2的优化<-O3的优化(不加是默认是-O)这个只在你的程序已经确定没有错误,可以发布时才去进行优化 平时就不用了

设置Core Dump的核心转储文件目录和命名规则
/proc/sys/kernel/core_uses_pid可以控制产生的core文件的文件名中是否添加pid作为扩展,如果添加则文件内容为1,否则为0
/proc/sys/kernel/core_pattern可以设置格式化的core文件保存位置或文件名,比如原来文件内容是core-%e
可以这样修改:
echo "/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern
将会控制所产生的core文件会存放到/corefile目录下,产生的文件名为core-命令名-pid-时间戳
以下是参数列表:
    %p - insert pid into filename 添加pid
    %u - insert current uid into filename 添加当前uid
    %g - insert current gid into filename 添加当前gid
    %s - insert signal that caused the coredump into the filename 添加导致产生core的信号
    %t - insert UNIX time that the coredump occurred into filename 添加core文件生成时的unix时间
    %h - insert hostname where the coredump happened into filename 添加主机名
    %e - insert coredumping executable name into filename 添加命令名

测试产生core文件:kill -s SIGSEGV $$

 

posted @ 2012-06-07 17:40  有安科技  阅读(40899)  评论(0编辑  收藏  举报