iOS Viewing values in the debugger

1458279

Suspended
Original poster
May 1, 2010
1,601
1,514
California
Xcode 4.01
LLVM GCC 4.2

Code:
//user selected start new video record
-(void)btnVideoStart:(id)sender
{

    if (self.captureSession.running)
I want to find the value of 'running' If I hoover over it with the mouse, it doesn't show the value (might be the wrong version for that)

I would like to add 'self.captureSession.running' as a watch variable or to get the value to show in the debugger.

Right now, I'm using NSLog, but I'd like to see it in the var list.

I understand the compiler to use is the LLVM, so what am I doing wrong.
 

chown33

Moderator
Staff member
Aug 9, 2009
8,554
4,617
inter-prandial
As given, 'running' is a property, not a variable. If it's backed by an ivar, please show the @interface for it. If you've synthesized the ivar (don't know if that's supported in your Xcode version), I'm not sure the debugger even knows what the ivar is.

What OS version are you using? And why so old an Xcode?
 

1458279

Suspended
Original poster
May 1, 2010
1,601
1,514
California
As given, 'running' is a property, not a variable. If it's backed by an ivar, please show the @interface for it. If you've synthesized the ivar (don't know if that's supported in your Xcode version), I'm not sure the debugger even knows what the ivar is.

What OS version are you using? And why so old an Xcode?
Ooops...:D

I meant to say that I want to see the value of the property. You're right, it's not a variable.

I run 10.6.6, it's a dualboot hackintosh and I don't want to upgrade until I've clone the hard drive. Just haven't gotten around to it yet, it's pretty stable as it is.

Ok, so how do I get the debugger to show the value of the property. I thought hovering over it did the trick.

In some debuggers, you have an 'immediate' window:
? self.captureSession.running ... would display the contents of running. All the books and online tutorials I've read, don't mention any immediate or watch window in Xcode, where you pick what you want to watch.
 

1458279

Suspended
Original poster
May 1, 2010
1,601
1,514
California
I just checked, the debugger shows the values of variables when I hoover over them, but it looks like it does not do this for properties.
 

chown33

Moderator
Staff member
Aug 9, 2009
8,554
4,617
inter-prandial
I just checked, the debugger shows the values of variables when I hoover over them, but it looks like it does not do this for properties.
A property is just accessor methods. Since the debugger must message an object to run a method, the debugger won't show properties like it shows variables. If you don't recognize the difference between a method and a variable, you should review the fundamentals.
 

1458279

Suspended
Original poster
May 1, 2010
1,601
1,514
California
A property is just accessor methods. Since the debugger must message an object to run a method, the debugger won't show properties like it shows variables. If you don't recognize the difference between a method and a variable, you should review the fundamentals.
I understand the difference, but didn't know the debugger had to message the object to get the value of a status like 'running'. I figured running would be a state (true/false). I'll have to dig into the debugger more, but finding comprehensive documentation on it is like finding a four leaf clover.

I still have no clue how to add a watch variable or eval an expression.

Thanks again for the heads up.
 

SteppingStone

macrumors member
Aug 6, 2012
70
0
The workaround is to explicitly create instance variables to back your properties.

E.g. in your header:

Code:
@interface MyClass : NSObject {

  float _myVar;

}

@property (nonatomic, assign) float myVar;
and in your .m file

Code:
@synthesize myVar = _myVar;
Then you can look at the instance variable in the debugger. You'd think that Xcode could be made smart enough to figure this sort of thing out in the common cases, but it just isn't.
 

forum user

macrumors regular
Aug 28, 2008
202
0
I would like to add 'self.captureSession.running' as a watch variable or to get the value to show in the debugger.
set at breakpoint in that line, when execute has stopped go to the debugger console and type:
Code:
 po [[self captureSession] running]
I haven't found a way yet to use dot notation in the console.
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
set at breakpoint in that line, when execute has stopped go to the debugger console and type:
Code:
 po [[self captureSession] running]
I haven't found a way yet to use dot notation in the console.
That drives me nuts. Dot notation is so much more compact and easier to type. In the debugger console I have to convert everything to method call notation.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Assuming this property is a BOOL then you use p (print), not po (print object).

p (BOOL) [[self captureSession] running]

If running is shown in the variables pane you can print it by right-clicking on the line for that variable and choose the Print Description (or whatever it's called) from the right click menu.
 

1458279

Suspended
Original poster
May 1, 2010
1,601
1,514
California
Where do you get a list of what can be done in the debugger console? I had no idea you could type in commands in there?

Is there a command list somewhere?
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
8,579
4,019
Where do you get a list of what can be done in the debugger console? I had no idea you could type in commands in there?

Is there a command list somewhere?
I believe they're suggesting you use Terminal, the Mac OS X app.

Edit: Actually, they might be suggesting you just type into the pane it prints NSLog statements to... I've never tried that before other than running C programs in Xcode.
 

1458279

Suspended
Original poster
May 1, 2010
1,601
1,514
California
I believe they're suggesting you use Terminal, the Mac OS X app.

Edit: Actually, they might be suggesting you just type into the pane it prints NSLog statements to... I've never tried that before other than running C programs in Xcode.
I just tried the lower right box where 'NSLog' displays output.

If you type 'help' it'll give you a list of classes of commands.

IE: help data:
Code:
(gdb) help data
Examining data.

List of commands:

append -- Append target code/data to a local file
call -- Call a function in the program
delete display -- Cancel some expressions to be displayed when program stops
delete mem -- Delete memory region
disable display -- Disable some expressions to be displayed when program stops
disable mem -- Disable memory region
disassemble -- Disassemble a specified section of memory
display -- Print value of expression EXP each time the program stops
dump -- Dump target code/data to a local file
enable display -- Enable some expressions to be displayed when program stops
enable mem -- Enable memory region
inspect -- Same as "print" command
invoke-block -- Invoke the function associated with the block passed in as the first
mem -- Define attributes for memory region
output -- Like "print" but don't put in value history and don't print newline
print -- Print value of expression EXP
print-object -- Ask an Objective-C object to print itself
printf -- Printf "printf format string"
ptype -- Print definition of type TYPE
restore -- Restore the contents of FILE to target memory
set -- Evaluate expression EXP and assign result to variable VAR
set variable -- Evaluate expression EXP and assign result to variable VAR
undisplay -- Cancel some expressions to be displayed when program stops
whatis -- Print data type of expression EXP
x -- Examine memory: x/FMT ADDRESS

Type "help" followed by command name for full documentation.
Command name abbreviations are allowed if unambiguous.
(gdb)
also within help data:
help ptype:
Code:
(gdb) help ptype
Print definition of type TYPE.
Argument may be a type name defined by typedef, or "struct STRUCT-TAG"
or "class CLASS-NAME" or "union UNION-TAG" or "enum ENUM-TAG".
The selected stack frame's lexical context is used to look up the name.
(gdb)
looks pretty handy once you understand what it does. I wonder what other functionality it has.

Edit: we should work in a 'understanding the debugger' how to, and post it as a sticky at the top of the forum.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Start with p and po. I rarely use anything else than that. gdb can be used in a completely command line mode but if you're using Xcode you won't need most of its functionality. lldb in Xcode 4.4 seems to be working well enough for regular use and it partly supports dot notation for properties and displays ivars that are only declared by @synthesize so it's much more useful than gdb.
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia

1458279

Suspended
Original poster
May 1, 2010
1,601
1,514
California
I saw the part in the tutorial where he talks about getting rid of the .asm code, but it doesn't work through the whole program:
(Source)
http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1

For fun, click on any one of the other items from the stacktrace and you’ll see a bunch of assembly code which might not make much sense to you:
...
Fortunately, you can tell Xcode to pause the program at just that moment, using an Exception Breakpoint. A breakpoint is a debugging tool that pauses your program at a specific moment. You’ll see more of them in the second part of this tutorial, but for now you’ll use a specific breakpoint that will pause the program just before an exception gets thrown.
To set the Exception Breakpoint, we have to switch to the Breakpoint Navigator:
...
That’s better! The source code editor now points to a line from the source code – no more nasty assembly stuff – and notice that the call stack on the left (you might need to switch to the call stack via the Debug Navigator depending on how you have Xcode set up) also looks different.
The problem is that the debugger still steps thru the .asm code

BTW, where do you select the debugger (GDB vs LLDB)? I thought it was under 'Build Settings' I'm using Xcode 4.01