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?

William Jockusch
  • 26,513
  • 49
  • 182
  • 323
  • 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. – Wayne Lo Feb 09 '11 at 22:58
  • 3
    At the bottom of the variable view is a little menu with entries: Auto, Local Variables, and All. – Jason Harrison Nov 07 '14 at 20:40
  • @WayneLo Take a look at my answer below, it works on the latest Xcode - Version 7.3 (7D175) – Nagendra Rao Aug 05 '16 at 14:19

19 Answers19

42

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.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • 4
    Thanks for the reply, but I'm pretty sure none of those apply in my case. – William Jockusch Jul 16 '10 at 21:11
  • 4
    I had temporarily switched the Run scheme to Release instead of Debug and forgot. Switching it back fixed. Thanks. – leontx Jul 13 '12 at 19:53
  • 1
    This is not the issue in my case. – Matthew James Briggs Mar 04 '15 at 07:35
  • What is hosing the stack? – Ian Warburton Jul 07 '16 at 12:24
  • 1
    @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). – Paul R Jul 07 '16 at 12:26
  • @PaulR Is that possible with Swift? – Ian Warburton Jul 07 '16 at 13:08
  • @IanWarburton: no idea I'm afraid, as I've never used Swift, but I would guess stack corruption is possible in pretty much any language. – Paul R Jul 07 '16 at 13:13
  • If a language handles memory management, then how could one's code overwrite the stack? – Ian Warburton Jul 07 '16 at 13:18
  • @IanWarburton: it's more difficult with "managed" languages, but given that any language will most likely call native code at some point (user libraries, system libraries, etc), then it may still be possible to corrupt the stack. Unbounded recursion is another possibility. But anyway, this is way off-topic for the current question, and chat in comments is discouraged on SO. If you want to ask a new question about this on SO then please go ahead and post it. – Paul R Jul 07 '16 at 13:37
  • 1
    I've accidentally set the scheme to Release once, forgot to change it back to Debug. That was the problem for me. – badhanganesh Sep 15 '17 at 13:45
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!

Community
  • 1
  • 1
Anil
  • 21,730
  • 9
  • 73
  • 100
  • 1
    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. – Juan Pedro Lozano Aug 01 '16 at 17:02
  • 1
    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. – Christian Chown Jun 06 '19 at 14:58
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

Community
  • 1
  • 1
augustos10
  • 133
  • 1
  • 6
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

IMFletcher
  • 656
  • 9
  • 19
  • 5
    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? – Ricardo Sanchez-Saez Oct 22 '12 at 10:03
  • Unfortunately switching's no longer possible, see: https://stackoverflow.com/q/28927815/8740349 – Top-Master Nov 25 '21 at 18:45
5

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

danielweberdlc
  • 452
  • 1
  • 8
  • 16
  • +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? – micnguyen Apr 10 '18 at 03:30
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
David Levesque
  • 22,181
  • 8
  • 67
  • 82
Sandro Vezzali
  • 147
  • 2
  • 4
2

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

devjme
  • 684
  • 6
  • 12
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

avuthless
  • 996
  • 2
  • 12
  • 27
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.

Marcos Reboucas
  • 3,409
  • 1
  • 29
  • 35
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

Community
  • 1
  • 1
the_mandrill
  • 29,792
  • 6
  • 64
  • 93
  • This solved it for me thanks! This should be a default for debug builds, or can other debuggers handle it (e.g. gdb)? – focs Aug 27 '15 at 15:56
  • 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. – the_mandrill Aug 27 '15 at 21:14
  • So it doesn't work well if you have if only for some files? – focs Aug 28 '15 at 12:11
  • 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. – the_mandrill Aug 30 '15 at 20:51
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

d0ye
  • 1,580
  • 1
  • 15
  • 26
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.

user1105951
  • 2,259
  • 2
  • 34
  • 55
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.

GTAE86
  • 1,780
  • 3
  • 29
  • 39
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.

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169
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.

Sharud
  • 415
  • 3
  • 9
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.

Benpaper
  • 144
  • 4
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.

Stephen Watson
  • 1,700
  • 16
  • 17
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.

Manuel
  • 14,274
  • 6
  • 57
  • 130
0

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

Eugene Alexeev
  • 1,152
  • 12
  • 32