Xcode调试器不打印对象,显示为nil,而它们不是。

时间:2021-09-23 20:44:48

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

当尝试用po 打印对象时,Xcode会显示一个错误,但只对一个项目进行打印。

Xcode调试器不打印对象,显示为nil,而它们不是。

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

错误:无法实现结构:变量 的大小与执行时的ValueObject的大小不一致,不能准备执行。

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

Xcode调试器还将所有对象显示为nil (self除外),当它们不是(NSLog显示正确的输出时,如图所示)。我不知道这个项目出了什么问题。其他项目都很好。

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

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

14 个解决方案

#1


246  

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).

如果你想看到变量值,你必须在“调试模式”(点击你的项目名称在左上角靠近start/stop按钮,然后“编辑scheme…”然后,“运行”设置,然后是“Info”选项卡,然后是“构建配置”。在这里设置“调试”。如果是在“释放”,那就是你看到的所有的nils。

#2


32  

I've set "optimisation level" for Debug configuration to "None" and it solved problem.

我已经将调试配置的“optimisation level”设置为“None”,并解决了问题。

#3


24  

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

确保在您的方案设置中关闭了地址消毒剂。地址清除器与调试器不能很好地工作。

  1. Go to Edit Scheme (Product >> Scheme >> Edit Scheme), choose Run, and go to the Diagnostics tab.
  2. 编辑方案(产品>>方案>>编辑方案),选择运行,并进入诊断选项卡。
  3. Make sure "Enable Address Sanitizer" is off.
  4. 确保“启用地址消毒剂”关闭。

Xcode调试器不打印对象,显示为nil,而它们不是。

#4


13  

It seems everyone has their own solution.

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

For me, I use Objective-C and Swift at the same time.

对我来说,我同时使用Objective-C和Swift。

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

首先,转到目标->构建设置并搜索代码生成。

You’ll find Apple LLVM 6.0 and Swift Compiler

你会发现苹果LLVM 6.0和Swift编译器。

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

将它们的优化级别更改为None,然后调试,您可能会发现值不是nil。

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

令人惊讶的是,一旦您看到了这个值,您就可以永久地解决这个问题,然后您就可以将优化级别更改为原来的值。

#5


11  

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”,甚至用于调试构建。为调试构建关闭这个程序解决了这个问题。

#6


7  

Xcode调试器不打印对象,显示为nil,而它们不是。

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

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

#7


6  

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

我刚刚遇到这个问题,发现是因为在构建设置中部署Postprocessing = YES。

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

把这个改成不固定,如下面的截图所示:

Xcode调试器不打印对象,显示为nil,而它们不是。

Xcode version: 6.0.1 (6A317) on OSX 10.9.5

Xcode版本:osx10.9.5上的6.0.1 (6A317)。

#8


5  

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

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

#9


4  

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调试器将一些对象类型(尤其是nsstring)打印出来,尽管它们是用一个值初始化的。输出通过

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之后,一切都正常了:)。

#10


3  

  1. Delete Derived Data
  2. 删除派生数据
  3. Quite Xcode / Restart
  4. 相当Xcode /重启
  5. Clean Project
  6. 清洁项目

That's all it took for me.

这就是我想要的。

#11


2  

The solutions here will also fix the bug where you see error: <EXPR>:1:1: error: use of unresolved identifier every time you try to po a variable.

这里的解决方案还将修复您所看到的错误: :1:1:错误:每次尝试po一个变量时使用未解析的标识符。

For me the solution was to go to Build Settings and search for Optimization Level and make sure each Debug setting was set to None.

对我来说,解决方案是去构建设置和搜索优化级别,并确保每个调试设置都没有设置。

#12


1  

Go to "Other C Flags" in build setting and set debug value from -o2 to -O0

在构建设置中使用“其他C标志”,并从-o2到-O0设置调试值。

#13


0  

I have run into this as well and when I found I was in release mode I switch to debug ... no fix. Turns out that I had to do a clean first (cmd+shift+k).

我也遇到过这样的情况,当我发现我处于释放模式时,我切换到调试…没有解决。结果是我必须先做一个干净的(cmd+shift+k)。

So I think what happens is that after built in release mode not everything is recompiled in develop and so lldb can't properly read the symbols. After cleaning and recompiling in develop it worked for me.

所以我认为,在发布模式之后,并不是所有的东西都被重新编译,所以lldb不能正确地读取这些符号。在清洗和重新编译后,它为我工作。

#14


-2  

The reality is that the system should work out of the box and doesn't due to links to a multiple quantity of different settings, to a point that things may work for you, or not.

实际情况是,系统应该从这个框中工作,而不是由于链接到多个不同的设置,以至于事情可能会为你工作,或者不是。

Why doesn't the system allows always to debug when in debug mode is a mystery that only Apple can answer (if they cared, which latelly i doubt they do).

为什么系统不允许在调试模式下总是调试,这是只有苹果才能回答的一个谜(如果他们关心的话,我怀疑他们会这么做)。

After all, the difference between debug / non-debug would be extra tables with metadata which only fill in memory / disk space.

毕竟,调试/非调试之间的差异将是额外的表,元数据只填充内存/磁盘空间。

If you are compiling against the simulator or a device directly, you will not care of those extra megabytes.

如果您是直接针对模拟器或设备进行编译,那么您将不关心这些额外的兆字节。

So we need to run extra loops to just do a very basic and plain thing that all ides that i know since last century do just fine.

所以我们需要运行额外的循环来做一个非常基础和简单的事情,我知道从上个世纪以来我所知道的一切都很好。

And to add, for me what worked was changing on "Debug" the Link-Time Optimization from "Monolithic" to "No" (xcode 8).

此外,对于我来说,在“调试”中,从“单片”到“不”(xcode 8)的链接时间优化工作正在发生变化。

#1


246  

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).

如果你想看到变量值,你必须在“调试模式”(点击你的项目名称在左上角靠近start/stop按钮,然后“编辑scheme…”然后,“运行”设置,然后是“Info”选项卡,然后是“构建配置”。在这里设置“调试”。如果是在“释放”,那就是你看到的所有的nils。

#2


32  

I've set "optimisation level" for Debug configuration to "None" and it solved problem.

我已经将调试配置的“optimisation level”设置为“None”,并解决了问题。

#3


24  

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

确保在您的方案设置中关闭了地址消毒剂。地址清除器与调试器不能很好地工作。

  1. Go to Edit Scheme (Product >> Scheme >> Edit Scheme), choose Run, and go to the Diagnostics tab.
  2. 编辑方案(产品>>方案>>编辑方案),选择运行,并进入诊断选项卡。
  3. Make sure "Enable Address Sanitizer" is off.
  4. 确保“启用地址消毒剂”关闭。

Xcode调试器不打印对象,显示为nil,而它们不是。

#4


13  

It seems everyone has their own solution.

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

For me, I use Objective-C and Swift at the same time.

对我来说,我同时使用Objective-C和Swift。

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

首先,转到目标->构建设置并搜索代码生成。

You’ll find Apple LLVM 6.0 and Swift Compiler

你会发现苹果LLVM 6.0和Swift编译器。

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

将它们的优化级别更改为None,然后调试,您可能会发现值不是nil。

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

令人惊讶的是,一旦您看到了这个值,您就可以永久地解决这个问题,然后您就可以将优化级别更改为原来的值。

#5


11  

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”,甚至用于调试构建。为调试构建关闭这个程序解决了这个问题。

#6


7  

Xcode调试器不打印对象,显示为nil,而它们不是。

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

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

#7


6  

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

我刚刚遇到这个问题,发现是因为在构建设置中部署Postprocessing = YES。

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

把这个改成不固定,如下面的截图所示:

Xcode调试器不打印对象,显示为nil,而它们不是。

Xcode version: 6.0.1 (6A317) on OSX 10.9.5

Xcode版本:osx10.9.5上的6.0.1 (6A317)。

#8


5  

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

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

#9


4  

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调试器将一些对象类型(尤其是nsstring)打印出来,尽管它们是用一个值初始化的。输出通过

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之后,一切都正常了:)。

#10


3  

  1. Delete Derived Data
  2. 删除派生数据
  3. Quite Xcode / Restart
  4. 相当Xcode /重启
  5. Clean Project
  6. 清洁项目

That's all it took for me.

这就是我想要的。

#11


2  

The solutions here will also fix the bug where you see error: <EXPR>:1:1: error: use of unresolved identifier every time you try to po a variable.

这里的解决方案还将修复您所看到的错误: :1:1:错误:每次尝试po一个变量时使用未解析的标识符。

For me the solution was to go to Build Settings and search for Optimization Level and make sure each Debug setting was set to None.

对我来说,解决方案是去构建设置和搜索优化级别,并确保每个调试设置都没有设置。

#12


1  

Go to "Other C Flags" in build setting and set debug value from -o2 to -O0

在构建设置中使用“其他C标志”,并从-o2到-O0设置调试值。

#13


0  

I have run into this as well and when I found I was in release mode I switch to debug ... no fix. Turns out that I had to do a clean first (cmd+shift+k).

我也遇到过这样的情况,当我发现我处于释放模式时,我切换到调试…没有解决。结果是我必须先做一个干净的(cmd+shift+k)。

So I think what happens is that after built in release mode not everything is recompiled in develop and so lldb can't properly read the symbols. After cleaning and recompiling in develop it worked for me.

所以我认为,在发布模式之后,并不是所有的东西都被重新编译,所以lldb不能正确地读取这些符号。在清洗和重新编译后,它为我工作。

#14


-2  

The reality is that the system should work out of the box and doesn't due to links to a multiple quantity of different settings, to a point that things may work for you, or not.

实际情况是,系统应该从这个框中工作,而不是由于链接到多个不同的设置,以至于事情可能会为你工作,或者不是。

Why doesn't the system allows always to debug when in debug mode is a mystery that only Apple can answer (if they cared, which latelly i doubt they do).

为什么系统不允许在调试模式下总是调试,这是只有苹果才能回答的一个谜(如果他们关心的话,我怀疑他们会这么做)。

After all, the difference between debug / non-debug would be extra tables with metadata which only fill in memory / disk space.

毕竟,调试/非调试之间的差异将是额外的表,元数据只填充内存/磁盘空间。

If you are compiling against the simulator or a device directly, you will not care of those extra megabytes.

如果您是直接针对模拟器或设备进行编译,那么您将不关心这些额外的兆字节。

So we need to run extra loops to just do a very basic and plain thing that all ides that i know since last century do just fine.

所以我们需要运行额外的循环来做一个非常基础和简单的事情,我知道从上个世纪以来我所知道的一切都很好。

And to add, for me what worked was changing on "Debug" the Link-Time Optimization from "Monolithic" to "No" (xcode 8).

此外,对于我来说,在“调试”中,从“单片”到“不”(xcode 8)的链接时间优化工作正在发生变化。