c - 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?
解决方案
要回答您问题的“替代”部分,lldb 不支持软件实现的观察点,因为它们实际上并不能很好地工作。因此,像 gdb 一样,我们仅限于您正在运行的机器的硬件资源。但是,除非您要观看的全局变量非常大,否则您应该能够将观察点一个一个地放在它们上。
当然,调试器只能告诉您谁访问了调试会话期间实际运行的代码中的监视数据。因此,如果您想为整个程序提供全面的答案,调试器不是正确的工具。
推荐阅读
- python - SettingWithCopyWarning,不确定我的 df 分配究竟发生在哪里
- java - 在java中使用正则表达式从字符串中获取单词
- html - cakephp - 如何使用 $this->Html->link 作为标签
- powershell - 我可以获取一个文本文件并将其用作变量来搜索大量文件的驱动器上的位置吗?(使用电源外壳)
- javascript - 检查点是否在圆圈内
- regex - 在 Java 8 字符串中搜索列表中是否存在单词
- python-3.x - CX_FREEZE 无法导入 easygui tkinter mo
- javascript - 如何在文本字段上正确创建 Resizer
- pandas - gspread 在谷歌表格顶部添加行
- c# - 将快捷方式从窗口传播到 WPF 中的用户控件