美文网首页
gdb 调试core文件

gdb 调试core文件

作者: myang199088 | 来源:发表于2015-04-02 18:39 被阅读657次

在实验室环境中经常会遇到的问题就是进程down了,这种问题没有gdb这种调试工具的话很难定位到具体有问题的点。首先要用core文件调试,需要在进程down掉的时候生成core文件,下面我们首先用root做好相应的设置。

  • 查看ulimit设置,
    omu1:/opt/y00249743 # ulimit -a
    core file size (blocks, -c) 0
    data seg size (kbytes, -d) unlimited
    file size (blocks, -f) unlimited
    pending signals (-i) 194775
    max locked memory (kbytes, -l) 32
    max memory size (kbytes, -m) unlimited
    open files (-n) 1024
    pipe size (512 bytes, -p) 8
    POSIX message queues (bytes, -q) 819200
    stack size (kbytes, -s) 2048
    cpu time (seconds, -t) unlimited
    max user processes (-u) 194775
    virtual memory (kbytes, -v) unlimited
    file locks (-x) unlimited
    现在core file size是0,这样进程down掉的时候是不会生成core file的。

  • 设置ulimit
    ulimit -c unlimited

  • 查看修改后的设置
    omu1:/opt/y00249743 # ulimit -a
    core file size (blocks, -c) unlimited
    data seg size (kbytes, -d) unlimited
    file size (blocks, -f) unlimited
    pending signals (-i) 194775
    max locked memory (kbytes, -l) 32
    max memory size (kbytes, -m) unlimited
    open files (-n) 1024
    pipe size (512 bytes, -p) 8
    POSIX message queues (bytes, -q) 819200
    stack size (kbytes, -s) 2048
    cpu time (seconds, -t) unlimited
    max user processes (-u) 194775
    virtual memory (kbytes, -v) unlimited
    file locks (-x) unlimited

  • 设置core文件生成的路径
    omu1:/opt/y00249743 # echo core > /proc/sys/kernel/core_pattern

  • 有问题的代码
    #include <stdio.h> void core_here(char *ptr) { *ptr = 0; } void test() { char *ptr = NULL; core_here(ptr); } int main() { test(); return 0; }

  • 编译代码
    omu1:/opt/y00249743 # gcc -g test.c -o test

  • 执行后将会在本目录下生成core文件
    omu1:/opt/y00249743 # ./test
    Segmentation fault (core dumped)

  • 用gdb调试core文件
    omu1:/opt/y00249743 # gdb test core
    GNU gdb 6.6
    Copyright (C) 2006 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "i586-suse-linux"...
    Using host libthread_db library "/lib/libthread_db.so.1".
    warning: Can't read pathname for load map: Input/output error.
    Reading symbols from /lib/libc.so.6...done.
    Loaded symbols for /lib/libc.so.6
    Reading symbols from /lib/ld-linux.so.2...done.
    Loaded symbols for /lib/ld-linux.so.2
    Core was generated by `./test'.
    Program terminated with signal 11, Segmentation fault.
    #0 0x0804838a in core_here (ptr=0x0) at test.c:5
    5 ptr = 0;
    虽然这里一眼就可以看出是在是在test.c的第5行,
    ptr = 0执行导致进程down掉,我们在实验室环境中调试代码可能有时候需要看下一些变量的值以及调用栈,所以我们继续看下。

  • 查看调用栈信息
    (gdb) bt
    #0 0x0804838a in core_here (ptr=0x0) at test.c:5
    #1 0x080483a7 in test () at test.c:11
    #2 0x080483bc in main () at test.c:16
    这里可以看到调用栈里有三个函数。

  • 查看具体变量值
    (gdb) frame 0
    #0 0x0804838a in core_here (ptr=0x0) at test.c:5
    5 *ptr = 0;
    确定代码块
    (gdb) l
    1 #include <stdio.h>
    2
    3 void core_here(char *ptr)
    4 {
    5 *ptr = 0;
    6 }
    7
    8 void test()
    9 {
    10 char *ptr = NULL;
    (gdb) p ptr
    $3 = 0x0

相关文章

  • gdb 调试core文件

    在实验室环境中经常会遇到的问题就是进程down了,这种问题没有gdb这种调试工具的话很难定位到具体有问题的点。首先...

  • linux opencv传递网络摄像头数据--Apple的学习笔

    一,遇到问题 1.段溢出? 根本原因:vector申请后没有释放,导致段溢出。调试方法:通过gdb调试core文件...

  • coredump备忘

    背景 程序已经挂死等情况,内核会生成一个core文件(是内存映像以及调试信息)。可以通过使用gdb来查看core文...

  • Protostar stack5问题

    1.stack5问题源码 2.编写脚本 3.执行stack5.sh生成core文件 4.gdb调试core 5.修...

  • Android debugger ptrace 的处理

    代码位置:system/core/debuggerd/debuggerd gdb调试: strace查看系统调用:

  • GDB命令

    gdb test 启动gdb调试test可执行文件gdb att 进程名 调试某个进程b [行数]/[函数名...

  • 利用Core Dump调试程序

    描述 这里介绍Linux环境下使用gdb结合core dump文件进行程序的调试和定位。 简介 当用户程序运行,可...

  • core调试

    嵌入式开发时,程序出现coredump之后,收集core文件并在宿主机上进行调试。 原理: 1. gdb工具 2....

  • 挂了而且gdb显示问号!

    这两天遇到一个程序挂的问题,关键是原因还不好找,虽然core了产生了core文件,但是通过gdb调试的时候很遗憾,...

  • gcc/gdb

    gcc esc----iso 指定头文件目录 使编译后文件支持gdb调试 gdb gcc -g之后开始 gdb a...

网友评论

      本文标题:gdb 调试core文件

      本文链接:https://www.haomeiwen.com/subject/pewoxttx.html