IOS开发常用的调试命令

来源:互联网 发布:hex editor mac 编辑:程序博客网 时间:2024/05/22 05:03
XCode4.0以后,编译器是LLVM,控制台调试命令前缀是lldb
 
第一、LLVM简介
LLVM是构架编译器(compiler)的框架系统,以C++编写而成,用于优化以任意程序语言编写的程序的编译时间(compile-time)、链接时间(link-time)、运行时间(run-time)以及空闲时间(idle-time),对开发者保持开放,并兼容已有脚本。
第二、 对关注编译技术的开发人员,LLVM提供了很多优点:

现代化的设计
LLVM的设计是高度模块化的,使得其代码更为清晰和便于排查问题所在。
语言无关的中间代码
一方面,这使得透过LLVM能够将不同的语言相互连结起来;也使得LLVM能够紧密地与IDE交互和集成。
另一方面,发布中间代码而非目标代码能够在目标系统上更好地发挥其潜能而又不伤害可调试性(i.e. 在目标系统上针对本机的硬件环境产生目标代码,但又能够直接通过中间代码来进行行级调试)
作为工具和函数库
使用LLVM提供的工具可以比较容易地实现新的编程语言的优化编译器或VM,或为现有的编程语言引入一些更好的优化/调试特性。
第三、使用前提:
1.既然是调试命令,理所当然的,程序模式应该选择Debug模式。
2.在Debug模式下,如果你的程序在运行中崩溃(Crash)掉,那么恭喜你,使用lldb调试的机会来了。
符合以上两个条件之后,控制台(即日志输出窗口All Output)会自动打出一个(lldb)命令,此时你就可以进行调试。
第四、常用的调试命令
po
po是print-object的简写,可用来打印所有NSObject对象。sample code:
 
(lldb) po self.view
 
<UITableView: 0xdb00200; frame = (0 20; 320 460); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x8b3ca50>; layer = <CALayer: 0x8b3c110>; contentOffset: {0, 0}>
 
(lldb) po self
 
<RootViewController: 0x9813e90>
 
p
p是print的简写,可以用来打印所有的简单类型,如int, float,结构体等。sample code:
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
ItemData item; 
        item.nMainID=1; 
        item.nSubID=2; 
        item.pszTitle=@"hello"
       
        NSRect rect=NSMakeRect(0, 10, 10, 10); 
   调试命令及输出结果:
(lldb)print rect
 
(NSRect) $0 = (x=0, y=10), (width=10, height=10)
 
(lldb) p item
 
(ItemData) $3 = {
 
  pszTitle = 0x0000000100001370 @"hello"
 
  nMainID = 1
 
  nSubID = 2
 
}

 

 
 
call
call即是调用的意思。其实上述的po和p也有调用的功能。因此一般只在不需要显示输出,或是方法无返回值时使用call
 
bt
 
这时Xcode会自动输出最后的一次调用堆栈
 
(lldb) bt
 

(lldb) bt

* thread #1: tid = 0x172ec, 0x0303edd0 libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 23.1

    frame #0: 0x0303edd0 libobjc.A.dylib`objc_exception_throw

    frame #1: 0x035809ad CoreFoundation`+[NSException raise:format:] + 141

    frame #2: 0x010ae0f5 UIKit`-[UITableViewController loadView] + 552

    frame #3: 0x00e1c0d8 UIKit`-[UIViewController loadViewIfRequired] + 154

    frame #4: 0x00e1c9c5 UIKit`-[UIViewController view] + 35

    frame #5: 0x010adb0f UIKit`-[UITableViewController tableView] + 36

    frame #6: 0x010aeaba UIKit`-[UITableViewController _viewControllerWasSelected] + 36

    frame #7: 0x00e623d7 UIKit`-[UINavigationController _viewControllerWasSelected] + 64

    frame #8: 0x00e7f50c UIKit`-[UITabBarController viewDidAppear:] + 169

    frame #9: 0x00e22582 UIKit`-[UIViewController _setViewAppearState:isAnimating:] + 774

    frame #10: 0x00e22d01 UIKit`-[UIViewController __viewDidAppear:] + 166

    frame #11: 0x00e22fda UIKit`-[UIViewController _endAppearanceTransition:] + 280

    frame #12: 0x00e642d8 UIKit`-[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 1340

    frame #13: 0x01155a72 UIKit`-[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 458

    frame #14: 0x01155e26 UIKit`-[UINavigationTransitionView _cleanupTransition] + 843

    frame #15: 0x01155e8e UIKit`-[UINavigationTransitionView _navigationTransitionDidStop] + 55

    frame #16: 0x00cea9af UIKit`-[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 247

    frame #17: 0x00ce72e2 UIKit`+[UIViewAnimationState popAnimationState] + 350

    frame #18: 0x00d0cd62 UIKit`+[UIView(Animation) commitAnimations] + 36

    frame #19: 0x011557b2 UIKit`-[UINavigationTransitionView transition:fromView:toView:] + 2909

    frame #20: 0x01154c4c UIKit`-[UINavigationTransitionView transition:toView:] + 56

    frame #21: 0x00e69722 UIKit`-[UINavigationController _startTransition:fromViewController:toViewController:] + 3791

    frame #22: 0x00e69ce0 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 1038

    frame #23: 0x00e6ae3b UIKit`-[UINavigationController __viewWillLayoutSubviews] + 68

    frame #24: 0x01046193 UIKit`-[UILayoutContainerView layoutSubviews] + 252

    frame #25: 0x00d1beb7 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 813

    frame #26: 0x03053059 libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70

    frame #27: 0x02af580a QuartzCore`-[CALayer layoutSublayers] + 144

    frame #28: 0x02ae94ee QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 388

    frame #29: 0x02ae9352 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 26

    frame #30: 0x02adbe8b QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 317

    frame #31: 0x02b0fe03 QuartzCore`CA::Transaction::commit() + 561

    frame #32: 0x02b106c4 QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92

    frame #33: 0x0349a61e CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30

    frame #34: 0x0349a57e CoreFoundation`__CFRunLoopDoObservers + 398

    frame #35: 0x0348fefc CoreFoundation`__CFRunLoopRun + 1340

    frame #36: 0x0348f706 CoreFoundation`CFRunLoopRunSpecific + 470

    frame #37: 0x0348f51b CoreFoundation`CFRunLoopRunInMode + 123

    frame #38: 0x044cb664 GraphicsServices`GSEventRunModal + 192

    frame #39: 0x044cb4a1 GraphicsServices`GSEventRun + 104

    frame #40: 0x00c521eb UIKit`UIApplicationMain + 160

  * frame #41: 0x0027b4ca EzPlug`main(argc=1, argv=0xbffbc8d0) + 138 at main.m:16

    frame #42: 0x03b9ca21 libdyld.dylib`start + 1

 
0 0
原创粉丝点击