栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

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

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

一、找到core dump产生的文件 1.打开/etc/profile文件添加如下配置:ulimit -c unlimited
sudo gedit /etc/profile
ulimit -c unlimited
2.在bashrc中进行生效,添加如下配置:source /etc/profile
gedit ~/.bashrc
source /etc/profile
3.设置core文件的目录
sudo sysctl -w kernel.core_pattern=/var/crash/core.%u.%e.%p
4.执行产生错误的可执行程序
./HelloGDB
5.用gdb调试工具查看core文件出现错误的行
gdb HelloGDB /var/crash/core.1000.HelloGDB.4393
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))]

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

6.查看函数调用栈
bt
#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 (__f=@0x561c015aaeb8: 0x561c01500365 ) at /usr/include/c++/9/bits/invoke.h:60
#3  0x0000561c0150124e in std::__invoke (__fn=@0x561c015aaeb8: 0x561c01500365 ) at /usr/include/c++/9/bits/invoke.h:95
#4  0x0000561c015011e0 in std::thread::_Invoker >::_M_invoke<0ul> (this=0x561c015aaeb8) at /usr/include/c++/9/thread:244
#5  0x0000561c0150119d in std::thread::_Invoker >::operator() (this=0x561c015aaeb8) at /usr/include/c++/9/thread:251
--Type  for more, q to quit, c to continue without paging--
#6  0x0000561c0150116e in std::thread::_State_impl > >::_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=) at pthread_create.c:477
#9  0x00007fa7c1180163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

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

暑期编程PK赛 得CSDN机械键盘等精美礼品!
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1015787.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号