Some debugging techniques in iOS

Source: Internet
Author: User

Programmers daily contact with the most is the object (their own initiative new) and bugs, and in the development of some debugging skills is very useful, today work encountered a bug made heart tired, at night to write a little of their own debugging will be used in the method.

Apple's compiler is LLVM, the compiler will help us a lot in development, just like memory management now we can set the arc of the compiler to be active, so that we don't have to be as bitter as we used to be in memory management.

So let's start with a compiler-related debugging technique.

A.lldb debug Command

Lldb is the debugger under LLVM, Xcode starts with the 4.0 compiler instead of LLVM, and the corresponding debugger changes from GDB to Lldb. All projects from Xcode5.0 are also automatically set to use LLDB (I have not contacted GDB)

We can use some LLDB commands to help us Debug.

How to debug first: Break a breakpoint in a project and we can see:

We see the lldb at the point where the arrows are pointing, so that we can enter the instructions:

PO---Most commonly used, PO is generally output objective-c object, p is the basic type of output, but we found that in fact can be used. (Note that the output contains the words in the message.) In fact, the results of each of our queries are saved in some persistent variable ($[0-9]+) so that you can use these values directly in the subsequent query like this:

(LLDB) PO $

Dongdong

Expr---Can dynamically execute the specified expression when debugging and print the results. Often used to modify the value of a variable during debugging

call--is called meaning, such as call age=18, will also get rid of the value 2.3 use the following figure, but in practice I rarely use



4.BT------Print Call stack, plus all to print all thread stack 5.image-----The mage command can be used for addressing, with multiple combination commands, such as image lookup--address the location of the code for the stack address (useful when encountering a heap of stack errors) image lookup--type (finds a matching type and feels mostly useless)

There are a lot of LLDB commands, but this is a few of the things I use in iOS development, and here are some of the LLDB commands and breakpoints

two. Breakpoint

we can do some editing in the breakpoint so that it reaches our requirements, using the method to double-click on the breakpoint to enter the first option, or commond+option+ Click to enter the edit state 1.lldb combination of command and breakpoint



When we hook up the options below, it means that when we run to this breakpoint, we fill in the value of the variable, and then we continue to run without breaking into debug mode here, we see that the output has changed 2. Conditional breakpoint



The meaning in Conditon is that a breakpoint only works if this condition is met.

Summary: Breakpoints and lldb knowledge in fact many, we in the development of its common methods and reasonable use will greatly promote our development speed and improve efficiency.


Related Article

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.