当前位置:   article > 正文

gdb+vscode进行调试7——程序出现segmentation default/段错误,如何进行调试?_vscode段错误

vscode段错误

一、找到core dump产生的文件

1.打开/etc/profile文件添加如下配置:ulimit -c unlimited

sudo gedit /etc/profile
  • 1
ulimit -c unlimited
  • 1

2.在bashrc中进行生效,添加如下配置:source /etc/profile

gedit ~/.bashrc
  • 1
source /etc/profile
  • 1

3.设置core文件的目录

sudo sysctl -w kernel.core_pattern=/var/crash/core.%u.%e.%p
  • 1

4.执行产生错误的可执行程序

./HelloGDB
  • 1

5.用gdb调试工具查看core文件出现错误的行

gdb HelloGDB /var/crash/core.1000.HelloGDB.4393
  • 1
Core was generated by `/home/bisheng/CLionProjects/gdb/cmake-build-debug/HelloGDB'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000561c01500301 in fun1 () at /home/bisheng/CLionProjects/gdb/fun.h:6
6           *p = 0;
[Current thread is 1 (Thread 0x7fa7c0f0c700 (LWP 4818))]
  • 1
  • 2
  • 3
  • 4
  • 5

可以看出,上述core dump
1)是由/home/bisheng/CLionProjects/gdb/cmake-build-debug/HelloGDB这个可执行程序产生的;
2)是在fun.h这个函数的第6行*p = 0产生的
3)产生core dump的线程是线程1

6.查看函数调用栈

bt
  • 1
#0  0x0000561c01500301 in fun1 () at /home/bisheng/CLionProjects/gdb/fun.h:6
#1  0x0000561c015003ad in thread1 () at /home/bisheng/CLionProjects/gdb/main.cpp:12
#2  0x0000561c015012b6 in std::__invoke_impl<void, void (*)()> (__f=@0x561c015aaeb8: 0x561c01500365 <thread1()>) at /usr/include/c++/9/bits/invoke.h:60
#3  0x0000561c0150124e in std::__invoke<void (*)()> (__fn=@0x561c015aaeb8: 0x561c01500365 <thread1()>) at /usr/include/c++/9/bits/invoke.h:95
#4  0x0000561c015011e0 in std::thread::_Invoker<std::tuple<void (*)()> >::_M_invoke<0ul> (this=0x561c015aaeb8) at /usr/include/c++/9/thread:244
#5  0x0000561c0150119d in std::thread::_Invoker<std::tuple<void (*)()> >::operator() (this=0x561c015aaeb8) at /usr/include/c++/9/thread:251
--Type <RET> for more, q to quit, c to continue without paging--
#6  0x0000561c0150116e in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)()> > >::_M_run (this=0x561c015aaeb0) at /usr/include/c++/9/thread:195
#7  0x00007fa7c1344de4 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#8  0x00007fa7c1458609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#9  0x00007fa7c1180163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

可以看到函数依次的调用顺序

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/366647
推荐阅读
相关标签
  

闽ICP备14008679号