c++ - GDB 不断产生 "No line xx in file"错误,即使文件中包含以下行

标签 c++ gdb

这真的很烦人。我用几个文件得到了这个,但我不明白为什么。这是一个示例源代码。 (请不要关心内容,只需复制粘贴并在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;
}

最佳答案

这是我听说的这个(或类似的)错误的第二个案例,在几周内, 在第一种情况下,升级到 7.3(最新版本)也修复了它。 您应该向分发您的 gdb 版本的任何人提交错误报告。

您可以通过以下方式解决此问题:

(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

在我第一次看到时,最后的 maint info symtabs 命令会显示符号表。 行号信息现在可用。

关于c++ - GDB 不断产生 "No line xx in file"错误,即使文件中包含以下行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7063466/

相关文章:

c - 如何跳过 GDB 中循环的多次迭代?

c++ - GDB 如何处理 SIGSEGV

GDB 在 macOS Sierra 上不起作用

python - 构建 CPython 时禁用编译器优化

c++ - 无法从 'g++' 调用获得输出结果

c++ - += 一对运算符和 make_pair 与模板

c++ - 处理导致性能问题的双端队列 block 大小

c++ - 在 TensorFlow C++ 中传递 RunOptions

c++ - GMOCK 参数验证

x86 - gdb信息帧输出: Wrong value for "Arglist at"?