6

I'm seeing a strange behavior with Xcode 6 debugger. I have created a singleton shared instance using the following code:

+ (instancetype)shared 
{
    static DataBaseManager *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
    sharedInstance = [[DataBaseManager alloc] init];
    });

   return sharedInstance;
}

Right after the object is initialized by calling the method like this:

DataBaseManager *manager = [DataBaseManager shared];
NSLog(@"");

I have placed a breakpoint on the "NSLog", and i'm seeing the following debugger status:

Xcode 6 debugger screen capture

I have made sure I'm launching on debug mode, and that the build settings are fine, following the question here: Xcode debugger doesn't print objects and shows nil, when they aren't

Any ideas on why this is happening? This is the first time i have ever seen this kind of strange behavior. Any help would be much appreciated.

**UPDATE**

A bug was reported to apple bug report system.
The bug status is: Duplicate of 17164538 (Closed) 

so it is probably a known bug in Xcode.
Community
  • 1
  • 1
Raz
  • 2,633
  • 1
  • 24
  • 44
  • 2
    My experience with the Xcode debugger visualization is that it's pretty fragile. The thing you can rely on is the LLDB shell on the right. For example, `po manager`, `po manager->_databasePath`, … If you experience consistent issues you might want to file a bug report with Apple, though. – DarkDust Oct 29 '14 at 14:21
  • @DarkDust 'po manager' does prints the memory address of 'manager'. everything is working, but this issue is frustrating. thanks. – Raz Oct 29 '14 at 14:34
  • The Xcode variable display stuff is often worthless. Any time you suspect it use `p` and `po`. You'll save a lot of time. (Also, of course, `NSLog(@"");` isn't going to show you anything. And if that was supposed to be the *only* reference to `manager` then it's likely been tossed by the optimizer.) – Hot Licks Nov 03 '14 at 12:30

3 Answers3

4

You shouldn't be in Release mode while you are debugging your code.

If you want to see variable values you have to be in Debug mode. The steps are

  1. Click on your project name on the top left corner near start/stop buttons
  2. Go in Edit scheme
  3. Go in Run settings
  4. Go in Info tab and then Build Configuration
  5. Set it to Debug

If it was on "Release" that's the matter you saw all nil. If still not working then try following in the project Build Settings

  1. Set Strip debug symbols during copy to NO
  2. Optimization Level to None -O0
Ans
  • 3,461
  • 3
  • 23
  • 24
2

Try setting Deployment Postprocessing to NO inside your Build Settings and check.

Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
  • made sure it's set to NO. just like stated in the question reference link: http://stackoverflow.com/questions/19870176/xcode-5-debugger-doesnt-print-objects-and-shows-nil-when-they-arent – Raz Oct 29 '14 at 14:32
  • Sometimes this is not sufficient to avoid the "error: Couldn't materialize: couldn't get the value of variable VARIABLENAME: variable not available Errored out in Execute, couldn't PrepareToExecuteJITExpression" – Jason Harrison Nov 07 '14 at 20:38
2

Make sure you have Link-Time Optimization set to No for debug mode in Build Settings.

llama591
  • 453
  • 5
  • 15