有没有办法在运行时访问调试符号? [英] Is there a way to access debug symbols at run time?

查看:49
本文介绍了有没有办法在运行时访问调试符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一些示例代码,可以让您了解我想要什么.

Here's some example code to give an idea of what I want.

int regular_function(void)
{
     int x,y,z;
     /** do some stuff **/
     my_api_call();
     return x;
}
...
void my_api_call(void)
{
    char* caller = get_caller_file();
    int line = get_caller_line();
    printf("I was called from %s:%d\n", caller, line);
}

有没有办法实现get_caller_file()get_caller_line()?我已经看到/使用了像 #defineing my_api_call 这样的技巧作为传入 __FILE____LINE__ 的函数调用宏.我想知道是否有办法在运行时而不是编译时访问该信息(假设它存在)?难道像 Valgrind 这样的东西不是必须做这样的事情才能得到它返回的信息吗?

Is there a way to implement the get_caller_file() and get_caller_line()? I've seen/used tricks like #defineing my_api_call as a function call passing in the __FILE__ and __LINE__ macros. I was wondering if there was a way to access that information (assuming it's present) at run time instead of compile time? Wouldn't something like Valgrind have to do something like this in order to get the information it returns?

推荐答案

如果您使用调试符号编译了二进制文件,您可以使用特殊库访问它,例如 libdwarf 用于 DWARF 调试格式.

If you have compiled your binary with debug symbols, you may access it using special libraries, like libdwarf for DWARF debug format.

这篇关于有没有办法在运行时访问调试符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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