Mastering macOS Programming
上QQ阅读APP看书,第一时间看更新

Editing breakpoint options

Right-click on the breakpoint to edit it:

We'll get to Edit Breakpoint... in a moment, but for now, note that you can disable and delete the breakpoint from here, or you can show it in the Breakpoint Navigator, which is very convenient when you have that huge number of breakpoints that you get when you've totally lost the plot. And who doesn't do that?

Okay, now select Edit Breakpoint....

You have a number of options that can help you make your debugging several orders of magnitude more focused:

In the preceding screenshot, you can see that we have added a few caveats to the breakpoint:

  • A Condition is set with a simple Boolean expression (Objective C veterans will appreciate the simplicity here). If the condition is not met, the breakpoint is ignored.
  • We have left the Ignore value at 0, although it often makes sense to restrict the breakpoint to be active after a line of code has been executed one or more times already. Need to know whether that line is executing more often than you expect it to? This is where to go.
  • For the Action parameter, we have selected Log Message (more of the other actions in a moment). A message can be any string you want, and note the %B we have added, which will print the name of the breakpoint's location in the code. The %H that prints the hit count can also be a great help in tracking down bugs.
  • You can even add an expression here, in the form @thisInt * thatInt@, which can be very useful indeed during debug sessions.

By clicking the + sign next to the Action menu, we have added a second action, this time choosing to play a sound. Now, this is a feature for those times when you're working alone, or at least have headphones to hand, but don't dismiss it as a gimmick; particularly when you have the option Automatically continue after evaluating actions selected, this can be a really practical tool. It allows you to monitor what is going on without having to stop, or even look away from, the code, and a few of these audible breakpoints in quick succession will convey a lot of information without interrupting the flow of the program (or the programmer). I use this a lot. Yes, you'll get caught by your colleagues occasionally and they'll think you're crazy.