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

IosObjective CXcodeDebugging

Ios Problem Overview


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

Screenshot

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

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.

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

Ios Solutions


Solution 1 - Ios

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

Solution 2 - Ios

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

  • Go to project Build settings
  • Search Debug
  • Under Apple Clang - Code Generation check Optimization Level
  • Set Debug to None [-OO]

After that, you will be able to see variable values in the debug area or console. enter image description here

Solution 3 - Ios

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. Make sure "Enable Address Sanitizer" is off.

enter image description here

Solution 4 - Ios

It seems everyone has their own solution.

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

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

You’ll find Apple LLVM 6.0 and Swift Compiler

Change their Optimization Level all to None, then Debug, you may find the value not 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.

Solution 5 - Ios

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.

Solution 6 - Ios

Filtered debug output

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

Solution 7 - Ios

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

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

enter image description here

Xcode version: 6.0.1 (6A317) on OSX 10.9.5

Solution 8 - Ios

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

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

Solution 9 - Ios

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

Solution 10 - Ios

  1. Delete Derived Data
  2. Quite Xcode / Restart
  3. Clean Project

That's all it took for me.

Solution 11 - Ios

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.

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.

Solution 12 - Ios

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

Solution 13 - Ios

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

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.

Solution 14 - Ios

I ran on this problem when some dependency was added in a very specific way - it works but when you try to print something from this framework you get error

Solution was to add this dependency in a general way

Solution 15 - Ios

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBinarianView Question on Stackoverflow
Solution 1 - IosMickView Answer on Stackoverflow
Solution 2 - IosLeszek ZarnaView Answer on Stackoverflow
Solution 3 - IosKIOView Answer on Stackoverflow
Solution 4 - IosLeiHaoView Answer on Stackoverflow
Solution 5 - IosThomasWView Answer on Stackoverflow
Solution 6 - IosCurmudgeonlybumblyView Answer on Stackoverflow
Solution 7 - IosLukeView Answer on Stackoverflow
Solution 8 - IosTorsten BarthelView Answer on Stackoverflow
Solution 9 - Iosllama591View Answer on Stackoverflow
Solution 10 - IosTMinView Answer on Stackoverflow
Solution 11 - IosKevin XuView Answer on Stackoverflow
Solution 12 - IosMuhammad ShauketView Answer on Stackoverflow
Solution 13 - IosSpencer HallView Answer on Stackoverflow
Solution 14 - IosyoAlex5View Answer on Stackoverflow
Solution 15 - IoskindaianView Answer on Stackoverflow