The LLDB debugger has long replaced GDB as the default debugger in Xcode projects.

Lldb.llvm.org/tutorial.ht…

How to run commands: You must break the point – > before entering debugging statements in the console. Or click pause after running.

Command completion: The completion pops up automatically when the third character is typed, or manually by using the Esc key.

About the ~/.lldbinit file: LLDB reads the ~/.lldbinit file on startup. This file holds the scripts/aliases that are executed when the LLDB is started.


Debugging commands

$0 $1 is a debug record of the current run and can be used directly. (Anything that starts with a dollar character exists in the LLDB namespace.)

The LLDB command actually does prefix matching. So like print, you can also use prin, pri, or p. But you can’t use pr because LLDB does not disambiguate process.

Help Displays the command help. (All commands are displayed when no parameter is passed. You can view the usage of moi parameters in detail.)

Help Po help break command add View the help of the add parameterCopy the code

The p (print) function prints information about native types (Boolean, INTEGER, float, etc). Format listing

P (int)[[[self view] subviews] count] p/x 16 print/< FMT > format p/t 16 binary output (t stands for two) p/c 16 Print string x/4c $STR X is called View memory. Look at four bytes hereCopy the code

The Po (print Object) function prints information about objects in Objective-C.

Po [[UIApplication sharedApplication] keyWindow] recursiveDescription prints the current view hierarchyCopy the code

Call, like Po or P, is a call. Used when the output is not needed.

call [self.view setBackgroundColor:[UIColor redColor]]Copy the code

Expr (expression, also abbreviated as E) modifies variable values, Pointers, etc.

E nsstrings * $STR = @ "blog.xigulu.com" to define a variable STR e @ import UIKit cellItem. E layer. The borderWidth = 1 e (void) [CATransaction Flush the interface (called when the interface is flushed because the program has been paused)Copy the code
E id $view = (id) 0x7FBD71432590 e (void) [$view setBackgroundColor:[UIColor redColor]] Changes the background color of the view (void)[CATransaction flush]Copy the code
NavigationController e id $vc = [[UIApplication sharedApplication] keyWindow] rootViewController [UIViewController new] // Generate a vc e (void)[[$vc view] setBackgroundColor:[UIColor yellowColor]] e (void)[$vc setTitle:@"Yay!"] E (void)[$NVC pushViewContoller:$vc animated:YES] //push caflush // e (void)[CATransaction flush] // displayCopy the code

Bt (thread backtrace) prints the call stack, and all prints the stack of all threads. Use this command when the program fails.

You can place the breakpoint at the beginning of the function, override the behavior of the function with the Thread Return command, and continue.

Thread return <exp> Can be used to control the flow of the program and falsify the return valueCopy the code

Frame variable Gets all variable values.

Frame v self->testVar also retrieves the current line count of the frame info variable and the source file, among other thingsCopy the code

Image can be used for addressing, with multiple combined commands. Often used to find the stack address corresponding to the code location, used for error (can locate the number of lines of error code).

Image lookup --address 0x0000000100004AF8 Last stack addressCopy the code

Breakpoint (or b) Sets a breakpoint. (Can be added at run time.)

Breakpoint set -f xxx.m -l 28 第28行. Viewcontroller.swift :28 行. Viewcontroller.swift :28 行 B -[NSArray objectAtIndex:] breakpoint list // Lists all breakpoints. Br li br dis 1 Disable a breakpoint breakpoint delete 3 // Delete breakpoint 3Copy the code

Breakpoint debugging commands: c (process continue), n (step over),s (step in), thread step-out (step out).

N Next s entersCopy the code

Watchpoint: Listens for changes to an instance (equivalent to the Xcode debug variable window – > right-click a variable – >Watch xx)

Note: Watchpoint is typed, including read, write, or read_write. Only write types can be added by right-clicking Xcode.

Watchpoint set self->testVar // Set watchpoint watchpoint set v -w read_write _mybTN // Set a listener of type read_write for _mybTN Watchpoint set expression 0x00007FB27B4969e0 Watchpoint command add -o 'frame info' 1 // Add subcommand 'frame info' watchpoint list for watchpoint 1 Watchpoint delete delete all watchpointsCopy the code

Define aliases: (We are free to create a collection of aliases for LLDB commands. LLDB reads the ~/. Lldbinit file during startup. This file stores the aliases created by the command alias command.

Command alias myCommand image Lookup --address %1 Defines the myCommand aliasCopy the code

The above can be simplified to call myCommand 0x0000000100004AF8

Breakpoint set --file foo.c --line 12 command alias BFL breakpoint set -f %1 -l %2 Unalias BFL Cancels the aliasCopy the code

Declare variables in LLDB: Same as variables in PHP

E int $a = 2 e NSArray *$array = @[@"Saturday", @"Sunday", @"Monday"]Copy the code

Debug the program in the terminal

Use LLDB debuggers

Debugging is usually done in Xcode, but can also be done on the command line. The steps are as follows: Reference (this is similar to the Debug program in Windows)

1. Load the program for debugging

2. Bind a running program to the LLDB

3. Set breakpoints and watch points

4. Control the execution of procedures

5. Navigate through the debugged program

6. Check the status and value variables

7. Implement alternative code

$LLDB/Users/xuneng/Desktop/MacApp MacDown. The app start debugging. (or directly ` LLDB ` into REPL interface) to set breakpoints... $q exits LLDBCopy the code

Q&A

Problem 1: Has unknown return type (unknown type or type mismatch)

P NSLog(@"%@",[self.view viewWithTag:1001]) (this has been fixed in the latest version) p (void)NSLog(@"%@",[self.view viewWithTag:1001]) The type must be explicitly declared.Copy the code

Q2: No known method ‘-characteratindex:’; Cast the message send to the method’s return type

P [[$array objectAtIndex:$a] characterAtIndex:0] P (char)[[$array objectAtIndex:$a] characterAtIndex:0] Add (char) to convertCopy the code

reference

Dancing with the debugger – the waltz of LLDB

Apple LLDB Quick Start Guide