lldb错误:变量不可用 [英] lldb error: variable not available

查看:755
本文介绍了lldb错误:变量不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的两行代码:

NSString *frontFilePath = [[NSBundle mainBundle] pathForResource:[self.bookendFileNames objectAtIndex:self.randomIndex] ofType:@"caf"];
NSLog(@"frontFilePath = %@", frontFilePath );

我在第二行设置了一个断点,当我在那里时,我尝试打印它:

I put a break point on the second line and when there, I try to print it:

(lldb) po frontFilePath

但我收到以下错误:

error: variable not available

我很困惑,因为如果我跳过NSLog语句,变量确实会打印到控制台。

I'm confused because if I step over the NSLog statement, the variable does indeed print to the console.

对于它的价值,我正在尝试调试第一行,因为有时它返回NULL,所以我不能,如现在,找出原因。

For what it's worth, I'm trying to debug the first line since sometimes it returns NULL, tho I can't, as of now, figure out why.

推荐答案

这是调试优化代码的工件。在构建设置中启用编译器优化时,它会在内存和寄存器之间移动变量,因为它决定最佳。在您检查lldb中的变量时,它可能根本不存在于寄存器或内存中 - 即使看起来它仍然可以显示。

This is an artifact of debugging optimized code. When the compiler's optimization is enabled in your build settings, it moves variables between memory and registers as it decides is best. At the point where you're examining the variable in lldb, it may not exist in registers or memory at all -- even though it looks like it should still be available for display.

这可能是编译器输出的调试信息的缺点。有时,编译器会将变量复制到寄存器中以供其使用,并且仅在调试信息中列出该寄存器位置。之后,登记册被重新用于其他用途;值仍然存在于堆栈中,但编译器没有告诉调试器可以在那里找到值。

It's possible it is a shortcoming of the debug information output by the compiler. Sometimes the compiler will copy a variable into a register for its use and only list that register location in the debug information. Later the register is repurposed for other uses; value is still present on the stack but the compiler hasn't told the debugger that the value can be found there.

真正判断调试信息是否不足的唯一方法或者如果在该特定指令中确实不存在该值,则是手动检查汇编代码。一旦你用编译器打开优化,源代码就会变成一个弱视图,看看实际上正在以任何特定顺序执行的内容。

The only way to really tell whether it's insufficient debug info or if the value genuinely doesn't exist at that particular instruction is to examine the assembly code by hand. As soon as you turn on optimization with the compiler, the source code becomes a weak view into what's actually being executed in any particular order.

而不是徘徊太远古怪的优化代码调试世界,我强烈建议关闭优化(构建设置中的优化级别),以便构建和调试,如果可能的话。如果您确实需要通过优化调试您的应用程序,请确保您使用Xcode支持的最新Apple LLVM编译器进行构建 - 始终有一些工作要做,以改进优化的代码调试,并且您希望利用自己的最佳功能你可以使用迄今为止的工具。

Instead of wandering too far into the wacky world of optimized code debugging, I strongly recommend turning off optimization (Optimization Level in your Build Settings) for your build and debugging it that way, if at all possible. If you do need to debug your app with optimization, make sure you're building with the latest Apple LLVM compiler supported by your Xcode -- there is always work being done to improve optimized code debugging and you want to avail yourself of the most up to date tools you can.

这篇关于lldb错误:变量不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆