首页 > 解决方案 > How to know what global variables or static variales are referred by what functions? (C)

问题描述

I'd like to know what functions refer (read or write) global or static variables in an executable compiled from C.

I don't think gdb or lldb offer such a function out-of-the-box. Is there some other tool that can do this?

Alternatively, one can get all the global and static variables from gdb/lldb and set a watchpoint on each variable. However, gdb seems not able to allow soft only watchpoint for read as this will require a large number of watchpoints that hardware watchpoints just can not do it. So I'd assume gdb is not appropriate to know what functions refer to what global/static variables.

Is lldb suitable for this task? Is there a ready to use solution for it?

标签: cgdbglobal-variableslldbstatic-variables

解决方案


要回答您问题的“替代”部分,lldb 不支持软件实现的观察点,因为它们实际上并不能很好地工作。因此,像 gdb 一样,我们仅限于您正在运行的机器的硬件资源。但是,除非您要观看的全局变量非常大,否则您应该能够将观察点一个一个地放在它们上。

当然,调试器只能告诉您谁访问了调试会话期间实际运行的代码中的监视数据。因此,如果您想为整个程序提供全面的答案,调试器不是正确的工具。


推荐阅读