有没有办法在Linux内核中获取函数调用者?我知道 __func__ 返回正在执行的函数名称。我正在寻找名为“ __func__ ”的函数
最佳答案
您可以使用__builtin_return_address(0)
来获得 call 者。
call 者的 call 者是__builtin_return_address(1)
,依此类推。
这是一个GCC扩展,已在gcc手册中记录:http://gcc.gnu.org/onlinedocs/gcc/Return-Address.html
编辑:我可能应该指出,这可以为您提供 call 者的地址。如果需要函数名称,可以使用%pS
进行打印,例如:
printk("Caller is %pS\n", __builtin_return_address(0));
如果您不想打印它,可以使用
kallsyms_lookup()
等。
关于linux-kernel - Linux内核中的函数调用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4141324/