Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The address where filename has been loaded is missing [GDB]

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

like image 762
user3262212 Avatar asked Feb 02 '14 08:02

user3262212


People also ask

What is symbol-file in gdb?

symbol-file indicates that gdb should use this file as a reference for symbols and debug information. This includes translating a symbol (function or variable name) into an address, a line number into a code address or vice-versa, etc.

How do I add debug symbols in gdb?

To add additional symbols you might use add-symbol-file . The add-symbol-file command reads additional symbol table information from the file filename. You would use this command when filename has been dynamically loaded (by some other means) into the program that is running.

What is File command in gdb?

Use the file command to get both symbol table and program to run from the same file. symbol-file with no argument clears out gdb information on your program's symbol table. The symbol-file command causes gdb to forget the contents of some breakpoints and auto-display expressions.

How gdb works?

GDB allows you to do things like run the program up to a certain point then stop and print out the values of certain variables at that point, or step through the program one line at a time and print out the values of each variable after executing each line. GDB uses a simple command line interface.


1 Answers

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.

like image 127
Employed Russian Avatar answered Sep 25 '22 08:09

Employed Russian