Reputation: 12446
Xcode shows an error when trying to print an object with po <objectName>
, but only for one project.
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
Reputation: 3317
I've set "Optimization Level" for Debug configuration to "None" and it solved problem.
Build settings
Debug
Apple Clang - Code Generation
check Optimization Level
Debug
to None [-OO]
After that, you will be able to see variable values in the debug area or console.
Upvotes: 41
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
Reputation: 2349
That's all it took for me.
Upvotes: 3
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
Reputation: 639
For me, Xcode was filtering out the debugger output. Make sure your output setting is Debugger Output or All Output
Upvotes: 9
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
Reputation: 473
Make sure Link-Time Optimization = No
for debug mode in Build Settings.
Upvotes: 5
Reputation: 2778
Go to "Other C Flags" in build setting and set debug value from -o2 to -O0
Upvotes: 1
Reputation: 2215
Make sure that Address Sanitizer is turned off in your Scheme settings. The Address Sanitizer does not work well with the debugger.
Upvotes: 32
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
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
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
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:
Xcode version: 6.0.1 (6A317) on OSX 10.9.5
Upvotes: 7
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
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