Summary of ios low-level articles

1. The p command

Short for print command

Use the p command to view the values of the base data types

Using the p command to view an object, only the pointer address of the object is returned.

The p command can be followed by variables, constants, and expressions. (But not macros)

2. Po orders

The Po command can be understood as printing objects.

The function is similar to the p command, so it can also print constants, variables, and objects returned by expressions. (Macros cannot be printed)

In addition to using the command, we can also use the left field by right-clicking the variable — > Print Description of “XXX”

3. The expr command

Expr is short for expression. Using the expr command, you can dynamically execute the assignment expression and print the result during debugging.

Dynamically changing the value of a variable during debugging is useful when debugging an application that wants to execute an exception path (such as an else case).

4. Call command

Xcode also supports dynamic invocation of functions.

By running this command on the console, you can modify the view on the interface without modifying the code or recompiling it.

Example: Dynamically remove a label from a contentView

(lldb) po cell.contentView.subviews
<__NSArrayM 0x60800005f5f0>(
<UILabel: 0x7f91f4f18c90; frame = (5 5; 300 25); text = '2 - Drawing index is top ... '; userInteractionEnabled = NO; tag = 1; layer = <_UILabelLayer: 0x60800009ff40>>,
<UIImageView: 0x7f91f4d20050; frame = (105 20; 85 85); opaque = NO; userInteractionEnabled = NO; tag = 2; layer = <CALayer: 0x60000003ff60>>,
<UIImageView: 0x7f91f4f18f10; frame = (200 20; 85 85); opaque = NO; userInteractionEnabled = NO; tag = 3; layer = <CALayer: 0x608000039860>>
)
 
(lldb) call [label removeFromSuperview]
(lldb) po cell.contentView.subviews
<__NSArrayM 0x600000246de0>(
<UIImageView: 0x7f91f4d20050; frame = (105 20; 85 85); opaque = NO; userInteractionEnabled = NO; tag = 2; layer = <CALayer: 0x60000003ff60>>,
<UIImageView: 0x7f91f4f18f10; frame = (200 20; 85 85); opaque = NO; userInteractionEnabled = NO; tag = 3; layer = <CALayer: 0x608000039860>>
)
Copy the code

5. The bt command

The BT command prints the stack information for the thread, which is more detailed than the Debug Navigator on the left sees.

(lldb) bt 
* thread #1: tid = 0x27363.0x000000010d204125 TestDemo`-[FifthViewController tableView:cellForRowAtIndexPath:](self=0x00007f91f4e153c0, _cmd="tableView:cellForRowAtIndexPath:", tableView=0x00007f91f5889600, indexPath=0xc000000000400016) + 2757 at FifthViewController.m:91, queue = 'com.apple.main-thread', stop reason = breakpoint 6.1
 * frame #0: 0x000000010d204125 TestDemo`-[FifthViewController tableView:cellForRowAtIndexPath:](self=0x00007f91f4e153c0, _cmd="tableView:cellForRowAtIndexPath:", tableView=0x00007f91f5889600, indexPath=0xc000000000400016) + 2757 at FifthViewController.m:91
  frame #1: 0x0000000111d0a7b5 UIKit` -UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 757
  frame #2: 0x0000000111d0aa13 UIKit` -UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
  frame #3: 0x0000000111cde47d UIKit` -UITableView _updateVisibleCellsNow:isRecursive:] + 3295
  frame #4: 0x0000000111d13d95 UIKit` -UITableView _performWithCachedTraitCollection:] + 110
  frame #5: 0x0000000111cfa5ef UIKit` -UITableView layoutSubviews] + 222
  frame #6: 0x0000000111c61f50 UIKit` -UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
  frame #7: 0x00000001117a5cc4 QuartzCore`-[CALayer layoutSublayers] + 146
  frame #8: 0x0000000111799788 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 366
  frame #9: 0x0000000111799606 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
  frame #10: 0x0000000111727680 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 280
  frame #11: 0x0000000111754767 QuartzCore`CA::Transaction::commit() + 475
  frame #12: 0x00000001117550d7 QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long.void*) + 113
  frame #13: 0x0000000110743e17 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
  frame #14: 0x0000000110743d87 CoreFoundation`__CFRunLoopDoObservers + 391
  frame #15: 0x0000000110728b9e CoreFoundation`__CFRunLoopRun + 1198
  frame #16: 0x0000000110728494 CoreFoundation`CFRunLoopRunSpecific + 420
  frame #17: 0x0000000114390a6f GraphicsServices`GSEventRunModal + 161
  frame #18: 0x0000000111b9d964 UIKit`UIApplicationMain + 159
  frame #19: 0x000000010d21294f TestDemo`main(argc=1, argv=0x00007fff529fe620) + 111 at main.m:14
  frame #20: 0x000000011458a68d libdyld.dylib`start + 1
(lldb)
Copy the code

The bt all command prints stack information for all threads.

6. P/t command

Binary printing

7. X command

Print memory dataCan be followed by an object (eg: x person) equivalent tomemory read (eg: memory read person)

4 x/gx command

X: prints memory data

4: prints four segments of address data

G: indicates the print format. Apple is in small-end mode. You need to read from back to front when reading

X: a 16-bit hexadecimal value of data that constitutes a value

X /4gw Command x: Prints memory data

4: prints four segments of address data

G: indicates the print format. Apple is in small-end mode. You need to read from back to front when reading

W: 8-bit hexadecimal values of data make up a value

8. Image command

Image list: Reads the entire image file in memory

Command to list all modules in the current App.

In addition to image list, there are image add, image lookup and other commands.

When crash occurs, only the address of stack frame can be seen by checking the thread stack. The image lookup-address address can be used to conveniently locate the code line corresponding to this address.