使用 DWARF 信息将内存地址映射到行号
我有一个通过内存跟踪程序执行的应用程序。我尝试使用 readelf --debug-dump=decodedline 来获取内存地址/行号信息,但我看到的内存地址通常与该转储给出的内存地址不匹配。我写了一些东西来将每个地址与 DWARF 数据中出现的“最新”地址相匹配——这似乎清理了一些东西,但我不确定这是否是解释该数据的“官方”方式。
有人可以解释使用 DWARF 将程序地址映射到行号的确切过程吗?
I have an application that traces program execution through memory. I tried to use readelf --debug-dump=decodedline
to get memory address / line # information, but the memory addresses I see don't match up often with the ones given by that dump. I wrote something to match up each address with the "most recent" one appearing in the DWARF data -- this seemed to clean some things up but I'm not sure if that's the "official" way to interpret this data.
Can someone explain the exact process to map a program address to line number using DWARF?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下
addr2line
程序。如果不能完全解决您的问题,它可能会为您提供一些如何执行此操作的指导(例如,通过删除它,或链接其功能)。Have a look at the program
addr2line
. It can probably give you some guidance on how to do this, if not solving your problem entirely (e.g. by shelling out to it, or linking its functionality in).事实上,正如 Phil Miller 的回答所提到的,
addr2line
是你的朋友。我有一个 gist ,其中我展示了如何在(C ++)中获取行号来自从回溯获得的地址的应用程序源代码。遵循此过程不会向您展示您提到的过程,但可以让您了解代码如何映射到目标代码(在可执行文件或库/存档中)。希望有帮助。
Indeed, as mentioned by Phil Miller's answer,
addr2line
is your friend. I have a gist where I show how I get the line number in the (C++) application source code from an address obtained from a backtrace.Following this process will not show you the process you mention, but can give you an idea of how the code gets mapped into the object code (in an executable or a library/archive). Hope it helps.