PDA

View Full Version : Viewing values in the debugger




KarlJay
Aug 7, 2012, 05:36 PM
Xcode 4.01
LLVM GCC 4.2

//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
Aug 7, 2012, 05:42 PM
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?

KarlJay
Aug 7, 2012, 07:32 PM
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.

KarlJay
Aug 7, 2012, 07:57 PM
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
Aug 7, 2012, 09:32 PM
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 (http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html%23//apple_ref/doc/uid/TP30001163-CH17-SW1). 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.

KarlJay
Aug 8, 2012, 01:43 AM
A property is just accessor methods (http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html%23//apple_ref/doc/uid/TP30001163-CH17-SW1). 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
Aug 8, 2012, 05:22 AM
The workaround is to explicitly create instance variables to back your properties.

E.g. in your header:


@interface MyClass : NSObject {

float _myVar;

}

@property (nonatomic, assign) float myVar;


and in your .m file


@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.

dejo
Aug 8, 2012, 08:42 AM
Maybe this will help:

http://stackoverflow.com/questions/5632477/where-is-the-expression-window-in-xcode-4

forum user
Aug 8, 2012, 01:07 PM
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:
po [[self captureSession] running]

I haven't found a way yet to use dot notation in the console.

Duncan C
Aug 8, 2012, 02:43 PM
set at breakpoint in that line, when execute has stopped go to the debugger console and type:
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
Aug 8, 2012, 04:56 PM
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.

KarlJay
Aug 8, 2012, 06:32 PM
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
Aug 8, 2012, 07:19 PM
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.

KarlJay
Aug 8, 2012, 09:31 PM
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:
(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:
(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
Aug 8, 2012, 10:52 PM
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.

forum user
Aug 9, 2012, 12:59 AM
Here is a tutorial. The po stuff is towards the end:

http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1

Duncan C
Aug 9, 2012, 08:54 AM
Here is a tutorial. The po stuff is towards the end:

http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1

The p (print-value) and po (print-object) commands are from the GDB debugger. In LLDB they are offered as aliases to LLDB commands for compatibility.

I, at least, am trying to learn about LLDB, since it's the default debugger for Xcode 4.3 and later. (Or is that 4.2 or later?)

KarlJay
Aug 9, 2012, 04:12 PM
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

PhoneyDeveloper
Aug 9, 2012, 05:05 PM
Edit Scheme.

KarlJay
Aug 9, 2012, 06:26 PM
Edit Scheme.

Ok, looks like Xcode 4.01 doesn't offer LLDB. I have two choices GDB and NONE.

Might be time for an update :D