IOS efficient debugging

Write code is inevitable bug. Reserve some debugging skills can definitely improve your work efficiency, let bug have no place to hide. Here and share some of my work in the iOS debugging skills.

1 print


The easiest way to do this is to print the log. Paste the two sections of the package of the log code:

The //swift version of func DLog< T> (message: T, file: String method: = #file, String = #function, line: = Int #line) {#if ("DEBUG print < / ((file as NSString).LastPathComponent): / (line) >, (method); / / (message) #endif //OC}") #ifdef DEBUG #define DLog Edition (FMT,...) (NSLog (@ <%s:%d>%s FMT), [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); # else #define DLog (#endif...)

Eg:

/ / call the following methods in AppDelegate.m - (void) applicationDidFinishLaunching: (UIApplication *) application{DLog (@ "Hello world");} / / 17:19:27.931 DateCell[2901:1622220] < print results: 2016-09-18; AppDelegate.m: 54> AppDelegate - applicationDidFinishLaunching:] Hello World

2 breakpoint


(1) ordinary breakpoint

Common breakpoints are most commonly used in debugging. When the program runs to the breakpoint will be suspended. The method is very simple: click on the left side of the line of code that needs to be set.

IOS efficient debugging
common breakpoint

(2) conditional breakpoint (adding a condition to the breakpoint and other attributes, for the time being)

Conditional breakpoints are added on the basis of the ordinary breakpoint. A breakpoint is valid when the program is executed to the breakpoint and satisfies the conditions set. The method is as follows:

IOS efficient debugging
open breakpoint edit box
IOS efficient debugging
here to write picture description

In the above settings, the condition breakpoint condition is i==3, then the entire cycle is only i=3 when the program stops at the breakpoint.
has the following four entries in the Edit Breakpoint window:

Condition settings. Ignore indicates how many times the breakpoint is disabled. For example: do not set conditions, Ignore is set to 4, then the i=4 program at the breakpoint stop. The action that Action performs at the breakpoint of the program (after this operation is completed, the code is not executed). Here is the operation of the LLDB statement on the LLDB will be described below. When Options is elected, the code will not stop after executing the Action operation, just as there is no breakpoint.

(3) abnormal breakpoint Exception BreakPoint

In the event of an exception, the Xcode will help us locate the location of the crash when the program is crash.

IOS efficient debugging
without exception breakpoint
IOS efficient debugging
set exception breakpoint

Set breakpoint:

IOS efficient debugging
here to write picture description

(4) symbol breakpoint Symbolic Breakpoint

A symbol breakpoint can set a breakpoint for a method or a method of a class. Functions as follows:

IOS efficient debugging
one of the methods of a class set breakpoint
IOS efficient debugging
performs breakpoints in a method

The steps are as follows:

IOS efficient debugging
symbol breakpoint setting step

3 LLDB


LLDB Xcode default debugger, we execute the LLDB command to make the debugging process more flexible.
Xcode embedded LLDB debug window. You can enter the LLDB command to debug the process after the execution of the program.

IOS efficient debugging
LLDB debug window

LLDB commonly used commands are as follows:

1, Po (print object) output objects, such as po [self view] (
), P (print) for the output of the basic types, such as P (int) [[[self view] subviews] output count] number of sub views.
3, expr (expression) can be dynamically executed at the time of the specified expression, and print out the results. Often used to modify the value of a variable during debugging. As shown above, the first implementation of
program to execute the following command: expr i=4
when the breakpoint you will see the following output: (int) $0 = 4
to run the program, the program output information is: value:4 i==4
4, call call is called. In fact, the above Po and P also have the function call. Therefore, the general use of call is not only the need to display the output, or the method does not return a value. We can set a breakpoint in the viewDidLoad:, and enter the following command when the interruption of the program: call the view setBackgroundColor:[UIColor [self.view redColor]] background color to red.
5, BT print call stack, plus all can print all the thread stack. No detailed examples, interested friends can try.
6, FR V -R command to print out the variables of unprocessed information

If you want to know more details, poke here.

4 Chisel


Chisel is an open source Facebook for interface debugging lldb command.

install

Chisel use homebrew to install, if you do not install homebrew, refer to homebrew.

Brew update brew install chisel

After the installation is complete, add the following to the ~/.lldbinit, no ~/.lldbinit is new.

~/.lldbinit command script import /path/to/fblldb.py #...

Restart Xcode, then Chisel can be used.

command

IOS efficient debugging
command set

Bad English students can see here.

5 interface debugging tool: Reveal


Reveal is absolutely iOS interface debugging tool. Just use it once and you’ll never get away with it. For the introduction of Reveal can go to the official website to understand.

install

Reveal is a fee, to promote genuine. The following version is only for teaching use, not for the production environment.
1, install the package and crack the software link: https://pan.baidu.com/s/1dFgjaYP password: 6wyq
2, see the use of cracking steps to explain the use of the document.
3, open Reveal and start using. The new version of Reveal may modify the verification logic, if there is no crack success then use genuine it. Configuring the project requires a simple configuration of the iOS project before using Reveal.

Collocation method

Configure a little trouble. The following is a detailed configuration process:
1, use Xcode to open the project you want to view UI;

2, open Reveal, click Help Show Library Reveal in Finder;

IOS efficient debugging
here to write picture description

3, drag the Reveal.framework into the Xcode project and click finish;

IOS efficient debugging
here to write picture description

4, click Build Phases and then delete the Binary from Link With Reveal.framework Libraries;

IOS efficient debugging
removed from Link With Libraries Binary Reveal.framework

5, then select Build Settings in the search bar to enter Other Linker Flags. Select Other Linker
in Other Linker Flags enter the following code: -ObjC -lz -framework Reveal

IOS efficient debugging
configuration Other Linker Flags

6, run the simulator, open the Reveal, link simulator.

IOS efficient debugging
link simulator

This is done. Then you can through the Reveal interface to your debug.

IOS efficient debugging
effect

6 debugging tool set: FLEX


FLEX is a series of open source Flipboard application debugging tools. FLEX to third party libraries in the form of integration in the application, use the library to the project, and then by calling the [[FLEXManager sharedManager] showExplorer]; you can show a toolbar for debugging debugging.

It provides the following functions:

  • View and modify views
  • View properties of any object
  • Dynamic modification properties
  • Dynamic invocation instance methods and class methods
  • Network request process
  • Added analog keyboard shortcuts
  • View system log
  • Get any object from the heap
  • View files in sandbox
  • View the SQLite/Realm database in the file system
  • Trigger 3D touch in simulator
  • View all classes in your application
  • Quick access to commonly used classes, such as [UIApplication sharedApplication], the app delegate, the root controller the key window, and on more., view
  • Dynamic view of the value inside the NSUserDefaults

It’s just hanging up. When you integrate FLEX into your project, you realize its power.

epilogue

Above introduced six kinds of debugging methods, the development can be selected according to the specific circumstances of the most appropriate debugging methods. If this blog is helpful to you.