Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

gdb

This is really annoying. I got this with several files and I couldn't understand why. Here is an example source code. (Please Just don't care about the content, just copy and paste and set break point somewhere in the my_atoi function, and gdb won't allow to set the break point). my_atoi works with decimal, octal and hexadecimal numbers, convert a C style string which is the representation of a number with those base into an integer (this is just for practicing though. I'm not gonna use it, so don't worry). In order to test it properly, please enter an argument in the command line.i.e.

./my_atoi 0x12

Here is the command for compilation:

g++ -g -o my_atoi my_atoi.cpp

Here is gdb command:

gdb -r --annotate=3 my_atoi

I enabled -r for another file which encounters similar error, and it was fixed (I don't understand why though). However, not for this case. I was running gdb through emacs. I don't think this is the problem.

Here is the source code:

#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;
}
like image 784
Amumu Avatar asked Aug 15 '11 09:08

Amumu


1 Answers

This is the 2nd case of this (or a similar) bug that I have heard of, in as many weeks, In the first case, upgrading to 7.3 (the most recent release) fixed it also. you should file a bug report with whomever distributes your version gdb.

you can possibly work around this by:

(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

in the first occurance I saw, the final maint info symtabs command would show symtabs. and line number information was now available.

like image 188
matt Avatar answered Oct 22 '22 11:10

matt