- p & po
po广泛用于OC和Swift的调试中用于输出变量、对象的值、地址或者description信息。
po -- Evaluate an expression on the current thread. Displays any
returned value with formatting controlled by the type's author.
在MasterViewController.swift中添加断点并重写description方法
override var description: String {
return "Yay! debugging " + super.description
}
// override var debugDescription: String {
// return "debugDescription: " + super.debugDescription
// }
MasterViewController
(lldb) po self
// 相当于调用了 description方法
Yay! debugging <Signals.MasterViewController: 0x7feae9e13140>
如果打开上文中debugDescription的注释这po self调的是debugDescription。
可以看出po在默认情况下是调用实例对象的description方法的,在重写了debugDescription的时候才调用debugDescription。通过image lookup命令可以查看哪些模块是重写的debugDescription的
(lldb) image lookup -rn '\ debugDescription\]'
24 matches found in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework/Foundation:
Address: Foundation[0x0000000000007130] (Foundation.__TEXT.__text + 23312)
Summary: Foundation`-[NSAffineTransform debugDescription] Address: Foundation[0x000000000000b57e] (Foundation.__TEXT.__text + 40798)
Summary: Foundation`-[NSArray(NSArray) debugDescription] Address: Foundation[0x0000000000010861] (Foundation.__TEXT.__text + 62017)
Summary: Foundation`+[NSBundle debugDescription] Address: Foundation[0x00000000000202cd] (Foundation.__TEXT.__text + 126125)
...
(lldb) po self.view!.layer.description
"<CALayer: 0x6000005af740>"
(lldb) po self.view!.layer
<CALayer:0x6000005af740; position = CGPoint (187.5 333.5); bounds = CGRect (0 0; 375 667); delegate = <UITableView: 0x7f8165060600; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600000bb9d70>; layer = <CALayer: 0x6000005af740>;
contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 0, 0}>; sublayers = (<CALayer: 0x6000005a9980>, <CALayer: 0x6000005afc00>); masksToBounds = YES; allowsGroupOpacity = YES; backgroundColor = <CGColor 0x6000021e0c60>
[<CGColorSpace 0x6000021eb180> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] ( 0.980392 0.980392 0.980392 1 ); _uikit_viewPointer = <UITableView: 0x7f8165060600; frame = (0 0; 375 667); clipsToBounds = YES;
autoresize = W+H; gestureRecognizers = <NSArray: 0x600000bb9d70>; layer = <CALayer: 0x6000005af740>; contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 0, 0}>>
可以看出在不同的类中用po 或者直接调用description输出的信息是不一样的。
p -- Evaluate an expression on the current thread. Displays any
returned value with LLDB's default formatting.
在同样的断点出 p self
(lldb) p self
(Signals.MasterViewController) $R16 = 0x00007f8164d14f00 {
UIKit.UITableViewController = {
baseUIViewController@0 = <extracting data from value failed>
_tableViewStyle = 0
_keyboardSupport = nil
_staticDataSource = nil
_filteredDataSource = 0x0000600000bbc330
_filteredDataType = 0
}
detailViewController = nil
}
在Swfit项目中采用OC语法会报错,可以通过expression 命令告诉lldb采用OC的语法
(lldb)expression -l objc -O -- [UIApplication sharedApplication]
网友评论