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!
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?
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With