转载

LLDB常用命令

基本命令

po:打印出对象的description描述。

这里列出几个常用的场景:

  • 查看KVO的详细信息:
po [observedObject observationInfo]
  • 查看AutoLayout布局的view的层级结构,需在 layoutSublayersOfLayer: 方法中添加断点。详参这篇。
po [self _autolayoutTrace]

e:在当前程序环境中,执行任何的表达式,并且可以定义和操作已存在的变量。

$ e result = []

控制流快捷命令

  • n ,Step Over
  • s , Step Into
  • finish , Step Out
  • c , 恢复程序执行操作
    thread return :不但可以使当前的函数返回,而且还可以任意修改当前函数的返回值,而不管传进来的参数如何。

断点创建命令

(lldb) breakpoint set -f ViewController.swift -l 28 Breakpoint 2: where = Example`Example.ViewController.viewDidLoad (Example.ViewController)() -> () + 478 at ViewController.swift:29, address= 0x000000010f74f61e 

简写:

b ViewController.swift:28 b add (add为函数名) 

一点Chisel

查看命令用法: help [command]

(lldb) help pviews
Print the recursion description of ~<aView>~.

Arguments:
~<aView>~; Type: UIView*/NSView*; The view to print the description of.

Options:
--up/-u ; Print only the hierarchy directly above the view, up to its window.
--depth/-d ~<depth>~; Type: int; Print only to a given depth. 0 indicates infinite depth.

Syntax: pviews /[--up] /[--depth=depth] ~<aView>~

This command is implemented as FBPrintViewHierarchyCommand in /usr/local/Cellar/chisel/1.2.0/libexec/commands/FBPrintCommands.py.

(LLDB adds the next line, sorry...)

查看view的层级结构的 原生命令

(lldb) po [[[UIApplication sharedApplication] keyWindow] recursiveDescription]

Chisel的简化版: pviews

  • 语法为: pviews [--up] [--depth=depth] <aView>
  • 可以添加以下参数:
    • —up/-u:只打印直属于当前view的层级关系。最高层为它的window。
    • —depth/-d :只打印指定层数,0意味着不限制层数。
(lldb) pviews
<UIWindow: 0x7f994423a3a0; frame = (0 0; 768 1024); autoresize = W+H; gestureRecognizers = <NSArray: 0x7f994423abc0>; layer = <UIWindowLayer: 0x7f9944239e90>>
| <UILayoutContainerView: 0x7f9943d4a160; frame = (0 0; 768 1024); transform = [0, -1, 1, 0, 0, 0]; autoresize = W+H; layer = <CALayer: 0x7f9943d4a380>>
| | <UITransitionView: 0x7f9943d4bbc0; frame = (0 0; 1024 768); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x7f9943d4be00>>
| | | <UIViewControllerWrapperView: 0x7f9943cb7b30; frame = (0 0; 1024 768); autoresize = W+H; layer = <CALayer: 0x7f9943cb8380>>
| | | | <UILayoutContainerView: 0x7f994412f9c0; frame = (0 0; 1024 768); autoresize = W+H; gestureRecognizers = <NSArray: 0x7f9943c67c30>; layer = <CALayer: 0x7f994412fba0>>
| | | | | <UINavigationTransitionView: 0x7f9943c606f0; frame = (0 0; 1024 768); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x7f9943c13890>>
| | | | | | <UIViewControllerWrapperView: 0x7f994426d090; frame = (0 0; 1024 768); autoresize = W+H; layer = <CALayer: 0x7f994426ce70>>
| | | | | | | <UIView: 0x7f994423db60; frame = (0 0; 1024 768); autoresize = W+H; layer = <CALayer: 0x7f994423dad0>>
| | | | | | | | <UICollectionView: 0x7f9944838000; frame = (0 0; 1024 768); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7f9944241220>; layer = <CALayer: 0x7f9944240a30>; contentOffset: {0, -64}> collection view layout: <UICollectionViewFlowLayout: 0x7f994423fca0>
... ...

(lldb) pviews --up
<UIWindow: 0x7f994423a3a0; frame = (0 0; 768 1024); autoresize = W+H; gestureRecognizers = <NSArray: 0x7f994423abc0>; layer = <UIWindowLayer: 0x7f9944239e90>>

(lldb) pviews --depth=5 0x7f9943d4ad60
<UITabBar: 0x7f9943d4ad60; frame = (0 712; 1024 56); autoresize = W+TM; layer = <CALayer: 0x7f9943d4b1a0>>
| <_UITabBarBackgroundView: 0x7f994423b920; frame = (0 0; 1024 56); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x7f994423bae0>>
| | <_UIBackdropView: 0x7f994423bb00; frame = (0 0; 1024 56); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <_UIBackdropViewLayer: 0x7f994423bdd0>>
| | | <_UIBackdropEffectView: 0x7f994423c320; frame = (0 0; 1024 56); clipsToBounds = YES; opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CABackdropLayer: 0x7f994423bac0>>
| | | <UIView: 0x7f994423c4f0; frame = (0 0; 1024 56); hidden = YES; opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x7f994423c5b0>>
| <UITabBarButton: 0x7f9943c8fd20; frame = (309 1; 76 55); opaque = NO; layer = <CALayer: 0x7f9943c923e0>>
| | <UITabBarSwappableImageView: 0x7f9943c92900; frame = (25.5 7; 25 25); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7f9943c92b70>>
| | <UITabBarButtonLabel: 0x7f9943c902f0; frame = (24 35; 28 17); text = '首页'; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7f9943c90590>>
| <UITabBarButton: 0x7f9943c9bf20; frame = (419 1; 76 55); opaque = NO; layer = <CALayer: 0x7f9943c9d520>>
| | <UITabBarSwappableImageView: 0x7f9943c9d910; frame = (25.5 8; 25 23); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7f9943c9d540>>
| | <UITabBarButtonLabel: 0x7f9943c9c0c0; frame = (24 35; 28 17); text = '课程'; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7f9943c9be40>>
| <UITabBarButton: 0x7f9943ca5450; frame = (529 1; 76 55); opaque = NO; layer = <CALayer: 0x7f9943ca6a50>>
| | <UITabBarSwappableImageView: 0x7f9943ca6d40; frame = (25.5 7; 25 25); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7f9943ca6a70>>
| | <UITabBarButtonLabel: 0x7f9943ca55f0; frame = (17 35; 42 17); text = '讨论区'; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7f9943ca5370>>
| <UITabBarButton: 0x7f9943caeaa0; frame = (639 1; 76 55); opaque = NO; layer = <CALayer: 0x7f9943cb0070>>
| | <UITabBarSwappableImageView: 0x7f9943cb0350; frame = (26 7.5; 24 24); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7f9943cb0090>>
| | <UITabBarButtonLabel: 0x7f9943caec40; frame = (31 35; 14 17); text = '我'; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7f9943cae9a0>>
| <UIImageView: 0x7f994423d490; frame = (0 -0.5; 1024 0.5); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x7f994423d590>>

刷新显示的原生命令:

(lldb) e (void)[CATransaction flush]

Chisel的简化版: caflush

Ref:

与调试器共舞 - LLDB 的华尔兹(objccn.io): http://objccn.io/issue-19-2/

LLDB使用篇(上): http://www.dreamingwish.com/article/lldb-usage-a.html

LLdb篇2教你使用faceBook的chisel来提高调试效率: http://www.jianshu.com/p/b2371dd4443b

http://swiftcafe.io/2015/09/05/lldb-debug/

原文  http://www.calios.gq/2016/01/19/LLDB常用命令/
正文到此结束
Loading...