使用GDB到地址转换为线 [英] Using gdb to convert addresses to lines

查看:157
本文介绍了使用GDB到地址转换为线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被剥夺应用程序,它看起来像这样生成的堆栈跟踪:

  ***检查失败的堆栈跟踪:***
    @ 0x7f0e442d392d(未知)
    @ 0x7f0e442d7b1f(未知)
    @ 0x7f0e442d7067(未知)
    @ 0x7f0e442d801d(未知)
    @ 0x7f0e457c55e6(未知)
    @ 0x7f0e457c5696(未知)
    @ 0x4e8765(未知)
    @ 0x4a8b43(未知)
    @ 0x7f0e43197ced(未知)
    @ 0x4a6889(未知)

和我有可执行文件和所有库的非剥离版本(编译时有debug信息)。但是,我怎么能地址转换为文件和行号??

下面是我曾尝试:

  GDB
设置solib-absolute- preFIX /路径/要/非剥离/编辑/的/根目录/文件系统/ SYSROOT /
文件/路径/要/非剥离/编辑/的/根目录/文件系统/ SYSROOT的/ usr / bin中/我-车应用
信息行* 0x7f0e457c5696

当我在文件中键入命令只是将其从文件,而不是它使用的所有库加载符号。有没有一种方法可以做到这一点?

信息线命令说:


  

用于地址0x7f0e442d801d没有行号信息


这我假设是因为地址在共享库之一,但我怎么能知道其中其中之一吗?


解决方案

  

但我怎么能地址转换成文件和行号?


有关主可执行文件(如地址 0x4e8765 )做到这一点:

  addr2line -e /path/to/non-stripped/.../my-buggy-app \\
    0x4a6889 0x4a8b43 0x4e8765

其实,你可能想要从上面所有的减去 5 (即呼叫指令的通常长度)地址。

有关在共享库中的地址,你必须知道库的加载地址。

如果您的应用程序生成一个核心文件,然后(GDB)信息共享将告诉你在哪里库加载

如果你没有得到一个核心文件,应用程序没有打印所需的映射,然后


  • 您应该修复应用程序,以便它不打印信息(堆栈跟踪是没有它大多无用),和

  • 您仍然可以猜测:看在可执行文件中code。在 0x4e8760 - 它应该是一个呼叫指令部分功能。现在发现,功能是在图书馆,并找到了其在库地址(通过纳米)。如果你是幸运的,该地址靠近 0xNc56NN 。现在,您可以猜到的任何图书馆是 0x7f0e457NNNNNN 加载地址。重复 0x7f0e457c55e1 ,您可以在 0x7f0e442dNNNN 找出库的加载地址。

I have a stack trace generated by a stripped application which looks like this:

 *** Check failure stack trace: ***
    @     0x7f0e442d392d  (unknown)
    @     0x7f0e442d7b1f  (unknown)
    @     0x7f0e442d7067  (unknown)
    @     0x7f0e442d801d  (unknown)
    @     0x7f0e457c55e6  (unknown)
    @     0x7f0e457c5696  (unknown)
    @           0x4e8765  (unknown)
    @           0x4a8b43  (unknown)
    @     0x7f0e43197ced  (unknown)
    @           0x4a6889  (unknown)

And I have a non-stripped version of the executable and all of its libraries ( compiled with debug information). But how can I translate the address into files and line numbers??

Here is what I have tried:

gdb
set solib-absolute-prefix /path/to/non-stripped/edition/of/root/filesystem/sysroot/
file /path/to/non-stripped/edition/of/root/filesystem/sysroot/usr/bin/my-buggy-app
info line *0x7f0e457c5696

When I type in the file command it only loads symbols from the file, not all the libraries which are used. Is there a way this can be done?

The "info line" command says:

No line number information available for address 0x7f0e442d801d

Which I assumes is because the address is in one of the shared libraries, but how can I know in which one of them?

解决方案

But how can I translate the address into files and line numbers?

For the main executable (addresses like 0x4e8765) do this:

addr2line -e /path/to/non-stripped/.../my-buggy-app \
    0x4a6889 0x4a8b43 0x4e8765

Actually, you might want to subtract 5 (usual length of the CALL instruction) from all of the above addresses.

For the addresses in shared libraries, you have to know the load address of the library.

If your application produced a core file, then (gdb) info shared will tell you where libraries were loaded.

If you did not get a core file, and the application did not print the required mapping, then

  • you should fix the application so it does print that info (the stack trace is mostly useless without it), and
  • you could still guess: look at the code in the executable at 0x4e8760 -- it should be a CALL instruction to some function. Now find out which library that function is in, and find its address in the library (via nm). If you are lucky, that address is near 0xNc56NN. You can now guess the load address of whatever library is at 0x7f0e457NNNNNN. Repeat for 0x7f0e457c55e1, and you can find out the load address of library at 0x7f0e442dNNNN.

这篇关于使用GDB到地址转换为线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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