简体   繁体   English

使用 libunwind 获取模块地址

[英]Getting module addresses with libunwind

I extract the instruction pointer from a stackframe using libunwind like this:我使用 libunwind 从堆栈帧中提取指令指针,如下所示:

unw_get_reg ( &cursor, UNW_REG_IP, &ip );

However, this only gives me the dynamic addresses of the function pointers.但是,这只给了我函数指针的动态地址。 I would like to receive the static addresses in the modules so I can query them via addr2line.我想接收模块中的静态地址,以便我可以通过 addr2line 查询它们。

A different thread didn't receive an answer back then.一个不同的线程当时没有收到答案。 Do you know how to achieve this info?你知道如何获得这些信息吗?

Regards问候

Assuming that by static address you mean offset from the start of the module where the function resides, you may use dladdr(ip, info) where info.dli_fbase gives you the base address of the loaded module.假设静态地址是指从函数所在模块的开头偏移,您可以使用dladdr(ip, info)其中info.dli_fbase为您提供加载模块的基址。 Then (pc - info.dli_fbase) gives you the offset of this function from the start of the module.然后(pc - info.dli_fbase)为您提供此函数从模块开始处的偏移量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM