Xcode debugger sometimes doesn't display variable values?

XcodeDebugging

Xcode Problem Overview


This happens to me pretty often. For example, right now I have the debugger stopped at a breakpoint in a method . . . and it isn't displaying any variable values at all. Other times, it displays some, but not others.

Can anyone explain?

Xcode Solutions


Solution 1 - Xcode

The most common reason for this is that you're trying to debug code compiled with optimisation enabled and/or no debug symbols. Typically this will be because you're trying to debug a Release build rather than a Debug build but it can also happen with Debug builds if you've made inappropriate changes to the Debug build settings.

Another less common possibility is that you've hosed the stack.

Solution 2 - Xcode

I had this issue (using Swift), I spent ages crawling through my git commits to find where to problem started.

xcode debugging variables not working or showing


For me, I was using Facebook Tweaks library, but I was (unnecessarily) importing it from my project-bridging-header.h file.

Once I got rid of it, I got my debugging back.

for example, in my bridging header I had:

#ifndef PROJECT_Bridging_Header_h
#define PROJECT_Bridging_Header_h
// Facebook Tweaks
#import "FBTweak.h"
#import "FBTweakStore.h"
#import "FBTweakCategory.h"
#import "FBTweakCollection.h"
#import "FBTweakViewController.h"
#import "FBTweakShakeWindow.h"
#endif

I removed all the imports and just imported it as usual in my AppDelegate import Tweaks.

e.g:

#ifndef PROJECT_Bridging_Header_h
#define PROJECT_Bridging_Header_h
// Removed Facebook Tweaks
#endif

and in my AppDelegate.swift

import Tweaks

This fixed all my debugging issues, everything works as expected and I can also using Facebook Tweaks.

> Note: I don't think this is an issue with Facebook Tweaks itself, you may have some other library causing the same issue. The idea is to remove things from your bridging-header one by one and see if you can narrow down the issue. > > I think I read somewhere that if a library is causing many issues behind the scenes, this can stop your debugger working. > > If this doesn't help, try crawling through your git commits and see at what stage the debugging stopped.

other similar issues on SO:

https://stackoverflow.com/questions/24065050/xcode-debugging-not-showing-values

https://stackoverflow.com/questions/32535044/xcode-debugger-doesnt-display-variable-information-after-installing-cocoapods-p

If you're having similar issues hope this helps! 

Solution 3 - Xcode

A possible solution is to set the Optimization Level for your current target Debug scheme to none.

Project -> Target -> Build settings -> Optimization level -> Debug (or whatever fits your project) -> None

Source:

https://stackoverflow.com/a/14948486/3590753

Solution 4 - Xcode

I've had similar issues using LLDB. Switching it back to GDB seems to address it. Obviously this isn't solving the problem, but its a workaround anyway

Solution 5 - Xcode

My issue was that I had address sanitizer enabled. Disabling sanitizer resolved my issue in XCode 8.2.1

Solution 6 - Xcode

You can get the value of any variable in the console by writing:

po name_of_an_objectCVar

or

print name_of_a_cVar

Solution 7 - Xcode

If your breakpoint has "automatically continue after evaluating options" set, then it won't write to the variable view - FYI

Solution 8 - Xcode

I know this is old, but i ran into same problem too. I could not see any summaries of any objects, just types and some address code. After 4 hours of struggling with compilers, debuggers and other solutions i was about to give up when by accident i found this option in debugger. "Show Summaries". Just by clicking it everything got fixed and now i see all variable summaries!

enter image description here

Solution 9 - Xcode

Had the same issue using Xcode 6.4 running the app on device. Running on simulator will show all variables on debugging variables panel.

Solution 10 - Xcode

There is a situation I have seen where Xcode can't cope with return value optimisation (RVO) -- if the compiler decides to apply RVO to a variable then it may not appear in the variables list. You can disable this in g++ and clang with the compiler flag -fno-elide-constructors

See also https://stackoverflow.com/questions/9267687/understanding-eliding-rules-with-regard-to-c11

Solution 11 - Xcode

For Swift mix OC Project which use pod

Fixing it by removing useless header(that import with framework by pod) xx-Bridging-Header.h

eg. In the past I import header with #import "GCDAsyncSocket.h" which I was added in podfile

platform:ios, '8.0' use_frameworks! target "roocontrollerphone" do pod 'CocoaAsyncSocket' end

just remove it in that xx-Bridging-Header.h file

Solution 12 - Xcode

If you are using the @property feature of Objective-C 2.0 the debugger does not display those variables unless they are backed by explicit ivars in your Class interface. This is slated to be fixed in Xcode 4 as I understand it.

Solution 13 - Xcode

temporary solution when it happpen to me : right click on the property jump to definition (u can do it manually and scroll to the @synthesize in the top of the file)

now, if the line is like this :

@synthesize myObject = _myObject ;

set the mouse cursor on the "_myObjects". that what worked for me..when i have problems.

Solution 14 - Xcode

I figured out why it is not working in XCode 4.6 - all of the variables in my object, self, were declared in the .m file instead of the .h. When I moved one of them back to the .h file, it showed up in the debugger. Sounds like a bug with XCode in that it cannot "see" variables declared in the implementation file.

Solution 15 - Xcode

For me it works changing the content of display variables panel to Local Variables and then back to Auto.

This solution worked on XCode 6.3.2, Swift type project.

Solution 16 - Xcode

You need to disable two types of build optimizations in the build settings. By default, the "swift compiler - code generation" optimization level for debug build is set to fast. You need to set this to none. Also check that the "apple llvm 7.1 - code generation" optimization is set to none for debug build. Finally, check that you are building the debug build in the "architectures" section of your build settings.

Hope this helps.

Solution 17 - Xcode

I have been stuck a while with this problem and finally find out a solution. I think that many reason can causes this bug but in my case here is the solution. While you are in the breakpoint position check the included classes. I was including using double quote a file which was located using include path.

#include "MyClass.h"

instead of

#include <MyPorject/MyClasses/MyClass.h>

So if you have this problem try to double check your inclusion and import. I know it seems weird but worked for me and I have been able to reproduce it by putting back the Double-Quote include.

Solution 18 - Xcode

One possible reason for the debugger displaying seemingly wrong values is that the variable type is of Any?.

E.g.

var a: Any? = 12
var b: Int? = a as? Int // b=13483920750
var c: Int = a as? Int ?? 0 // c=1

In the example above, b holds the correct value of 1 even though it is not displayed as such.

Solution 19 - Xcode

I've had the same issue and I fixed it by reinstalling all Pods. Just delete them and install again.

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
QuestionWilliam JockuschView Question on Stackoverflow
Solution 1 - XcodePaul RView Answer on Stackoverflow
Solution 2 - XcodeAnilView Answer on Stackoverflow
Solution 3 - Xcodeaugustos10View Answer on Stackoverflow
Solution 4 - XcodeIMFletcherView Answer on Stackoverflow
Solution 5 - XcodedanielweberdlcView Answer on Stackoverflow
Solution 6 - XcodeSandro VezzaliView Answer on Stackoverflow
Solution 7 - XcodedevjmeView Answer on Stackoverflow
Solution 8 - XcodeavuthlessView Answer on Stackoverflow
Solution 9 - XcodeMarcos ReboucasView Answer on Stackoverflow
Solution 10 - Xcodethe_mandrillView Answer on Stackoverflow
Solution 11 - Xcoded0yeView Answer on Stackoverflow
Solution 12 - XcodeStephen WatsonView Answer on Stackoverflow
Solution 13 - Xcodeuser1105951View Answer on Stackoverflow
Solution 14 - XcodeGTAE86View Answer on Stackoverflow
Solution 15 - XcodeMiguelSlvView Answer on Stackoverflow
Solution 16 - XcodeSharudView Answer on Stackoverflow
Solution 17 - XcodeBenpaperView Answer on Stackoverflow
Solution 18 - XcodeManuelView Answer on Stackoverflow
Solution 19 - XcodeEugene AlexeevView Answer on Stackoverflow