ios Xcode 调试器不打印对象并显示 nil,当它们不是时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19870176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:49:29  来源:igfitidea点击:

Xcode debugger doesn't print objects and shows nil, when they aren't

iosobjective-cxcodedebugging

提问by Binarian

Xcode shows an error when trying to print an object with po <objectName>, but only for one project.

Xcode 在尝试使用 打印对象时显示错误po <objectName>,但仅针对一个项目。

Screenshot

截屏

error: Couldn't materialize struct: size of variable <varName> disagrees with the ValueObject's size Errored out in Execute, couldn't PrepareToExecuteJITExpression

错误:无法实现结构:变量 <varName> 的大小与 ValueObject 的大小不一致 在执行中出错,无法 PrepareToExecuteJITExpression

The Xcode debugger also shows ALL objects as nil(selfexcluded), when they aren't (NSLogshows correct output, as seen in the image). I don't know what's wrong with the project. Every other project works fine.

Xcode 调试器还将所有对象显示为nilself排除),如果它们不是(NSLog显示正确的输出,如图所示)。不知道项目出了什么问题。其他所有项目都运行良好。

Any idea what it could be? (Cleaning the project had no effect.)

知道它可能是什么吗?(清理项目没有效果。)

回答by Mick

Are you sure you are not in "Release mode"?

你确定你不是在“发布模式”?

If you want to see variable values you have to be in "Debug mode" (click on your project name on the top left corner near start/stop buttons, then "Edit scheme...", then "Run" settings, then "Info" tab, then "Build Configuration". Here set "Debug". If it was on "Release" that's the matter you saw all nils).

如果您想查看变量值,您必须处于“调试模式”(单击左上角开始/停止按钮附近的项目名称,然后单击“编辑方案...”,然后单击“运行”设置,然后单击“ Info”选项卡,然后是“Build Configuration”。在这里设置“Debug”。如果它在“Release”上,那你就看到了所有的 nils)。

回答by Leszek Zarna

I've set "Optimization Level" for Debug configuration to "None" and it solved problem.

我已将调试配置的“优化级别”设置为“无”,它解决了问题。

回答by KIO

Make sure that Address Sanitizer is turned off in your Scheme settings. The Address Sanitizer does not work well with the debugger.

确保在您的 Scheme 设置中关闭了 Address Sanitizer。Address Sanitizer 不适用于调试器。

  1. Go to Edit Scheme (Product >> Scheme >> Edit Scheme), choose Run, and go to the Diagnostics tab.
  2. Make sure "Enable Address Sanitizer" is off.
  1. 转到编辑方案(产品 >> 方案 >> 编辑方案),选择运行,然后转到诊断选项卡。
  2. 确保“启用地址清理程序”已关闭。

enter image description here

在此处输入图片说明

回答by LeiHao

It seems everyone has their own solution.

似乎每个人都有自己的解决方案。

For me, I use Objective-Cand Swiftat the same time.

对我来说,我同时使用Objective-CSwift

First of all, go to TARGETS -> Build Settingsand search the code generation

首先,去TARGETS -> Build Settings搜索code generation

You'll find Apple LLVM 6.0and Swift Compiler

你会发现Apple LLVM 6.0Swift Compiler

Change their Optimization Levelall to None, then Debug, you may find the value not nil

把它们Optimization LevelNone改成 , 然后 Debug, 你可能会发现值不是nil

Amazingly once you can see the value, you solve this problem permanently, then you can change the Optimization Levelto it used to be.

令人惊讶的是,一旦您看到该值,您就永久解决了这个问题,然后您可以将其更改Optimization Level为以前的状态。

回答by ThomasW

There are other ways this can occur. For me it was because the "Other C Flags" value was set to "-O2", even for the debug build. Turning this off for the debug build resolved the issue.

还有其他方式可能会发生这种情况。对我来说,这是因为“其他 C 标志”值设置为“-O2”,即使对于调试版本也是如此。为调试版本关闭此功能解决了该问题。

回答by Curmudgeonlybumbly

Filtered debug output

过滤的调试输出

For me, Xcode was filtering out the debugger output. Make sure your output setting is Debugger Output or All Output

对我来说,Xcode 过滤掉了调试器的输出。确保您的输出设置是调试器输出或所有输出

回答by Luke

I just encountered this issue and found that it was because Deployment Postprocessing = YESin the Build Settings.

我刚刚遇到这个问题,发现是因为Deployment Postprocessing = YES在Build Settings中。

Changing this to NOfixed it, as seen in the screenshot below:

更改它以NO修复它,如下面的屏幕截图所示:

enter image description here

在此处输入图片说明

Xcode version: 6.0.1 (6A317) on OSX 10.9.5

Xcode 版本:OSX 10.9.5 上的 6.0.1 (6A317)

回答by Torsten Barthel

I just run into a similar problem: At one point suddenly the Xcode debugger printed out some object types especially NSStrings as (null) although they were initialized with a value. Printed out via

我刚刚遇到了一个类似的问题:有一次 Xcode 调试器突然打印出一些对象类型,尤其是 NSStrings 为 (null),尽管它们是用一个值初始化的。通过打印

NSLog(@"String value: %@", myString);

the correct value for the object was shown.

显示了对象的正确值。

Confusing! Solving the problem was rather easy: I just shut down Xcode and restarted my computer. After I restarted Xcode everything works fine again :).

令人困惑!解决这个问题相当简单:我只是关闭了 Xcode 并重新启动了我的电脑。在我重新启动 Xcode 后,一切又正常了 :)。

回答by llama591

Make sure Link-Time Optimization = Nofor debug mode in Build Settings.

确保Link-Time Optimization = No在构建设置中使用调试模式。

回答by TMin

  1. Delete Derived Data
  2. Quite Xcode / Restart
  3. Clean Project
  1. 删除派生数据
  2. 相当 Xcode / 重新启动
  3. 清洁工程

That's all it took for me.

这就是我所需要的。