龙芯2K1000/2K500开发板如何利用coredump 进行调试

  1. 编译时加入调试信息 ((PC 机上))

    编译参数为 -g

loongarch64-linux-gnu-gcc -g 1.c

  1. 开启core 文件 (开发板上)

    ulimit -c unlimited

    查看ulimit 的所有参数设置

    # ulimit -a
    core file size          (blocks, -c) unlimited
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 3145
    max locked memory       (kbytes, -l) 65536
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) unlimited
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 100000
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    
    
  2. 查看core 文件的名字 (开发板上)

# cat /proc/sys/kernel/core_pattern

core

或者

# sysctl kernel.core_pattern

kernel.core_pattern = core
  1. 示例 (开发板上)
# ./a.out

[  374.566878] do_page_fault(): sending SIGSEGV to a.out for invalid write access to 0000000000000000
[  374.576031] era = 0000000120000748 in a.out[120000000+4000]
[  374.581699] ra  = 0000000120000788 in a.out[120000000+4000]
Segmentation fault (core dumped)

执行程序之后在当前路径生成了名为core 的 coredump 文件。

# ls -sh

total 508K
16K a.out  488K core
  1. 调试(PC 机上)

    将板卡上运行生产的core 文件复制到PC 机上,然后使用交叉工具链中的gdb 进行调试。

    调试步骤:

    1. 启动 loongarch64-linux-gnu-gdb
    2. 加载 二进制文件
    3. 加载 core 文件
    4. 查看堆栈
    $ loongarch64-linux-gnu-gdb
    GNU gdb (LoongArch GNU toolchain rc1.2 (20230615)) 8.1.50.20190122-git
    Copyright (C) 2018 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Type "show copying" and "show warranty" for details.
    This GDB was configured as "--host=x86_64-linux-gnu --target=loongarch64-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
        <http://www.gnu.org/software/gdb/documentation/>.
    
    For help, type "help".
    Type "apropos word" to search for commands related to "word".
    (gdb) file a.out				## 加载二进制文件
    Reading symbols from a.out...done.
    (gdb) core-file ./core			## 加载core 文件
    warning: exec file is newer than core file.
    [New LWP 473]
    warning: Section `.reg2/473' in core file too small.
    warning: Could not load shared library symbols for /lib/loongarch64-linux-gnu/libc.so.6.
    Do you need "set solib-search-path" or "set sysroot"?
    Core was generated by `./a.out'.
    Program terminated with signal SIGSEGV, Segmentation fault.
    warning: Section `.reg2/473' in core file too small.
    #0  0x0000000120000748 in change_val (p=0x0) at 1.c:7	## 从这里可知是给空指针赋值后导致的
    7               *p = 10;
    (gdb) bt					## 查看堆栈
    #0  0x0000000120000748 in change_val (p=0x0) at 1.c:7
    #1  0x0000000120000788 in main (argc=1, argv=0x7ffbcbc0e8) at 1.c:13
    (gdb)
    

    示例源代码如下

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void change_val(char *p)
    {
            *p = 10;
    }
    
    int main(int argc, char *argv[])
    {
            char *p = NULL;
            change_val(p);
            printf("p:%d\n", *p);
            return 0;
    }
    
  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值