在 iOS 上调试动态库函数调用时,XCode/gdb 丢失堆栈
我有一个 iOS 项目,它链接到用 C++ 编写的外部静态库。静态库调用 libstdc++ 实现的函数,该函数是动态链接的。例如,我调用该库的初始化函数(我们称之为 foo_init()
),它立即调用 setlocale()
。
静态库是使用 -g 编译的,这意味着调试符号可供我单步执行调试器内的代码。我成功进入 foo_init()
。当我尝试单步执行对 setlocale()
的调用时,XCode 并没有完全做到这一点。它最终出现在一个名为 dyld_stub_setlocale 的函数中。该函数是一条jmp
指令,用于执行动态加载和加载。函数调用。
我尝试过跨入/跨入/跨出dyld_stub_setlocale
,但它们没有让我到达我想要的位置,即回到foo_init()
。 Step Over 和 Step In 最终在 stub_helpers
中,而 Step Out 的作用类似于 continue。如果我在 stub_helpers
内尝试 Step Over/In,XCode 单步执行并且显示 foo_init()
的堆栈窗口会更改为 ??
。此时,用于步入/退出的决策树会爆炸,因此我不会详细介绍,但我尝试过的任何组合都不会在调用 setlocale
后返回到该行。
我可以为该行设置一个断点,点击继续,然后让它工作,但这不是一个用于调试我不太熟悉的静态库的可扩展解决方案。
请注意,我试图找到一种方法来链接 libstdc++-static,这样我就可以避免动态加载程序问题,但 Apple 已从较新的 SDK 中删除了该库,而我没有旧的 SDK。
是否有链接器或编译器选项可以使代码更容易被调试器解读?
I've got an iOS project that links to an external static library written in C++. The static library makes calls to functions implemented by libstdc++, which is dynamically linked. For instance, I call the initialization function for this library (let's call it foo_init()
) and it immediately calls setlocale()
.
The static library is compiled with -g, meaning debug symbols are around for me to step into code inside the debugger. I successfully step into foo_init()
. When I attempt to Step Over the call to setlocale()
, XCode doesn't quite do that. It ends up in a function called dyld_stub_setlocale
. This function is a single jmp
instruction to perform the dynamic load & function call.
I've tried Stepping Over/In/Out of dyld_stub_setlocale
but they don't get me where I want, which is back into foo_init()
. Step Over and Step In end up in stub_helpers
, and Step Out acts like continue. If I try Step Over/In inside stub_helpers
, XCode single steps and the stack window displaying foo_init()
changes to ??
. At this point, the decision tree for stepping in/out kind of explodes so I won't go into further details, but no combinations I've tried end up back to the line after the call to setlocale
.
I am able to set a breakpoint for the line, hit continue, and have it work, but this is not a scalable solution for debugging a static library with which I am not very familiar.
Note that I tried to find a way to link libstdc++-static instead so I could avoid the dynamic loader issues, but Apple has removed the library from newer SDKs and I don't have the older ones.
Is there a linker or compiler option to make the code easier for the debugger to decipher?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论