gdb调试共享库<优化掉>问题

发布于 2025-01-07 05:43:46 字数 378 浏览 0 评论 0原文

我正在尝试使用 gdb 来调试共享库,

当单步执行共享库中的函数时,我已经开始为所有局部变量(用 C 编写)获取

我'我尝试过链接到共享库(.so)链接到静态库(.a)确保Makefile中没有设置优化,即为库和库线束设置了-O0和-g

奇怪的事情我能够之前调试它, 最近才出现,但我不知道为什么,例如我最初能够看到局部变量

我知道这是一个模糊的问题,还有各种进一步的问题我可能需要提供信息来对其进行排序,例如 Makefile、源代码等,但可能有人从这个高级描述中认识到问题并可以提供潜在的修复方案?

I'm trying to use gdb to debug a shared library

when stepping into the function in the shared library I've started getting <optimized out> for all the local variables (written in C)

I've tried linking to a shared library (.so) linking to a static library (.a) making sure no optimisations are set in the Makefiles, i.e. -O0 and -g is set for both the library and the library harness

The strange thing I was able to debug it previously, <optimized out> has only appeared recently but I have no idea why, e.g. I was able to see the local variable originally

I know this is a vague question and theres all sorts of further info I may need to provide to sort it, e.g. Makefiles, source code etc. but possibly someone recognises the problem from this high level description and can offer a potential fix?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不顾 2025-01-14 05:43:46

最近才出现,但我不知道为什么

只能在调试优化代码时出现。

由于您已验证编译行中不存在 -O* 标志(不要只查看 Makefile,请检查实际 编译日志),逻辑结论是有人在系统的其他地方安装了不同(优化)版本的库,并且您正在链接到那个版本。

在 Linux(和许多其他 UNIX 系统)上,您可以将 -Wl,-t 标志添加到链接行,并查看链接时实际使用的库。

当使用共享库时,GDB info shared 命令会告诉您在运行时选择了哪个库。

only appeared recently but I have no idea why

The <optimized out> can only appear when you debug optimized code.

Since you've verified that no -O* flags are present in your compile lines (don't just look in the Makefile, examine the actual compile log), the logical conclusion is that someone installed a different (optimized) version of your library somewhere else on the system, and that you are linking to that version.

On Linux (and many other UNIX systems) you can add -Wl,-t flag to your link line, and see which library is actually used at link time.

When using a shared library, GDB info shared command will tell you which library is picked up at runtime.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文