zoukankan      html  css  js  c++  java
  • coredump文件设置及调试

    linux下coredump文件管理及问题定位
    1、core文件生成开关、大小及路径设置
     查看大小命令:ulimit -c, 如果结果是0,则表示开关关闭,否则表示产生core文件的大小
     查看路径设置:cat /proc/sys/kernel/core_pattern或sysctl -a |grep pattern
     大小设置:ulimit -c filesize(单位kbyte),ulimit -c unlimited表示core大小不受限
     路径设置:echo "/home/mnt/c/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern,则生成core文件名为core-程序名-pid-时间戳,存放在corefile文件中(该文件夹要存在哦)
      其他参数列表:
         %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 添加程序名
     永久生效设置:
      1)、修改/etc/init.d/rc.local,添加如下脚本,
        mkdir -p /home/mnt/c/corefile/
        echo 1 > /proc/sys/kernel/core_uses_pid     ————让core文件携带进程ID
        echo "/home/mnt/c/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern
      2)、修改profile文件
        在/etc/profile文件尾添加, ulimited -S -c unlimited >/dev/null 2>&1
        或在~/.bash_profile中添加unlimited -S -c unlimited > /dev/null 2>&1
       
    2、coredump文件调试
     gdb 程序名 -c coredumpfile
     
    3、demo
     
     1)、编写测试文件testcore.c

            #include<stdio.h>
            #include<string.h>
           int main()
          {
              char * str = new char[10];
             delete str;
             str = NULL;
            strncpy(str,"hello,world",10);
            printf("str=%s ",str);
            return 1;
        }

     2)、编译g++ -g -Wall testcore.c -o test
     3)、生成core文件,./test

         root@XXX-virtual-machine:/home/mnt/c/ctests# ./test
         段错误 (核心已转储)
     4)、调试core文件,gdb test -c /home/mnt/c/corefile/core-test-2665-1376708583

        

    Program terminated with signal 11, Segmentation fault.
    #0  0x080484d5 in main () at coretest.c:8
    8  strncpy(str,"hello,world",10);
    (gdb) bt
    #0  0x080484d5 in main () at coretest.c:8
    (gdb) p str
    $1 = 0x0
    (gdb)

     
     
     
     
     

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    [JAVA] 运行 java HelloWorld 命令,提示“错误: 找不到或无法加载主类
    「Ubuntu」 终端更新时,报错
    【MATLAB】 运行Simulink时出现报错
    Ubuntu提示boot内存不足
    python+unittest+requests实现接口自动化的方法
    Python + Requests + Unittest接口自动化测试实例分析
    七.测试执行的log读取
    五.DDT测试驱动
    操作json文件
    四.爬取拉勾网实例
  • 原文地址:https://www.cnblogs.com/agiletiger/p/4888243.html
Copyright © 2011-2022 走看看