【问题标题】:The address where filename has been loaded is missing [GDB]已加载文件名的地址丢失 [GDB]
【发布时间】:2014-02-25 19:37:09
【问题描述】:

我有以下示例代码

    #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;
    }

我用 gcc 的 -g 选项编译了这段代码。

gcc -g file.c

生成单独的符号文件

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

从 a.out 中剥离符号

strip -s a.out

在 gdb 中加载这个 a.out

gdb a.out

gdb 说“没有找到调试信息”很好。 然后我在 gdb 中使用 add-symbol-file 命令

(gdb) add-symbol-file a.out.debug [Enter]
The address where a.out.debug has been loaded is missing
  • 我想知道如何找到这个地址
  • 有什么命令或技巧可以找到吗?
  • 这个地址代表什么?

我知道 gdb 有另一个命令 symbol-file 但它会覆盖之前加载的符号。 所以我必须使用这个命令在 gdb 中添加许多符号文件。 我的系统是 64 位运行 ubuntu LTS 12.04 gdb 版本为 7.4-2012.04 gcc 版本是 4.6.3

【问题讨论】:

    标签: linux gdb memory-address


    【解决方案1】:

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

    如果您希望 GDB 自动加载 a.out.sym,请按照here 列出的步骤操作(特别注意您需要执行“添加.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' 仅提取该行)
    猜你喜欢
    • 2020-06-23
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多