Viewing values in the debugger

Discussion in 'iPhone/iPad Programming' started by KarlJay, Aug 7, 2012.

  1. macrumors 65816

    Joined:
    May 1, 2010
    Location:
    California
    #1
    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.
     
  2. macrumors 603

    Joined:
    Aug 9, 2009
    #2
    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?
     
  3. thread starter macrumors 65816

    Joined:
    May 1, 2010
    Location:
    California
    #3
    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.
     
  4. thread starter macrumors 65816

    Joined:
    May 1, 2010
    Location:
    California
    #4
    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.
     
  5. macrumors 603

    Joined:
    Aug 9, 2009
    #5
    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.
     
  6. thread starter macrumors 65816

    Joined:
    May 1, 2010
    Location:
    California
    #6
    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.
     
  7. macrumors member

    SteppingStone

    Joined:
    Aug 6, 2012
    #7
    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.
     
  8. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  9. macrumors regular

    Joined:
    Aug 28, 2008
    #9
    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.
     
  10. macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #10
    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.
     
  11. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #11
    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.
     
  12. thread starter macrumors 65816

    Joined:
    May 1, 2010
    Location:
    California
    #12
    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?
     
  13. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #13
    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.
     
  14. thread starter macrumors 65816

    Joined:
    May 1, 2010
    Location:
    California
    #14
    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.
     
  15. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #15
    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.
     
  16. macrumors regular

    Joined:
    Aug 28, 2008
    #16
  17. macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #17
    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?)
     
  18. thread starter macrumors 65816

    Joined:
    May 1, 2010
    Location:
    California
    #18
    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

    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
     
  19. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #19
    Edit Scheme.
     
  20. thread starter macrumors 65816

    Joined:
    May 1, 2010
    Location:
    California
    #20
    Ok, looks like Xcode 4.01 doesn't offer LLDB. I have two choices GDB and NONE.

    Might be time for an update :D
     

Share This Page