已加载文件名的地址丢失 [GDB] [英] The address where filename has been loaded is missing [GDB]

查看:13
本文介绍了已加载文件名的地址丢失 [GDB]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下示例代码

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

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

I compiled this code with -g option to gcc.

gcc -g file.c

生成单独的符号文件

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

从 a.out 中剥离符号

Strip the symbols from a.out

strip -s a.out

在 gdb 中加载这个 a.out

Load this a.out in gdb

gdb a.out

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

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

      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

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

      如果您希望 GDB自动加载 a.out.sym,请按照 here(特别注意,您需要执行添加.gnu_debuglink"步骤).

      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).

      这个地址代表什么

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

      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
      

      这里,你要给GDB 0x401900 作为加载地址.

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

      这篇关于已加载文件名的地址丢失 [GDB]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆