Xcode breakpoint debugging skills

Source: Internet
Author: User

After a breakpoint is triggered, the system stops running at the breakpoint on the console.

After (lldb), you can use common Debugging commands to debug code lines. The commonly used commands are as follows:

Po (print-object) + object printing Object Information

P (print) + print basic type variable information such as basic data type int

BT prints the last call stack

Expr + variable/object = *** dynamic variable Modification

 

Tip 1: Modify the variable value during running

 

How did you verify whether the entire program cannot work properly due to the value of a variable? Modify the variable value in the code, and then cmd + R restart the app? Now you don't need to do this. You only need to set a breakpoint. When the program enters the debugging mode, you can use the expr command to modify the value of the variable at runtime.

Assume that there is a loginwithusername: method. Two parameters are required: username and password.

Set the breakpoint first, as shown in:

Run the app, enter the breakpoint mode, and enter

 

1 expr username = @"username"
2 expr password = @"badpassword"

The console returns the following information:

 

 

1 (NSString *) $0 = 0x3d3504c4 @"username"
2 (NSString *) $1 = 0x1d18ef60 @"badpassword"

Now exit the breakpoint and execute the two output statements after the breakpoint. The console will have the following output:

 

 

1 (0x1c59aae0) A line for the breakpoint
2 (0x1c59aae0) Username and Password after: username:badpassword

You can see that we modified the value of a variable at runtime, which makes things easier. We can edit the breakpoint so that it can automatically fill in the value of the variable to be modified, in addition, you can choose not to enter the breakpoint mode at this breakpoint, just modify the value of the specified variable, and then automatically execute subsequent code.

 

Right-click the breakpoint and select "Edit breakpoint..." (or press cmd + option and click the breakpoint), and set the breakpoint, as shown in.

Note that the selection box of the last line ("automatically continue after evaluating") is selected. This ensures that when the breakpoint is run, the value of the variable is filled and the variable continues to run, the breakpoint does not enter the debugging mode here.

Run the app and you will get the same output as the value of the variable manually set above.

Next, click the breakpoint to make it disabled. Now the arrow color should be light blue. Run the app again and you will find that the username and password values are not changed at runtime.

 

In addition, if you select automatically continue after evaluating in the breakpoint settings, you can finish the corresponding tasks at the break point (for example, you can use the lldb command to output or modify the variable value)

Xcode breakpoint debugging skills

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.