1

I'm using Red Hat 4.4.7-3 and gcc 4.8.3

I have code in two files(test.c and sum.c) and I compiled them separately with gcc(with debug information). In the last phase when I'm making the final output by combining both files, debug information is lost.

test.c:

int main()
{

    int a=5,b=7;
    int c=testsum(a,b);

    printf("%d + %d=%d\n",a,b,c);
    return 0;
}



sum.c:
int testsum(int a, int b)
{
    return a+b;
}

I did the following:

gcc -c -g test.c -o test.o
gcc -c -g sum.c -o sum.o

gcc -g test.o sum.o -o output

When I do gdb sum.o then it is showing the line number information

(gdb) l testsum
1   int testsum(int a, int b)
2   {
3       return a+b;
4   }

but with the gdb output I'm not getting line number information.

(gdb) l testsum 
No line number known for testsum.
(gdb)

I repeated the same thing on my personal laptop(gcc-4.8.real (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1) and here it is working perfectly fine. But I need the debug information in the final output on the redhat machine for some project.

Any suggestions/comments regarding obtaining the line number information in final executable would be much appreciated.

Suraj
  • 27
  • 7
  • BTW: just tried this on uptodate CentOS 6.5 32&64 bit (gcc 4.4.7-4, binutils 2.20.51... and gdb 7.2) and it this works as expected. It also works fine with developers toolset (2.1). It seem you have something messed up on your system. – dbrank0 Aug 20 '14 at 08:39
  • This answer may apply: http://stackoverflow.com/a/18408197/2554472 . gcc 4.8 will by default emit debugging info in a format that can't be recognized by older versions of gdb. – Mark Plotnick Aug 20 '14 at 14:09

1 Answers1

1

You need to compile and link with gcc -g. Perhaps you forgot the -g flag at link time.

And use surely want to compile with gcc -Wall -g since warnings are incredibly useful.

You should run gdb on the ELF executable file, not on object files (so gdb sum.o is wrong):

gdb ./output

You should have a Makefile (see this example) and build your program using GNU make

Perhaps the gdb on the remote Redhat server is not accepting the same DWARF format than on your local laptop. Check the versions of gdb. (Perhaps consider compiling on the remote sever, or passing some explicit debugging option like -gdwarf-3 or whatever is appropriate for the remote gdb to your gcc laptop compiler).

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547