Only know how to breakpoint with the left mouse button? It's time to try this and that breakpoint

Only know how to breakpoint with the left mouse button? It's time to try this and that breakpoint

[[143035]]

Coding is impossible without debugging, and debugging is impossible without breakpoints. XCode's breakpoint function is becoming more and more powerful.

Basic breakpoints

As shown in the figure below, this is the most commonly used breakpoint and the easiest to set. You can set it with a single left click.

Edit Breakpoints

Breakpoints are editable.

The breakpoint has the following properties that can be set:

  • Condition
  • Ignore
  • Action
  • Options

Condition

Here you can enter a conditional expression, and the breakpoint will take effect when the condition is met. For example, enter a == 50 above. This is a very useful setting, especially when debugging in the loop body. It is really cool to use.

Ingore

Here you can set the number of breakpoints to be ignored.

Action

Action is the most complex and powerful function here. There are 6 types of Action.

  1. AppleScript

  2. Capture GPU Frame

  3. Debugger Command

  4. Log Message

  5. Shell Command

  6. Sound

Commonly used are Log Message and Debugger Command

Log Message

What you fill in here can be printed to the console. For example, I made the following settings:

%B will print the name of the breakpoint, %H will print the number of times the breakpoint is called, and you can enter an expression in the middle of @@. The output of the above settings in the console is as follows:

#p#

Debugger Command

Here you can enter debugging commands, such as po (print object information), bt (print function stack), expression (expression) and other debugging commands. You can understand it by looking at the picture:

The image console output is as follows:

Options

If you check Automatically continue after evaluating actions, the program will continue to run after the breakpoint is generated. This property is quite useful, as it allows you to enter debugging information without pausing the program.

In addition to the basic breakpoints above, XCode also provides the following four breakpoints, which need to be added by clicking the + sign in the lower left corner of the breakpoint panel.

  • Exception Breakpoint

  • OpenGL ES Error Breakpoint

  • Symbolic Breakpoint

  • Test Failure Breakpoint

Exception Breakpoint

Exception Breakpoint is a very useful breakpoint item. As the name suggests, a breakpoint is generated when the program throws an exception. Usually the program crashes and stops at the crash location, but sometimes it cannot stop exactly at the place where the exception is caused. For example, array out of bounds! As shown in the figure below, it will cause array out of bounds access.

The program will crash when it is running. However, the crash stops in the main function. Even if you look at the stack information, you cannot immediately locate the array out-of-bounds access. Why can't the crash stop at the point where the array is out of bounds? This is because array out-of-bounds access does not necessarily cause the program to crash. Array out-of-bounds access will cause an exception to be thrown, and the thrown exception will not be handled before the program crashes. Therefore, it will cause the crash to stop in the CoreFoundation framework. At this time, you need to set an Exception Breakpoint to generate a breakpoint to locate the error.

OpenGL ES Error Breakpoint

This is mainly for breakpoint debugging of OpenGL ES, which I have never used.

Symbolic Breakpoint

Symbolic Breakpoint is really a debugging tool. When the program runs to a specific symbol, a breakpoint will be generated. By adding a breakpoint in this way, you don't need to add it to the source file, nor do you need to know which line of the file the breakpoint is set on. As shown in the figure:

It has two more properties than ordinary breakpoints: Symbol and Module.

Symbol

The contents of Symbol can be as follows:

1. Method name: It will take effect on all class methods with this method name, for example initWithFrame:.

2. Class-specific methods: applicable to both OC and C++ classes, for example, [UIView initWithFrame:] or Shap::draw().

3. Function name, such as a normal C function.

Debugging by setting Symbol is so convenient that you can't stop at all and can set breakpoints wherever you want.

Test Failure Breakpoint

This type of breakpoint will pause program execution when a test assertion fails.

<<:  Using Clang Address Sanitizer directly on Xcode 7

>>:  Improve problem-solving skills through psychological knowledge

Recommend

ARKit & OpenGL ES - ARKit principle and implementation

Principle If you want to learn more about OpenGL ...

Mobile technology for the masses: words and gestures from the Overheard Word

[[120670]] Programmatically integrate third-party...

Optimize the allocation of advertising resources

After I took over the client, I proposed several ...

Huang Yongsheng's resume: website promotion and marketing skills

Website promotion and marketing of pharmacies 1. ...

Wuwei Mindset: "Trading Sense Training Camp" 238th issue

Resource introduction of the 238th issue of "...

In addition to Meizu, there will be more Ubuntu phones on the market

At the moment, it's hard to measure the succe...

Event Promotion: How to do a good job in event review?

Since last year, I have started to learn how to r...

More than 660 alien species have invaded China

More than 660 alien species have invaded China (w...

Summary of 2 aspects: The right way to open user growth

The essence of user growth is to conduct precise ...