摘要
如何在调试中高级运用调试方法,减少重新运行
LLDB获取帮助
调用help命令来列出LLDB所有的顶层命令
LLDB高级运用
(lldb) e int $a = 2
(lldb) p $a * 19
38
(lldb) e NSArray *$array = @[ @"Saturday", @"Sunday", @"Monday" ]
(lldb) p [$array count]
3
(lldb) po [[$array objectAtIndex:0] uppercaseString]
SATURDAY
(lldb) p [[$array objectAtIndex:$a] characterAtIndex:0]
error: no known method '-characterAtIndex:'; cast the message send to the method's return type
error: 1 errors parsing expression
//lldb无法判定某一步的计算结果是什么数据类型
(lldb) p (char)[[$array objectAtIndex:$a] characterAtIndex:0]
'M'
(lldb) p/d (char)[[$array objectAtIndex:$a] characterAtIndex:0]
77
(lldb) thread step-in // The same as "step" or "s" in GDB.
(lldb) thread step-over // The same as "next" or "n" in GDB.
(lldb) thread step-out // The same as "finish" or "f" in GDB.
(lldb) thread step-inst // The same as "stepi" / "si" in GDB.
(lldb) thread step-over-inst // The same as "nexti" / "ni" in GDB.
(lldb) thread list
(lldb) thread backtrace
(lldb) thread backtrace all //查看调用栈状态
(lldb) thread return //命令需要一个参数来指明函数强制返回时的返回值。
//检查帧参数和本地变量的最简便的方式是使用frame variable命令
(lldb) frame variable
self = (SKTGraphicView *) 0x0000000100208b40
_cmd = (struct objc_selector *) 0x000000010001bae1
sender = (id) 0x00000001001264e0
selection = (NSArray *) 0x00000001001264e0
i = (NSUInteger) 0x00000001001264e0
c = (NSUInteger) 0x00000001001253b0
(lldb) frame variable self
(SKTGraphicView *) self = 0x0000000100208b40
(lldb) frame variable *self
(SKTGraphicView *) self = 0x0000000100208b40
(NSView) NSView = {
(NSResponder) NSResponder = {
...
(lldb) frame select 9
frame #9: 0x0000000100015ae3
//查看工程中使用的库
lldb) image list
[ 0] 432A6EBF-B9D2-3850-BCB2-821B9E62B1E0 0x0000000100000000 /Users/**/Library/Developer/Xcode/
(lldb) image lookup --address 0x0000000100000de0//具体哪一行
(lldb) image lookup --type NSURL //如果想查看具体类型
自定义执行
执行任意代码
(lldb) e char *$str = (char *)malloc(128)
(lldb) e (void)strcpy($str,"wxrld of warcraft")(lldb) e $str[1] ='o'(char) $0 ='o'
(lldb) p $str(char *) $str =0x00007fd04a900040"world of warcraft"(lldb) e (void)free($str)在debugger中可以修改view的颜色、尺寸、甚至创建controller来push。
打印cgframe
(lldb) po self.view.frameerror: unsupported expressionwithunknowntypeerror: unsupported expressionwithunknowntypeerror:2errors parsing expression
(lldb) p (CGRect)[self.view frame](CGRect) $0= origin=(x=0, y=0) size=(width=320, height=480)
观察watchpoint
watchpoint可以在某个变量被写入/读取时暂停程序运行
(lldb) watchpointsetexpression-- (int*)&_abc4Watchpoint created: Watchpoint7: addr =0x15e36d3csize=4state = enabledtype= wnewvalue:0x00000000(lldb) watchpointsetv -wread_abc4Watchpoint created: Watchpoint8: addr =0x15e36d3csize=4state = enabledtype= r watchpoint spec ='_abc4'newvalue:0(lldb) watchpointsetv -w read_write _abc3Watchpoint created: Watchpoint9: addr =0x15e36d38size=4state = enabledtype= rw watchpoint spec ='_abc3'newvalue:0
刷新UI
(lldb) po [[[UIApplication sharedApplication] keyWindow] recursiveDescription]|(lldb) e id $myView = (id)0x7f82b1d01fd0(lldb) e (void)[$myView setBackgroundColor:[UIColor blueColor]](lldb) e (void)[CATransaction flush]//必须加(lldb) e id $nvc = [[[UIApplication sharedApplication] keyWindow] rootViewController](lldb) e id $vc = [UIViewController new](lldb) e (void)[[$vc view] setBackgroundColor:[UIColor yellowColor]](lldb) e (void)[$vc setTitle:@"Yay!"](lldb) e (void)[$nvc pushViewContoller:$vc animated:YES](lldb) e (void)[CATransaction flush]
查找按钮的 target
(lldb) po [$myButtonallTargets]{( )}
(lldb) po [$myButtonactionsForTarget:(id)0x7fb58bd2e240forControlEvent:0](_handleTap:)
网友评论