Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to watch variables without using breakpoints in XCode 4?

I am pretty sure I know the answer already but thought I'd ask anyways. I'm about sick and tired of having to create Logs and Breakpoints just to make sure my variables are where I want them to be at a certain point.

Anyone know of a way to watch variable as they are running without breakpoints/logs?

Thanks!

like image 967
Louie Avatar asked Dec 28 '22 09:12

Louie


2 Answers

If you want to ensure that your variables must be a certain way at a certain point, that's what assertions are for (NSAssert() for instance).

If you just want to know when a variable changes, use a watchpoint rather than a breakpoint. (Click on the variable in the debugger and select "Watch.")

If you want to check a variable at a certain point and break only if it's "something in particular," use a conditional breakpoint. Right click on the breakpoint in xcode and select "Edit breakpoint." You can also use this to only break every so often (such as after 100 fires).

If you just want to know when a line of code is reached, but not stop there, use the action "Sound" on the Edit Breakpoint window and then "Automatically continue after evaluating actions." I use this quite a lot in performance work. When I hear it start buzzing, I know I've found a hotspot in the code.

Did you have something else in mind?

like image 51
Rob Napier Avatar answered Apr 29 '23 11:04

Rob Napier


Following on to Rob Napier's excellent suggestions, you can also edit a breakpoint to log the values that you care about and then continue, like this:

Image showing a logging breakpoint.

As you can see, I've set this breakpoint to log the value of the expression [marker center]. GDB often needs help to know what the final type of an expression is, which is why I had to add the (CGPoint) cast. This is obviously a little more work than just clicking in the left column to set a plain old breakpoint, but it's arguably less work than inserting NSLog() statements in your code, and you can do it in the middle of a debug session -- no need to recompile or even restart the app.

like image 40
Caleb Avatar answered Apr 29 '23 09:04

Caleb