Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display the value of a variable property in LLDB debugger?

Tags:

xcode

lldb

I'm using a breakpoint with Action "Log Message", and I want to print the row of an NSIndexPath. So I tried: cell row @indexPath.row@ but nothing gets printed. I also tried using a debugger command: expr (void)NSLog(@"indexPath row:%i", indexPath.row) but I get an error: error: property 'row' not found on object of type 'NSIndexPath *'

What am I doing wrong?

like image 319
Snowman Avatar asked Jul 08 '12 19:07

Snowman


People also ask

How do I see variables in Xcode?

We can show or hide the variables view and the console by clicking the middle view control at the top right or by clicking the leftmost button of the debug bar. The variables view is empty at the moment because the application isn't paused.

How do I print a variable in Xcode?

If the variable is an image or other type that isn't expressible as text, click the Quick Look button at the upper-right to see a preview of the variable. Click the Print Description button to print a description of the object in the console.

How do you set a breakpoint in LLDB?

In lldb you can set breakpoints by typing either break or b followed by information on where you want the program to pause. After the b command, you can put either: a function name (e.g., b my_subroutine ) a line number (e.g., b 12 )


2 Answers

The dot syntax is just syntactic sugar added by the compiler. I've always disagreed with adding it to Objective-C, but some people love it. What you have to remember is that these dots are getting converted into method calls by the compiler, so when you message something directly, like in the debugger, you must use the actual method call. Try rewriting your expression:

expr (void)NSLog(@"indexPath row: %ld", (long int)[indexPath row])

I'm not sure if the debugger's basic log method will execute method calls like this, so you may have to use the expression type.

like image 160
Jason Coco Avatar answered Sep 20 '22 12:09

Jason Coco


I think this is a special case. The code below will work, but only if row is initialised to some value.

(lldb) print (NSInteger)[indexPath row]

I think this might be related to the fact that the row property is an extension of NSIndexPath in UIKit and is implemented as a category on that class.

like image 25
Mike M Avatar answered Sep 22 '22 12:09

Mike M