假设我有一个小程序,涉及从数据库中选择一个文档:
let errorDatabase = NSError(domain: "dk.myproject.couchbase",code: 0,userInfo: nil) let rev = database.existingDocumentWithID("_design/" + designDocName) // in xcode I set a break point here assert(rev != nil) if rev == nil { promise.failure(errorDatabase) }
然后我插入一个断点,运行程序,之后可以执行:
(lldb) po rev 0x00007fad21df61c0 { ObjectiveC.NSObject = {...} } (lldb) print rev.properties["views"] (AnyObject?) $R29 = Some { ...
完美让我们进入repl并与rev对象一起玩:
(lldb) repl 6> rev repl.swift:6:1: error: use of unresolved identifier 'rev' rev ^
我可能对swift repl有错误的期望 – 我期待某种python,nodejs或scala repl.我可以玩物体等的行为
任何提示?
解决方法
第一次在LLDB中输入repl时,我希望同样的事情,但我很快发现,不幸的是你不能这样做.
事实证明,LLDB中的repl正在顶级注入的模块中运行.因此,您可以在此处的repl中定义顶级对象和函数,然后在“normal”lldb中可见:
(lldb) repl 1> func pt() -> CGPoint { 2. return CGPointZero 3. } 4> : (lldb) po pt() (0.0,0.0)
…但反过来却不是这样:你不能在repl中看到你被暂停时的局部变量,因为它们显然不在顶级范围内.
但请注意,您可以在expr表达式中执行赋值.因此,您可以更改局部变量的值,现有对象的属性等,只需说出expr后跟一个赋值 – 并且这确实发生在您暂停的上下文中.
例如,假设我正在创建一个平移边缘手势识别器,我在这一行的断点处暂停:
p.edges = UIRectEdge.Right
现在:
(lldb) th step-over (lldb) expr p.edges = UIRectEdge.Left (lldb) continue
现在应用程序正在运行,但是从左侧而不是右侧滑动时手势识别器正常工作.