Add breakpoints to Xcode debug

Source: Internet
Author: User

1. Add a global breakpoint (add Exception Breakpoint)

By adding a global breakpoint, you can quickly locate the line of code that caused the program to collapse.
Find Breakpoint Navigator in Xcode (also via shortcut command + 7), click the plus sign at the bottom, and the first one is:

This adds a global breakpoint:

Whenever a program crashes, it triggers the breakpoint and navigates to the line of code that caused the crash.

2. Add symbol breakpoint (add symbolic Breakpoint)

Symbolic breakpoint is a very powerful breakpoint.
Select the second item as the previous step:

After adding, enter viewdidload in the Symbol field.

This will trigger a breakpoint when all viewdidload methods in the program are called.

Of course, our page can add breakpoints just for a particular class of methods. Enter "[ClassName viewdidload]" (objective-c) or "Classname.viewdidload" (Swift) in the Symbol column class.

3. Add a condition to a breakpoint (Condition)

Sometimes we may create breakpoints in a loop, but it is obviously a very inefficient way to click Continue again and again to know the conditions we want to appear. Fortunately, Xcode provides us with conditional breakpoints.

First, insert a normal breakpoint in the following code

Right click on breakpoint, select Edit Breakpoint, enter I > 90 in Condition column

This way, the breakpoint is triggered only when the program is running to meet the criteria.

4. Monitoring breakpoints (Watch)

Most of our debugging program is to monitor the change of a variable, in the code where the variable appears to add a breakpoint is not only tired and may also miss, after the next one to delete, it is very tired.

We can do this simply by adding a monitoring breakpoint to the variable.

Locate the first occurrence of the variable, add a normal breakpoint, enter debug mode, right-click the variable in variables view, and select the watch variable name. So every time the variable triggers a breakpoint to tell us.

We can see the changes in the console.

5. Log information Breakpoints

The most common type of debug should be NSLog or println (Swift). Usually we will print out various instance information in this way to detect the program running state.
But there are also obvious drawbacks to this debug approach:

    • Cannot add at run time
    • Add too many to interfere with the line of sight and need to be removed or commented out in trouble
    • will be compiled into the app, which needs to be turned off in the official version (we can, of course, use the macro to determine if it should be compiled, but this will add extra action)

Fortunately, we have another option in Xcode.
Add a normal breakpoint in the following code, select Edit Breakpoint, then click Add Action, select Log Message, enter the number Is:@[email protected] in the input box.

The effect is as follows:

Because of the log output here, we can tick the bottom of the automatically continue after evaluating actions, so this breakpoint will only silently output the log for us.

Add breakpoints to Xcode debug

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.