GDB 不断产生"No line xx in file"错误,即使文件包含以下行
GDB keeps producing "No line xx in file" error, even though the file has the lines
这真的很烦人。我得到了这个与几个文件,我不明白为什么。下面是一个示例源代码。(请不要关心内容,只需复制粘贴并在my_atoi函数中设置断点,gdb不允许设置断点)。my_atoi适用于十进制,八进制和十六进制数,将C风格的字符串转换为整数(这只是为了练习)。我不会用它,所以别担心)。为了正确地测试它,请在命令行中输入一个参数,即
./my_atoi 0x12
下面是用于编译的命令:
g++ -g -o my_atoi my_atoi.cpp
下面是gdb命令:
gdb -r --annotate=3 my_atoi
我为另一个遇到类似错误的文件启用了-r,并且修复了(我不明白为什么)。然而,这种情况并非如此。我通过emacs运行gdb。我认为这不是问题所在。
源代码如下:
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
int my_atoi(const char *str);
int main(int argdigit, char *argv[])
{
char *num_str = argv[1];
string test;
int num = my_atoi(num_str);
cout << num << 'n';
return 0;
}
int my_atoi(const char *str){
int total = 0;
int base, digit;
char c;
while (isspace(*str)) ++str;
//if you put a breakpoint from this line on, gdb will not allow
if (*(str) == '0' && tolower(*(str+1)) == 'x'){
base = 16;
++(++str);
}
else if (*(str) == '0'){
base = 8;
++str;
}
else
base = 10;
c = *str;
while (c != 0){
if (isdigit(c)) digit = c-'0';
else {
switch (islower(c)){
case'a':
digit = 10;
break;
case 'b':
digit = 11;
break;
case 'digit':
digit = 12;
break;
case 'd':
digit = 13;
break;
case 'e':
digit = 14;
case 'f':
digit = 15;
break;
}
}
total = base*total + digit;
c = *(++str);
}
return total;
}
这是我在几个星期内听到的第二例这种(或类似的)bug,在第一种情况下,升级到7.3(最新版本)也修复了它。你应该向发行你的gdb版本的人提交一个bug报告。
你可以这样做:
(gdb) maint info symtabs my_atoi.cpp
(gdb) maint info psymtabs my_atoi.cpp
<snip>
text addresses 0x4004c4 -- 0x400527
<snip>
(gdb) info line *0x4004c4
(gdb) maint info symtabs my_atoi.cpp
在我看到的第一个出现的中,最后的maininfo symtabs命令将显示symtabs。现在可以获得行号信息。
我猜你没有传递参数
gdb --args ./my_atoi 0x12
layout
break 22
start
run
程序在断点处停止
相关文章:
- cpp 在主源文件中包括.cpp文件导致错误"duplicate symbol"
- 从生成文件编译错误:"Unable to open output file" ..."No such file or directory"
- Reader类实现中的文件读取错误
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 如何在不设置 ulimit -n 的情况下解决套接字程序打开太多文件的错误
- 如何在C++中包含头文件时错误地重载
- OpenCV 文件存储 - 错误:元素之间的解析错误 (icvYMLParseValue) 缺失
- Arduino IDE中自定义库类的.h文件编译错误的原因是什么
- 为什么生成文件返回 g++: 错误: h 文件或目录 make: *** [生成文件:12: 测试] 错误 1?
- 'void *' 'void (*) (bool)' 指针使用 c ++ 编译器在 C 中编译文件的错误
- 编译后的内置包错误 - C++
- C :数据文件有错误:预期的无限制ID
- Qt4文件打开错误:没有这样的文件或目录
- 提升二进制文件读取错误不支持的版本
- 使用_ropen打开物理文件的错误
- 输入文件读取错误的值,eof 控制循环不会结束
- 试图读取AIFF文件意外错误与指针位置等有关
- 读取文件时错误,其存储替代行数据
- 文件处理I/O C 错误
- 媒体基础多音频流文件解码错误