Xcode Development Debugging Tips-Breakpoint debugging

Source: Internet
Author: User
Tags print object

Http://www.itcast.cn/news/20141015/16463596716.shtml

1.Condational Breakpoints (conditional breakpoint)
A normal breakpoint stops the program as long as it executes to the line where the breakpoint is located, but sometimes we want to stop the program when certain conditions are met. This debugging technique is useful when you want to capture a specific value of a variable in a loop, or something that doesn't happen often, without having to stop at each iteration to see it.
How do I turn on conditional variables?
1. Add a normal breakpoint

2. Right-click on the breakpoint and select "Edit breakpoint"

3. Open the breakpoint editor, where you can set the breakpoint condition (and some other breakpoint settings), and then you can witness the miracle.



2.Global Breakpoint (Global Breakpoint) when an application generates an exception or crashes, Xcode will generally jump directly to the main function. But that's not what we want, and what we want is to create an exception or crash where the exception or crash occurs instead of jumping to the main function. Fortunately, there is a way to do that.
Xcode has a beautiful function called an exception breakpoint, allowing us to place a breakpoint where the exception occurred when the exception occurred. You can specify a specific exception or you can specify all exceptions.
How do I turn on an abnormal breakpoint?
1. The project switches to the Abnormal Browsing window, click the "Add Breakpoint" button on the left of the bottom
2. Select "Add Exception Breakpoint" to ensure that all exceptions can be caught.



The catch to exception effect is as follows:



3. GDB command to debug a program
In general, we add breakpoints in our program code to see the state of a variable through the ' Variables view ' provided by Xcode, which is next to the console of the Xcode bottom. Theoretically, the window can display the status of all values related to the current context. In fact, this is a little bit of a problem, and sometimes after the breakpoint is over, the window does not make the relevant update. But Xcode has a great feature: we can use the console's commands to check a particular object--which is useful for debugging programs
1.PO command: For the abbreviation of print object, displays the text description of the objects (displays the string information obtained from the object's description message and prints nil if the object does not exist).


2. Use ' P ' when processing scalar values


3. Export the view hierarchy. (but hidden commands), recursivedescription.


4. Other commands (Help):
1. Order explanation
2.break NUM sets a breakpoint on the specified line.
3.BT displays all the call stack frames. This command can be used to display the order in which functions are called.
4.clear deletes breakpoints that are set on a specific source file, on a specific line. Its usage is: Clear filename:num.
5.continue continue executing the program you are debugging. The command is used in the program because of processing a signal or breakpoint
6. Causes the stop run time.
7.display EXPR Displays the value of an expression every time the program stops. An expression consists of a variable defined by a program.
The 8.file file loads the specified executable file for debugging.
9.help NAME Displays help information for the specified command.
10.info break Displays the list of current breakpoints, including the number of times the breakpoint was reached.
11.info files displays detailed information about the file being debugged.
12.info func Displays all the function names.
The 13.info local displays the local variable information in the function.
14.info prog displays the execution status of the debugged program.
15.info var displays all the global and static variable names.
16.kill terminates the program being debugged.
17.list Displays the source code snippet.
18.make run the Make tool without exiting GDB.
19.next executes a line of source code forward without stepping into other functions.
20.print expr Displays the value of the expression expr.
21st.
22.print-object Printing an Object
23.print (int) name prints a type
24.print-object [artist description] Call a function
25.set artist = @ "Test" sets the value of the variable
26.whatis viewing the data type of the variable

Xcode Development Debugging Tips-Breakpoint debugging

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.