I have following sample code

    #include<stdio.h>
    int main()
    {
      int num1, num2;
      printf("Enter two numbers\n");
      scanf("%d",&num1);
      scanf("%d",&num2);
      int i;
      for(i = 0; i < num2; i++)
        num1 = num1 + num1;
      printf("Result is %d \n",num1);
          return 0;
    }

I compiled this code with -g option to gcc.

gcc -g file.c

Generate separate symbol file

objcopy --only-keep-debug a.out a.out.sym

Strip the symbols from a.out

strip -s a.out

Load this a.out in gdb

gdb a.out

gdb says "no debug information found" fine. Then I use add-symbol-file command in gdb

(gdb) add-symbol-file a.out.debug [Enter]
The address where a.out.debug has been loaded is missing
  • I want to know how to find this address?
  • Is there any command or trick to find it?
  • This address is representing WHAT?

I know gdb has an other command symbol-file but it overwrites the previous loaded symbols. So I have to use this command to add many symbol files in gdb. my system is 64bit running ubuntu LTS 12.04 gdb version is 7.4-2012.04 gcc version is 4.6.3

有帮助吗?

解决方案

objcopy --only-keep-debug a.out a.out.sym

If you want GDB to load the a.out.sym automatically, follow the steps outlined here (note in particular that you need to do the "add .gnu_debuglink" step).

This address is representing WHAT

The address GDB wants is the location of .text section of the binary. To find it, use readelf -WS a.out. E.g.

$ readelf -WS /bin/date
There are 28 section headers, starting at offset 0xe350:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .interp           PROGBITS        0000000000400238 000238 00001c 00   A  0   0  1
...
  [13] .text             PROGBITS        0000000000401900 001900 0077f8 00  AX  0   0 16

Here, you want to give GDB 0x401900 as the load address.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top