Linux 加载文件名的地址缺少[GDB]

Linux 加载文件名的地址缺少[GDB],linux,gdb,memory-address,Linux,Gdb,Memory Address,我有以下示例代码 #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;

我有以下示例代码

    #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;
    }
生成单独的符号文件

objcopy --only-keep-debug a.out a.out.sym
从a.out中去掉符号

strip -s a.out
在gdb中加载此a.out

gdb a.out
gdb说“找不到调试信息”很好。 然后在gdb中使用addsymbolfile命令

(gdb) add-symbol-file a.out.debug [Enter]
The address where a.out.debug has been loaded is missing
  • 我想知道怎么找到这个地址
  • 有什么命令或技巧可以找到它吗
  • 这个地址代表什么
我知道gdb有另一个命令符号文件,但它会覆盖以前加载的符号。 因此,我必须使用此命令在gdb中添加许多符号文件。 我的系统是64位运行UbuntuLTS12.04 gdb版本为7.4-2012.04 gcc版本为4.6.3

objcopy--仅保留调试a.out a.out.sym

如果希望GDB自动加载a.out.sym,请按照概述的步骤进行操作(特别注意,您需要执行“添加
.gnu_debuglink
”步骤)

这个地址代表什么

GDB想要的地址是二进制文件的
.text
部分的位置。要找到它,请使用
readelf-WS a.out
。例如

$ 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

在这里,您希望将GDB
0x401900
作为加载地址。

(您也可以使用
|grep.text'
仅提取该行)
$ 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