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

GDB keeps producing "No line xx in file" error, even though the file has the lines

本文关键字:文件包 错误 in No GDB xx line file      更新时间:2023-10-16

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

程序在断点处停止