Breakpoint Debug proper usage iOS?

2019-07-11 18:46发布

问题:

I put breakpoint. I used command ⌥⌘-click on breakpoint.

It showed me following options.

How can I use these options.

1. AppleScript
2. Capture GPU Frame
3. Debugger Command
4. Log Message
5. Shell Command
6. Sound

There are other options

1. Condition
2. Ignore
3. Action
4. Options

What are these options. How are they working?

回答1:

You can read this detailed tutorial on breakpoints options: https://www.bignerdranch.com/blog/xcode-breakpoint-wizardry/

Short summary:

  • Condition: if condition evaluated to true, breakpoint is triggered.
  • Ignore is self explaining. Like "ignore first 2 passes".
  • Action: what to do if breakpoint is triggered.
  • Options: set if you do not want to stop on this breakpoint in XCode

For action field you can choose what to do when breakpoint is triggered. Possible values is:

  • AppleScript: execute entered AppleScript code
  • Capture GPU frame: capture OpenGL frame contents
  • Debugger Command: execute entered GDB command
  • Log Message: log entered message to console
  • Shell Command: execute entered shell command
  • Sound: play a sound file


回答2:

These options may be used to perform additional actions once the debugger hits this breakpoint.

The "Log Message", for example, can be very useful as it lets you print automatically collected data like the hit count for this breakpoint, the name of the method it's in, values of variables and other expressions.

Using the same principal, you can have the debugger run an Apple script, execute shell commands, etc.

You can also check the "Automatically continue after evaluating actions" so the debugger won't actually break while hitting it - but the action will still be executed.

There are even more advanced options you can utilize like performing the action only when a certain condition is met, ignore the breakpoint unless it has a certain minimum of hits, and even chaining several operations (+ and - buttons).