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

Windows 10 Build 10130 feature improvement summary

Windows 10 Build 10130 was released to test users...

Why are 80% of operations destined to be just miscellaneous tasks?

If a person wants to operate well, I think he may...

How much does it cost to make a mechanical equipment applet in Mianyang?

Why should you be an agent for WeChat Mini Progra...

How much does it cost to invest in Anshan Sports Mini Program?

How much does it cost to attract investment in An...

How to operate topic UGC? Think about these 3 questions carefully!

UGC has been recognized as a way to improve produ...

Can you buy your privacy for 300 yuan?! How terrible is "opening the box"...

Is your privacy still safe? Do you dare to believ...

Case analysis: How to build a community content system and active users?

This sharing session will mainly focus on strateg...

Schrödinger's mung bean soup: red or green?

Mung beans have a long history in my country, and...