在Linux中调试段错误(core dumped)(2)

调试我的coredump的程序结果如下:

sudo gdb -c /tmp/core-CodeCraft-2019.23637.jl.1554030516 GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <> 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 "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <>. Find the GDB manual and other documentation resources online at: <>. For help, type "help". Type "apropos word" to search for commands related to "word". [New LWP 23637] Core was generated by `./bin/CodeCraft-2019 ../1-map-training-1/car.txt ../1-map-training-1/road.txt .'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x0000556393da88ad in ?? () (gdb)

可以看到, 该程序在执行过程中接收到了一个SIGSEGV信号, 该信号表示一个进程执行了一个无效的内存引用, 或发生了段错误.

然后在gdb工具中不停的bt找到出现段错误在程序的多少行和真正引起段错误的原因.

bt的含义是backtrace, 列出调用栈.

gdb调试中常用的几个命令参数:

attach用GDB调试一个正在运行中的进程gdb <program> PID;

br用来设置断点, br filename:line_num,br namespace::classname::func_name;

n:单步跳过, s:单步进行;

finish:执行到函数return返回的地方;

list:列出当前位置之后的10行代码;list line_number列出line_number之后的十行代码;

info locals列出当前函数的局部变量;

p var_打印变量值;

info breakpoints列出所有断点;

delete breakpoints删除所有断点;

delete breakpoints id删除编号为id的断点;

disable/enable breakpoints id禁用/启动断点;

break ... if ...条件中断;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/64ec0cd5759bfa40452f88e9f85fc868.html