linux-kernel - Linux内核中的函数调用程序

标签 linux-kernel linux-device-driver embedded-linux kernel kernel-mode

有没有办法在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/

相关文章:

android - 检查/dev/input/eventX是否遵守多点触摸协议(protocol)或单点触摸协议(protocol)

c - 为什么 mmap 会失败?

linux -/dev/tty* 的设备节点未为 uart 串行驱动程序创建

c - 是write系统调用减少内存写周期如何处理

c - OMAP4460 UART 如何实现全双工传输?

linux-kernel - 内核崩溃 - 不同步 : Requested init/linuxrc failed (error -2)

linux - 在 docker 容器中挂载 cgroup

c - 我如何读取 sysfs 属性

linux - 如何从 Linux 内核模块的 init_module 代码创 build 备节点?

linux-kernel - 如何在驱动模块中使用 seq_file 实现可写的 proc 文件