【VSC】ERROR:GDB exited unexpectedly.
【VSC】ERROR:GDB exited unexpectedly.
记录一次调试所遇bug的查找历程
问题描述
ERROR: GDB exited unexpectedly. Debugging will now abort.
The program has exited with code -1 (0xffffffff).
vscode成功进入gdb调试,运行过程中意外退出。
bug案发现场
图1 案发现场
源代码
main.cpp
#include <iostream>
#include "13.h"
int main()
{
Solution soLuTion;
std::cout << soLuTion.romanToInt("MCMXCIV") << std::endl;
std::cout << sizeof("MCMXCIV") << std::endl;
return 0;
}
13.cpp
#include <iostream>
#include <string>
#include "13.h"
int Solution::romanToInt(std::string s)
{
// std::cout << s[0] << std::endl;
int tempNum = 0;
char tempChar = '0';
for (int getC = 0; getC < s.size(); getC++)
{
switch (s[getC])
{
case 'I':
tempNum += 1;
break;
case 'V':
if (tempChar == 'I')
{
tempNum += 4 - 1;
}
else
{
tempNum += 5;
}
break;
case 'X':
if (tempChar == 'I')
{
tempNum += 9 - 1;
}
else
{
tempNum += 10;
}
break;
case 'L':
if (tempChar == 'X')
{
tempNum += 40 - 10;
}
else
{
tempNum += 50;
}
break;
case 'C':
if (tempChar == 'X')
{
tempNum += 90 - 10;
}
else
{
tempNum += 100;
}
break;
case 'D':
if (tempChar == 'C')
{
tempNum += 400 -100;
}
else
{
tempNum += 500;
}
break;
case 'M':
if (tempChar == 'C')
{
tempNum += 900 - 100;
}
else
{
tempNum += 1000;
}
break;
default:
break;
}
tempChar = s[getC];
}
return tempNum;
}
13.h
#pragma once
#include <string>
class Solution
{
public:
int romanToInt(std::string s);
};
更多日志
=thread-group-added,id="i1"
GNU gdb (GDB) 8.1
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 "x86_64-w64-mingw32".
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".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
[New Thread 15724.0x744]
[New Thread 15724.0x258c]
[New Thread 15724.0x2ba0]
[New Thread 15724.0x2950]
Thread 1 hit Breakpoint 1, main () at D:\myproject\CPP\learn\leecode\main.cpp:6
6 std:: cout << soLuTion.romanToInt("MCMXCIV") << std::endl;
Loaded 'C:\Windows\SYSTEM32\ntdll.dll'. Symbols loaded.
Loaded 'C:\Windows\System32\kernel32.dll'. Symbols loaded.
Loaded 'C:\Windows\System32\KernelBase.dll'. Symbols loaded.
Loaded 'C:\Windows\System32\msvcrt.dll'. Symbols loaded.
Loaded 'D:\solfware\mingw64\mingw64\opt\bin\libgcc_s_seh-1.dll'. Symbols loaded.
Loaded 'D:\solfware\mingw64\mingw64\opt\bin\libwinpthread-1.dll'. Symbols loaded.
Loaded 'D:\solfware\mingw64\mingw64\bin\libstdc++-6.dll'. Symbols loaded.
Loaded 'C:\Windows\System32\user32.dll'. Symbols loaded.
Loaded 'C:\Windows\System32\win32u.dll'. Symbols loaded.
Loaded 'C:\Windows\System32\gdi32.dll'. Symbols loaded.
Loaded 'C:\Windows\System32\gdi32full.dll'. Symbols loaded.
Loaded 'C:\Windows\System32\msvcp_win.dll'. Symbols loaded.
Loaded 'C:\Windows\System32\ucrtbase.dll'. Symbols loaded.
Loaded 'C:\Windows\System32\imm32.dll'. Symbols loaded.
Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)
ERROR: GDB exited unexpectedly. Debugging will now abort.
The program 'D:\myproject\CPP\learn\leecode\build\13' has exited with code -1 (0xffffffff).
launch.json文件配置
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\build\\13",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\solfware\\mingw64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
使用平台
OS: WIN 10 64bit
g++ --version: g++.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
gdb --version: GNU gdb (GDB) 8.1
vscode version: 1.67.0
问题排查
看看是不是gdb的问题
使用gdb命令行调试
gdb .\13.exe
调试过程
(gdb) b 6
Breakpoint 2 at 0x401563: file D:\myproject\CPP\learn\leecode\main.cpp, line 6.
(gdb) r
Starting program: D:\myproject\CPP\learn\leecode\build\13.exe
[New Thread 5436.0x241c]
[New Thread 5436.0x3e9c]
[New Thread 5436.0x2b38]
[New Thread 5436.0x2ec0]
Thread 1 hit Breakpoint 2, main () at D:\myproject\CPP\learn\leecode\main.cpp:6
6 std:: cout << soLuTion.romanToInt("MCMXCIV") << std::endl;
(gdb) s
Solution::romanToInt (this=0x62fddf, s="MCMXCIV") at D:\myproject\CPP\learn\leecode\13.cpp:7
7 int tempNum = 0;
(gdb) watch tempNum
Hardware watchpoint 3: tempNum
(gdb) n
8 char tempChar = '0';
(gdb) n
9 for (int getC = 0; getC < s.size(); getC++)
(gdb) n
11 switch (s[getC])
(gdb) c
Continuing.
Thread 1 hit Hardware watchpoint 3: tempNum
Old value = 0
New value = 1000
Solution::romanToInt (this=0x62fddf, s="MCMXCIV") at D:\myproject\CPP\learn\leecode\13.cpp:75
75 break;
(gdb) c
Continuing.
Thread 1 hit Hardware watchpoint 3: tempNum
Old value = 1000
New value = 1100
Solution::romanToInt (this=0x62fddf, s="MCMXCIV") at D:\myproject\CPP\learn\leecode\13.cpp:55
55 break;
(gdb) c
Continuing.
Thread 1 hit Hardware watchpoint 3: tempNum
Old value = 1100
New value = 1900
Solution::romanToInt (this=0x62fddf, s="MCMXCIV") at D:\myproject\CPP\learn\leecode\13.cpp:75
75 break;
(gdb) c
Continuing.
Thread 1 hit Hardware watchpoint 3: tempNum
Old value = 1900
New value = 1910
Solution::romanToInt (this=0x62fddf, s="MCMXCIV") at D:\myproject\CPP\learn\leecode\13.cpp:35
35 break;
(gdb) c
Continuing.
Thread 1 hit Hardware watchpoint 3: tempNum
Old value = 1910
New value = 1990
Solution::romanToInt (this=0x62fddf, s="MCMXCIV") at D:\myproject\CPP\learn\leecode\13.cpp:55
55 break;
(gdb) c
Continuing.
Thread 1 hit Hardware watchpoint 3: tempNum
Old value = 1990
New value = 1991
Solution::romanToInt (this=0x62fddf, s="MCMXCIV") at D:\myproject\CPP\learn\leecode\13.cpp:15
15 break;
(gdb) c
Continuing.
Thread 1 hit Hardware watchpoint 3: tempNum
Old value = 1991
New value = 1994
Solution::romanToInt (this=0x62fddf, s="MCMXCIV") at D:\myproject\CPP\learn\leecode\13.cpp:25
25 break;
(gdb) c
Continuing.
Watchpoint 3 deleted because the program has left the block in
which its expression is valid.
0x0000000000401599 in main () at D:\myproject\CPP\learn\leecode\main.cpp:6
6 std:: cout << soLuTion.romanToInt("MCMXCIV") << std::endl;
(gdb) c
Continuing.
1994
[Thread 5436.0x2ec0 exited with code 0]
[Thread 5436.0x2b38 exited with code 0]
[Thread 5436.0x3e9c exited with code 0]
[Inferior 1 (process 5436) exited normally]
可以看出gdb是可以正常调试的,那么应该不是gdb的问题(误)
看看是不是平台的问题
同样的程序我跑到ubuntu虚拟机上用VSCdebug,是可以正常调试的。
内核版本
LINUX: 5.4.0-109-generic
Ubuntu:18.04.1
GCC: 7.5.0
GDB: 8.1.1
成功快照
图2 linux虚拟机平台
ok,真相了,是平台的差异导致的。那到底是哪里的差异呢?
灵机一动:如果我不watch变量看看
我不watch特定变量,在WIN10下试试debug
图3 不用watch
是可行的!那么找到突破口了,经过我的测试,我找到了引起意外退出的罪魁祸首,s[getC]。
Howerver
在我的虚拟机里,在创建getC这个变量的时候,会先给getC赋个值,具体可以观察图2,这个是是随机的一长串数字,有时是正,有时是负,大概有-996661983,有297860271等,一开始我想到了越界的问题,但是对于虚拟机来讲,它是可以正常调试的,getC的值在创建前的那一刹那会附一个上述的那些值,但这应该不是重点,因为创建完它就被赋予了0,然后我watch s[getC]也不应该有影响。
会不会是gdb版本的问题
回到我的WIN10环境,我不禁陷入了沉思,我又看了看两种环境下gdb的版本,决定再验证一下是不是gdb的问题。
再一次使用gdb命令行调试,我特意watch 了 s[getC],你猜怎么着,也闪退了。
调试过程
(gdb) l
1 #include <iostream>
2 #include "13.h"
3 int main()
4 {
5 Solution soLuTion;
6 std::cout << soLuTion.romanToInt("MCMXCIV") << std::endl;
7 std::cout << sizeof("MCMXCIV") << std::endl;
8 return 0;
9 }(gdb) b 6
Breakpoint 1 at 0x401563: file D:\myproject\CPP\learn\leecode\main.cpp, line 6.
(gdb) r
Starting program: D:\myproject\CPP\learn\leecode\build\13.exe
[New Thread 17844.0x18a4]
[New Thread 17844.0x33c]
[New Thread 17844.0x2960]
[New Thread 17844.0x4300]
Thread 1 hit Breakpoint 1, main () at D:\myproject\CPP\learn\leecode\main.cpp:6
6 std::cout << soLuTion.romanToInt("MCMXCIV") << std::endl;
(gdb) s
Solution::romanToInt (this=0x62fddf, s="MCMXCIV") at D:\myproject\CPP\learn\leecode\13.cpp:7
7 int tempNum = 0;
(gdb) watch s[getC]
No symbol "getC" in current context.
(gdb) n
8 char tempChar = '0';
(gdb) n
9 for (int getC = 0; getC < s.size(); getC++)
(gdb) watch s[getC]
PS D:\myproject\CPP\learn\leecode\build>
嗯,我大概找到原因了,ERROR: GDB exited unexpectedly.这个错误是由
gdb 8.1 在调试我程序里的变量 s[getC] 时造成的。
结论
gdb 8.1极有可能存在某个bug会造成我所遇到的 gdb exited unexpected。
在网上冲了会浪,发现有人也遇到了和我同样的问题。某不知名人士所遇得bug。他的问题几乎和我相同,同样的string,同样的去watch string里的一个字符,同样的for循环,哈哈,这是变相遇到知音了。
github里也有个issue差不多佐证了我的想法。
【VSC】ERROR:GDB exited unexpectedly.的更多相关文章
- 【matlab】error:试图访问 im2(1,1211);由于 size(im2)=[675,1210],索引超出范围。
试图访问 im2(1,1211):由于 size(im2)=[675,1210],索引超出范围. 出错 dect (line 14) if abs((im2(i,j))-(im1(i,j)))> ...
- 【BZOJ】1002:轮状病毒(基尔霍夫矩阵【附公式推导】或打表)
Description 轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生的.一个N轮状基由圆环上N个不同的基原子和圆心处一个核原子构成的,2个原子之间的边表示这2个原子之间的信息通道.如下图 ...
- 【NLP】前戏:一起走进条件随机场(一)
前戏:一起走进条件随机场 作者:白宁超 2016年8月2日13:59:46 [摘要]:条件随机场用于序列标注,数据分割等自然语言处理中,表现出很好的效果.在中文分词.中文人名识别和歧义消解等任务中都有 ...
- 【NLP】蓦然回首:谈谈学习模型的评估系列文章(一)
统计角度窥视模型概念 作者:白宁超 2016年7月18日17:18:43 摘要:写本文的初衷源于基于HMM模型序列标注的一个实验,实验完成之后,迫切想知道采用的序列标注模型的好坏,有哪些指标可以度量. ...
- 【scikit-learn】06:make_blobs聚类数据生成器
版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/kevinelstri/article/ ...
- 【7】解决:移动端点击a链接出现蓝色边框
[1]_blank : 浏览器总在一个新打开.未命名的窗口中载入目标文档. [2]title : 鼠标悬浮显示的文字. [3]href : 跳转到哪个链接. a{ border: no ...
- 【大数据面试】【框架】Flume:Source的断点续传、重复数据、Channel选择
〇.用途 流式结构 获取磁盘日志,拦截器过滤后,传递指定数据,写入HDFS或kafka 一.组成-Source.Channel.Sink 事务(put/take) 1.Source---taildir ...
- 【故障处理】ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
今天在使用冷备份文件重做从库时遇到一个报错,值得研究一下. 版本:MySQL5.6.27 一.报错现象 dba:(none)> start slave; ERROR (HY000): Slave ...
- 【转】Error:JAVA_HOME is not set and could not be found
如果stop-dfs.sh也报了这个错,把$HADOOP_HOME/libexec/hadoop-config.sh中的如下内容之前加上 export JAVA_HOME=/home/lqr/Tool ...
- 【解决】ERROR in xxx.js from UglifyJs
当我们运行打包脚本npm run build或者打包iosweexpack build ios有可能会遇到以下报错 ERROR in index.js from UglifyJs ![](https: ...
随机推荐
- MySQL日期/时间函数
1.查询当前时间函数: select NOW(),LOCALTIME(),SYSDATE(),CURRENT_TIMESTAMP(); 但是now()与sysdate()有点差异的,一个语句中now( ...
- docker从C盘迁移到D盘
docker镜像在C盘占据大量的空间,将.docker从C:\Users\Administrator迁移到E:\.docker. 一.关闭virtual Box 使virtual Box处于关闭.停止 ...
- mac中Mysql各种版本下载
https://downloads.mysql.com/archives/community/ 安装后,5.8以下修改密码,参考 https://www.cnblogs.com/xuyin/p/121 ...
- mysq 报错, sql语句在数据库里运行正常, 在内网测试正常,打包放外网的时候就报下面错误
sql语句为: select t1.day as day , any_value(IFNULL(t2.avgNum,0)) as avgNum, any_value(IFNULL(t2.maxNum, ...
- web端测试的测试点和注意事项【转载】
文章来源:作者:simplesally 出处:https://www.cnblogs.com/simple1025/ [转载] 工作中接触了不同类型的web端系统,内容不同,需求不同,测试关注点也 ...
- Python 删除文件及文件夹
2种方式: [不删除给定的目录] path1 = "D:\\dev\\workspace\\python\\pytestDemo\\222" def del_filedir(pat ...
- plsql链接oracle
安装两个oracle文件夹在一个database中,安装plsql 要先配置两个都要修改,不然会找不到服务器 管理员运行 监听服务/监听位置和数据库服务都要修改 ass文件---监听程序配置 和本场 ...
- jquery 判断字符串长度
function titleLength(str) { var strLength = 0; var list = str.split(""); for (var i = 0; i ...
- jmeter 压测的执行步骤步骤
一.设置测试参数 如图 Number of Threads:总共起多少个线程. Ramp-UP Period(in seconds):多少秒启动完所有线程. loop Count:循环次数 Sched ...
- linux中安装启动postgresql教程
安装: 官网地址:https://www.postgresql.org 选择下载版本: https://www.postgresql.org/ftp/source 下载方式: wget https:/ ...