Breakpoints
Breakpoint Classification
Breakpoint are also classified. I am here in the article roughly according to the way of use divided into Normal breakpoint,exception breakpoint,opengl ES Error breakpoint,symbolic breakpoint,test Failure Breakpoint,watchpoints. The ability to use different types of breakpoint according to detailed scenarios is fundamental to solving this problem.
Normal Breakpoint
Adding a normal breakpoint is not much to say. Click on the right side of the source code to do it. Or. Use shortcut keys: Command + \ To add and delete. These two ways of joining breakpoints on Xcode can be seen through the UI.
There are also the ability to add breakpoints directly at execution with the following two LLDB commands. However, it is important to note that breakpoints cannot be seen directly through the UI on one hand. On the other hand, only exists in this execution, the next time the simulator is executed again, these breakpoints will not take effect.
For example, the "BR li" command to print all the breakpoint, can see a common with 3 breakpoint. The first one was joined through the Xcode UI, and the next two were joined by the following two commands: "Breakpoint set-f xxx.m-l XX" and "B xxx.m:xx".
Exception Breakpoint
The ability to join exception breakpoint through the UI in Xcode. Sometimes. For example, an array is out of bounds or an empty object is set. Throws an exception, but this type of error can be difficult to locate. You can use exception breakpoint at this time to debug, to catch and stop the program when an exception occurs.
The exception in OC is a place that is often overlooked, but in fact the system is widely used within the framework. Most of these error messages, the system framework will be thrown out in the form of exceptions, so the use of such breakpoint, we can greatly reduce the time to find errors.
For example, after we join exception breakpoint such as the following (BT command after the text will be explained.) The purpose of this command is when a breakpoint is triggered. Print callback stack information):
This array is similar to the problem of cross-border. We are able to locate the problem very easily. No more searching for a clue:
When a breakpoint is paused, we are able to view the call stack information through the Xcode UI:
or view the call stack information printed by the BT command:
There are similar errors such as the following can be very easy to navigate through such breakpoints to:, just such a problem, can be avoided by using setvalue:forkey: substitution.
OpenGL ES Error BreakpointJoin the button in the lower part of Xcode's Breakpoint navigator. Select "Add OpenGL ES Error Breakpoint" to do so.
This breakpoint is primarily used to stop the execution of the program when OpenGL ES errors occur.
Symbolic BreakpointJoin symbolic breakpoint through the UI of Xcode with exception breakpoint, pop-up boxes such as the following:
Symbolic breakpoints when a particular function or method starts to run. Pauses the program's operation. By adding a breakpoint in this way, we do not need to know whether to add it in the source file or to know the breakpoint set in the first line of the file.
, the most basic setting is the content of the symbol. Can have for example the following several: 1. A method name. The method name. For example, Pathsmatchingextensions: This method name will work on all classes of this method.
2. A method of a particular class. A method of a particular class.
For example, [Skline Drawhandlesinview]. or people::P erson::name ()
3. A function name. The function name. For example, _objc_msgforward such a C function.
In addition, symbolic breakpoints can be added to the command line.
To add a breakpoint to the C function:
Add a breakpoint to the OC method:
This type of breakpoint is often used, objc_exception_throw can be used to replace exception breakpoint. Another-[nsobject Doesnotrecognizeselector:] is also more frequently used to detect method calls that fail.
Test Failure BreakpointThe UI join method via Xcode is the same as above. This type of break point pauses the operation of the program when test assertion fails.
watchpoints
Watuchpoints is a tool used to listen for changes in the value of a variable or change in memory address, triggering a pause in the debugger when a change occurs.
For those states that do not know how to track accurately, this tool can be used to solve the problem. To set Watchpoint. When the program executes to the stack frame including the variable you want to observe, let debugger suspend execution, this time the variable is in the scope of the current stack frame, this time the ability to set the variable watchpoint.
You can set watchpoint in Xcode's GUI, keep the variables you want to watch in Xcode's Variables view, then right-click to set "Watch XXX". As a percentage, observe the title variable of self and click on Watch "_button1clickcount".
command Line
Or you can set the Watchpoint:watch set variable _button1clickcount from the command line. Specific commands can be tested: http://lldb.llvm.org/lldb-gdb.html, there are several commands to achieve the same effect.
The above is an observation of the variables. In fact, we can observe the random memory address, such as the following command: Watchpoint set expression-0x123456. References: http://stackoverflow.com/questions/21063995/watch-points-on-memory-address
It is important to note that Watchpoint is a sub-type, containing read,write or read_write types, which is easy to understand whether the watchpoint is triggered when reading, writing, or reading or writing variables or memory.
Read,write or Read_write follows the-w parameter to indicate the type.
Other than that. The command line. Watchpoint other shorthand, set shorthand is S. Watch shorthand is wa,variable shorthand for V.
The following demo sample is a few commands from the http://www.dreamingwish.com/article/lldb-usage-a.html site:
The first command is to listen to the memory address of the _ABC4 variable write changes, the second is to listen to _ABC4 variable read changes, the third is to listen to _ABC3 variable read_write changes.
It is important to note that. The watchpoint that is added through the Xcode GUI is the default type, which is the write type. If you want to join read-write watchpoint, you can only join by using command-line tools.
Using Watchpoint modify-c ' (xxx==xx), the change is watchpoint after a certain value is monitored.
Editing Options
Breakpoint Condition
When we edit breakpoint through Xcode, we can find that the normal breakpoint and symbolic breakpoint have a "Condition" input option, which is very easy to understand, These breakpoints only work if you set the condition expression to Yes.
For example, breakpoint stops executing when the string is inferred to be equal:
Be able to notice the use of stringwithutf8stirng here: method. The reason is that LLDB's expression parser has a bug. Incompatible non-ASCII characters, need to deal with the line, or will be error "an Objective-c constant string ' s string initializer are not an array", Reference:/http Stackoverflow.com/questions/17192505/error-in-breakpoint-condition
A simpler example would not be said. For example i = = 99 simple comparison, only the result of the expression is the bool type can be.
Breakpoint Actions
You can see that there are basically "Add Action" options in each of the breakpoint editing options above, and when breakpoint is triggered, the actions we set are first run. Then we get control, that is, Xcode shows the UI that the program stopped running. This action is better understood by the sample. We explain it by the exception above that Setobject:forkey:. The code is as follows:
Set Breakpoint:
able to see in. We have a total of 3 action sets.
The first action, which is used to print the specific information of the exception, uses the method: http://stackoverflow.com/questions/17238673/ Xcode-exception-breakpoint-doesnt-print-details-of-the-exception-being-thrown.
The second action, we use the shell command "say". Make the computer sound. read out a piece of text. The third action, we use the "BT" command to print the call stack information
After the setting is complete, when the exception occurs. We will hear the computer voice in English, and then in the log can see such as the following information, the first line is exception descriptive narrative information, the following is the call stack:
continuing after Evaluation
Looking at Breakpoint's edit pop-up window, we can find a "automatically continue after evaluation actions" checkbox option. When we tick this checkbox, debugger will run all the actions added in breakpoint and then continue running the program. For us, in addition to triggering a lot of command and running very long time, the program will skip this breakpoint very quickly, so we may not even notice the existence of this breakpoint. Therefore, the function of this option is equivalent to running after the last action, the direct input continue command continues to run.
With this very powerful feature. We are able to make changes to our program directly through breakpoints. When a line of code stops running, use the "expression" command to directly alter a program's variable settings to change the UI directly. And then continue running. Expression/call with this option, it is very powerful and very convenient to implement very many very powerful functions.
Like what. We implement a function such as the following to change the background color of the selectbackgroundview of the first cell of TableView to red:
The action's content is "expression [[cell Selectedbackgroundview] Setbackgroundcolor:[uicolor Redcolor]", where the expression is not to be cared for first. As we'll see later in the Lldb chapter, after the change, when we click on the cell, the cell's background will be red for example:
In this way, we can implement various debugging effects on the UI without having to change one line of code, just by changing the breakpoint.
References:
- Https://developer.apple.com/library/ios/recipes/xcode_help-breakpoint_navigator/articles/about_breakpoint_navigator.html
- http://www.objc.io/issues/19-debugging/lldb-debugging/
- http://blog.csdn.net/freshforiphone/article/details/8546677
- https://www.bignerdranch.com/blog/xcode-breakpoint-wizardry/
- http://lldb.llvm.org/tutorial.html, lldb command Daquan
Lldb
Use commands frequently HelpEnter the help command directly to list all available commands. Use Help <command> to get a command's detailed usage
expressionAbbreviated form: expr/e. Execute the expression at debug time to change the value of the program's variable directly, or declare a variable object using this command.
For example: Change the value of a variable: expression count = 20 or declare a new variable a:
The expression command can have a number of parameters. But it will also bring some problems. For example: e-h +17 command, this command on easy confusion, exactly-h is the parameter flag, and then +17 is the input variable. Or to calculate the last value of the-h+17 expression.
Lldb provides a very easy solution, using "--" to specify the termination of the command, the beginning of the command input。 For example, E-h-+17 represents the first explanation of the command in the preceding article, and E---h+17 represents the second interpretation of the command in the preceding article.
PrintAbbreviated form: prin/pri/p. But can not use PR Express. Because it is confused with process. As a matter of fact. You will find. Lldb for the short name of the command, is the head matching method, only to be confused with each other, can be abbreviated to a command.
In fact, if you enter "Help print" in the console, you will get
' print ' is a abbreviation for ' expression--'This sentence, which means that print is actually equivalent to expression--。
It's easy to understand how the following commands work. P _lastpoiid=20. This line of command expression is run.
To print an object, use the PO command, the expression is Expression-o-XXX
Using print/<fmt> or p/<fmt> to format the print variable, you can refer to the corresponding format list: https://sourceware.org/gdb/onlinedocs/gdb/Output-Formats.html. p/x prints a variable using hex, p/t prints the integer using binary, p/c prints the character, p/s prints the C string.
Now that we can print objects and simple types, and change them directly through the expression command in debugger. Then we can alleviate our workload by using some variables. As we've said before, we can declare variables directly using the expression command. Note, however, that the newly declared variable must start with the $ sign.
The last command gave an error because LLDB was unable to determine the type of the result. Must be a stronger conversion to tell LLDB.
PagerInvokes the command. Similar to expression, the average user does not need to print the results or where there is no return value
BTTo print the call stack information, use the BT all command to print out the call stack information for all of the thread, for example: Calls [Self.view Setbackgroundcolor:[uicolor Redcolor]. Use this command to set the background color of the view controller to red
ImageThe image command can be used for addressing. There are multiple combinations of commands. A useful way to use this is to find the appropriate code location for the stack address. Specific use methods: http://www.starfelix.com/blog/2014/03/17/lldbdiao-shi-ming-ling-chu-tan/. http://blog.csdn.net/hursing/article/details/8745334
FAQcompatibility with ChineseAs mentioned in the previous article, you must use the [NSString stringwithutf8string:] method When you have Chinese, because the LLDB expression parser has a bug. Non-ASCII characters are not compatible. Need to deal with it, otherwise it will be error "an Objective-c constant string ' s string initializer was not an array", reference: http://stackoverflow.com/ Questions/17192505/error-in-breakpoint-condition
Types of issuesWhen the type is indeterminate or type mismatch occurs. will be an error. This time must be forced to convert talent enough.
For example, the expression of the method that gets the Indexpath row in the previous article: (int) [Indexpath row], or a simply no return value P (void) NSLog (@ "%@", [Self.view viewwithtag:1001]) like the following. or P (char) [[$array objectatindex: $a] characteratindex:0] above, you need to understand the type of output in these scenarios.
Method not foundNote that you cannot use the DOT syntax when using the properties of a system framework object. For example, the problem.
Change to a format such as the following:
Chisel
Based on LLDB support for Python plug-ins, http://lldb.llvm.org/python-reference.html. Facebook developed a set of LLDB command libraries for open source. Https://github.com/facebook/chisel, which includes a lot of very interesting command tools.
The installation method is very easy. Use the Brew tool. Specific reference to the official site, not much to say.
After installation, use the Help command. In the following can user-defined commands be able to find some of the self-defined commands provided by this framework. Chisel provides a lot of useful command-line tools, debugging the UI is very convenient, detailed can refer to the official site.
References
- http://www.objc.io/issues/19-debugging/lldb-debugging/
- http://www.starfelix.com/blog/2014/03/17/lldbdiao-shi-ming-ling-chu-tan/
- Http://www.dreamingwish.com/article/lldb-usage-a.html
- https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/ Introduction.html
- Http://lldb.llvm.org/lldb-gdb.html
- Http://lldb.llvm.org/tutorial.html
- Https://github.com/facebook/chisel
Breakpoints && Lldb & #160;&& Use of chisel