Binarian
Binarian

Reputation: 12446

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

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

Upvotes: 177

Views: 65941

Answers (15)

Leszek Zarna
Leszek Zarna

Reputation: 3317

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

Upvotes: 41

yoAlex5
yoAlex5

Reputation: 34401

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

Upvotes: 1

TMin
TMin

Reputation: 2349

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

That's all it took for me.

Upvotes: 3

Spencer Hall
Spencer Hall

Reputation: 3739

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.

Upvotes: 1

Curmudgeonlybumbly
Curmudgeonlybumbly

Reputation: 639

Filtered debug output

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

Upvotes: 9

kindaian
kindaian

Reputation: 147

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

Upvotes: -4

llama591
llama591

Reputation: 473

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

Upvotes: 5

Muhammad Shauket
Muhammad Shauket

Reputation: 2778

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

Upvotes: 1

Igor Kovryzhkin
Igor Kovryzhkin

Reputation: 2215

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

Upvotes: 32

Kevin Xu
Kevin Xu

Reputation: 126

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.

Upvotes: 2

Lei
Lei

Reputation: 171

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.

Upvotes: 15

Torsten Barthel
Torsten Barthel

Reputation: 3476

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

Upvotes: 5

Luke
Luke

Reputation: 11476

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

Upvotes: 7

ThomasW
ThomasW

Reputation: 17317

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.

Upvotes: 11

Mick
Mick

Reputation: 3335

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

Upvotes: 286

Related Questions