(lldb) expr 1+1 Shared Swift state for Run could not be initialized. The REPL and expressions are unavailable.
expr
も list
も動きましたsettings set target.source-map <ターゲットパス> <ローカルパス>
をやったらlldb-server
上でプロセス起動/アタッチまではいけましたが、ブレークポイントが効きませんでした。error: <EXPR>:3:1: error: use of unresolved identifier 'hogehoge'
とかなって苦しんでたんですが、Address SanitizerをoffにするとなおることがわかりましたwillThrow
にErrorを渡してる。 // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): %2 = metatype $@thin MyError.Type // user: %4 // function_ref MyError.init() %3 = function_ref @main.MyError.init() -> main.MyError : $@convention(method) (@thin MyError.Type) -> @owned MyError // user: %4 %4 = apply %3(%2) : $@convention(method) (@thin MyError.Type) -> @owned MyError // user: %7 %5 = alloc_existential_box $Error, $MyError // users: %10, %8, %6 %6 = project_existential_box $MyError in %5 : $Error // user: %7 store %4 to %6 : $*MyError // id: %7 %8 = builtin "willThrow"(%5 : $Error) : $() br bb1 // id: %9 bb1: // Preds: bb0 %10 = builtin "errorInMain"(%5 : $Error) : $() unreachable // id: %11 } // end sil function 'main'
(edited)$arg2
を見ても0
になってる。 $ xcrun --toolchain org.swift.5020190117a swift swift_oss_helper command enabled. warning: (x86_64) /Library/Developer/Toolchains/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-01-17-a.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework/Resources/repl_swift empty dSYM file detected, dSYM was created with an executable with no debug info. Welcome to Apple Swift version 5.0-dev (LLVM a6b53a73a4, Clang 5fd77fa5bf, Swift 08e20c0d48). Type :help for assistance. 1> :br s -E swift Breakpoint 1: where = libswiftCore.dylib`swift_willThrow at ErrorObject.mm:569, address = 0x0000000101313d50 1> struct MyError: Error, CustomStringConvertible { 2. var description = "my error" 3. } 4. 5. throw MyError() Execution stopped at breakpoint. Enter LLDB commands to investigate (type help for assistance.) libswiftCore.dylib was compiled with optimization - stepping may behave oddly; variables may not be available. Process 68387 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #0: 0x0000000101313d50 libswiftCore.dylib`swift_willThrow(unused=0x0000000000000000, error=<unavailable>) at ErrorObject.mm:569 [opt] 566 /// Breakpoint hook for debuggers. 567 SWIFT_CC(swift) void 568 swift::swift_willThrow(SWIFT_CONTEXT void *unused, -> 569 SWIFT_ERROR_RESULT SwiftError **error) { 570 // empty 571 } 572 Target 0: (repl_swift) stopped. (lldb) p $arg1 (unsigned long) $0 = 4296026880 (lldb) p $arg2 (unsigned long) $1 = 0 (lldb)
willThrow
の実装をみると中身が無いので、オプティマイザがパラメータを省略してしまっているのかも。 https://github.com/apple/swift/blob/master/stdlib/public/runtime/ErrorObjectNative.cpp#L111-L114Error
を投げる場所のソースがあるならSwift Error Breakpointもいけるけど、ちゃんとcatch
するのが無難ぽい。