iOS LLDB console debug总结

Xcode's debugging console window is a full-featured LLDB debugging console. When your app is paused(at a breakpoint), the debugging console shows the LLDB command prompt. You can type any LLDB debugger common into the console to help you with debugging, including loading external python script.

The most frequently used command is po, which stands for print object. When your application is paused in debugger, you can print any variable that is in the current scope. This includes any stack variables, class variables, properties, ivars, and global variables. In short, any variable that is accessible by your application at the breakpoint can be accessed via the debugging console.

Printing scalar variables

when you're dealing with scalars like integers or structs(CGRect, CGPoint, etc..), instead of using po, you use p, followed by the type of struct.

p (int) self.myAge

p (CGPoint) self.view.center

Printing Registers

Registers in your CPU are used for storing variables that have to be accessed frequently. Compilers optimize frequently used variables like the loop variable, method arguments, and return variables in the registers. When your app crashes for no apparent reason, probing the register for the method name or the selector name that crashed your app will be very useful.

(lldb) register read

General Purpose Registers:

        r0 = 0x37c9cb21  libobjc.A.dylib`objc_msgSend + 1

        r1 = 0x37c9cb21  libobjc.A.dylib`objc_msgSend + 1

        r2 = 0x01b5c214  "idKey"

        r3 = 0x01b5eb28  "checkCurrentContactBean"

        r4 = 0x00000000

        r5 = 0x37c9cb21  libobjc.A.dylib`objc_msgSend + 1

        r6 = 0x27d09bd0

        r7 = 0x27d09bc8

        r8 = 0x01b5bbc4  "view"

        r9 = 0x00000000

       r10 = 0x01b5e3f8  "masterViewController"

       r11 = 0x00000000

       r12 = 0x3a11c1d0  (void *)0x382c3959: _os_lock_handoff_unlock$VARIANT$mp + 1

        sp = 0x27d09358

        lr = 0x37cacabb  libobjc.A.dylib`objc_object::sidetable_release(bool) + 95

        pc = 0x002cce40  iPoS_IOS`-[PersonMainForm viewWillAppear:] + 232 at PersonMainForm.m:59

      cpsr = 0x60000030


Your output may vary, butt pay close attention to the waxdcx, and esi on the simulator or r0-r4 registers when running on a device. These registers store some of the values that you're interested in. In the Simulator, the dcx register holds the name of the selector that is called when your app crashed. You print an individual register to console by specifying the register name as shown below

register read ecx.

You can also specify multiple registers like

register  read eax ecx.

The dcx register on Intel architecture and the r15 register on ARM architecture hold the program counter. Printing the address of the program counter will show the last executed instruction. Similarly, wax(r0 on ARM) holds the receiver address, ecx (r4 on ARM) and holds the selector that was called last. The arguments to the methods are stored in registers r1-r3. If your selector has more than three arguments, they are stored on stack, accessible via the stack pointer(r13). sp, lr, and pc are actually aliases to the r13,r14 and r15 register, respectively. Hence, register read r13 is equivalent to register read sp.


你可能感兴趣的:(ios,debug,lldb)