Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Why can't the debugger 'see' my variables??

I have created a simple Foundation Tool app that utilizes simple C-type functions. I have not set up this program with the normal @interface/@implementation sections.

What I am curious about is that the debugger does not see the variables within the functions I have created. I have had to insert NSLog(); statements within these functions to see the values of my variables during execution.

To be clear, this program compiles with no warnings. If anyone has any comments or suggestions in this regard I would like to know them.

Thanks,
Phillip Anthony

24" iMac, 17" PowerBook, Mac OS X (10.6.2)

Posted on May 4, 2010 6:43 AM

Reply
Question marked as Best reply

Posted on May 4, 2010 11:52 AM

Some things to check.

1. Make sure you set a breakpoint in your program. The variable viewer in the debugger doesn't show anything unless you pause your program's execution.

2. Make sure you're using the Debug build configuration. Use the Overview pulldown menu on the project window toolbar to set the active build configuration.

3. Make sure the Generate Debug Symbols build setting is activated. Choose Project > Edit Active Target to open the target inspector. Click the Build tab in the inspector. The Generate Debug Symbols build setting is in the Code Generation collection.

4. Are other variables like function arguments showing up in the variable viewer or is it only local variables that don't appear?
10 replies
Question marked as Best reply

May 4, 2010 11:52 AM in response to Phillip Anthony

Some things to check.

1. Make sure you set a breakpoint in your program. The variable viewer in the debugger doesn't show anything unless you pause your program's execution.

2. Make sure you're using the Debug build configuration. Use the Overview pulldown menu on the project window toolbar to set the active build configuration.

3. Make sure the Generate Debug Symbols build setting is activated. Choose Project > Edit Active Target to open the target inspector. Click the Build tab in the inspector. The Generate Debug Symbols build setting is in the Code Generation collection.

4. Are other variables like function arguments showing up in the variable viewer or is it only local variables that don't appear?

May 7, 2010 7:57 AM in response to Mark Szymczyk

Mark,
Please accept my apologies for my late reply, but life has kept me away from the computer for a few days. I sincerely appreciate your very helpful comments.


1. Make sure you set a breakpoint in your program. The variable viewer in the debugger doesn't show anything unless you pause your program's execution.


Break point had been set in the method as described below

2. Make sure you're using the Debug build configuration. Use the Overview pulldown menu on the project window toolbar to set the active build configuration.


I checked and it was set as you described.

3. Make sure the Generate Debug Symbols build setting is activated. Choose Project > Edit Active Target to open the target inspector. Click the Build tab in the inspector. The Generate Debug Symbols build setting is in the Code Generation collection.


I checked and it was set as you described.

4. Are other variables like function arguments showing up in the variable viewer or is it only local variables that don't appear?


It is only local variables that are not showing up.

When I step through the code with the debugger I think that I should be able to see the local variable 'right_digit' which is in the method get num_ofdigits, but it is never visible under the Variable > self folder of the debugger when I Step Over each line of code in that method.

This is the applicable code:

@interface Calculator : NSObject {

int accumulator, avg, right_digit, num, new_num;
int i, total, new_value;
}
...
-(int) get num_ofdigits : (int) number : (int) value_2;
...
@end // end of interface section

@implementation
...
-(int) get num_ofdigits : (int) number : (int) value_1 { // << break point set here

while ( number != 0 ) {
right_digit = number % 10;

++value_1;

number /= 10;
}
return value_1;
}

@end // end of implementation section

In main () we have the following:

int value_1, number, result, n, new_num;

value_1 = 0;

printf("Enter your number =>>>> " );
scanf ("%i", &number);

// number entered = 123

result = [ myCalculator get num_ofdigits : number : value_1 ];

In a nutshell - once I get to the method break point all that the debugger sees under the self folder is:

_cmd some hex #
number 123 = value entered in main()
value_1 0 ( = initial value )

the other Variables - Globals, Registers, Vector Registers and x87 Registers do not contain the variable of interest.

Thanks again for your help,
Phillip Anthony

May 7, 2010 8:04 AM in response to Mark Szymczyk

I should have mentioned that the code compiles without any errors at all.

What bothers me is that when debugging my code I must to insert print stmts (printf() or NSLog()) to determine what values my local variables are actually generating. I believe that the debugger should do this for me, but I must have something set incorrectly which is causing the debugger to overlook these variables.

Thanks.

May 7, 2010 11:18 AM in response to Phillip Anthony

There are no local variables in your get num_ofdigits() function. Local variables are variables that are declared inside a function. You haven't declared any variables in get num_ofdigits().

I'm guessing that you want to see the variables in your Calculator class (avg, right_digit, etc.) in the variable viewer. When you reach the breakpoint, the variable viewer shows the arguments to the get num_ofdigits() function. One of those arguments should be self. Self is your Calculator object. The self argument should have a disclosure triangle next to it. Clicking the disclosure should display all the data members of the Calculator class.

May 7, 2010 12:51 PM in response to Mark Szymczyk

Mark,

Thanks for your comments.

It was my understanding that a 'local' variable was simply one that you declared within the @interface section. WRONG! After reading your comments and doing a bit of research, I now understand that a 'local' variable is one that has to be declared WITHIN the method that references it. Exactly as you said. THANK YOU! Lesson learned. You are absolutely correct: I have no local variables within get num_ofdigits.

Time permitting, I have one more question for you: Can you recommend good documentation for the debugger used in Xcode 3.2.2? That would help me greatly.

I sincerely appreciate your help.

Phillip Anthony

May 7, 2010 1:22 PM in response to laurent demaret

laurent,

Thanks for the great info. Good thing I have a 24" monitor. Grin. That was a very long link.

I couldn't quite get the link to work for me, but you might try this next time. I keep it in my Bookmarks Bar.

http://tinyurl.com/2e7ejz6

I've used this quite a bit and it really helps shorten long links.

Back on topic: my Xcode does not work quite right. For instance, I have to always do a 'Clean All' else I any new changes to my code will not show up in the next build. And I have pulled down the Xcode help and have gotten some strange results. This time though, the correct Help did come up and I found the Xcode Debugging Guide.

Anyway, thanks again for your help.

Phillip Anthony

Why can't the debugger 'see' my variables??

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.