55

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?

3
  • 1
    Hi William, did you ever find the solution. I have the same problem. Very annoying. So I need to do NSLog all the time; the xcode debugger is really crippled to work this way. Commented Feb 9, 2011 at 22:58
  • 3
    At the bottom of the variable view is a little menu with entries: Auto, Local Variables, and All. Commented Nov 7, 2014 at 20:40
  • @WayneLo Take a look at my answer below, it works on the latest Xcode - Version 7.3 (7D175) Commented Aug 5, 2016 at 14:19

19 Answers 19

43

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.

Sign up to request clarification or add additional context in comments.

10 Comments

Thanks for the reply, but I'm pretty sure none of those apply in my case.
I had temporarily switched the Run scheme to Release instead of Debug and forgot. Switching it back fixed. Thanks.
This is not the issue in my case.
@IanWarburton: a "hosed" or "trashed" stack just means that a bug in your code has overwritten some part of the stack and corrupted local variables and/or return addresses, making it impossible for a debugger to display meaningful information for local variables and the calling chain (backtrace).
I've accidentally set the scheme to Release once, forgot to change it back to Debug. That was the problem for me.
|
19

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:

Xcode Debugging not showing values

Xcode debugger doesn't display variable information after installing CocoaPods Podfile

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

2 Comments

I've found the same issue, while switching to Carthage version of a 3rd Party framework. I just forgot to remove the .h from the bridging-header file and I had no warning about it.
Thanks or this comment! Mine was bridging header related too; I determined the exact fix by using "(lldb) po variableICannotSee" and then seeing why the error was occurring - warning: Swift error in module My-Bridging-Header.h, error: 'thisFileNotFound.h' file not found error: failed to import bridging header 'My-Bridging-Header.h' Debug info from this module will be unavailable in the debugger.
9

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

Comments

6

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

2 Comments

For me, variables where showing normally when execution stopped at a breakpoint, except for exception breakpoints. This was a huge pain in the ass. Luckily switching to GDB fixed it for me. Why can't apple get their Xcode act together?
Unfortunately switching's no longer possible, see: stackoverflow.com/q/28927815/8740349
5

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

1 Comment

+1 for solving my problem as well.The new address sanitiser in XCode is preventing me from debugging some variables as well. It is a great feature to have on and catches some very real problems, but this isn't a great trade off. Is this a known issue?
3

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

po name_of_an_objectCVar

or

print name_of_a_cVar

2 Comments

This does not answer the OP's question.
For some reason, only print works for me, thanks.
2

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

Comments

1

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

Comments

1

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

Comments

1

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 Understanding eliding rules with regard to c++11

4 Comments

This solved it for me thanks! This should be a default for debug builds, or can other debuggers handle it (e.g. gdb)?
We did try turning the compiler switch off but it caused problems in our projects because some files weren't compiled with it -- I guess it's all-or-nothing.
So it doesn't work well if you have if only for some files?
Yes, we had random crashes -- if RVO is enabled then the caller and callee have to have the same setting otherwise you'll probably get stack corruption.
1

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

Comments

0

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.

Comments

0

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.

Comments

0

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.

Comments

0

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.

Comments

0

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.

Comments

0

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.

Comments

0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.