Avatar
Swift Error Breakpoint使ってlldbでエラーの詳細を見られないかと試したけど、ダメぽい。 (edited)
10:30 AM
SILを見ると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)
10:30 AM
けど、ブレークポイントで$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) (SILと同じソースで試したログと差し替え) (シンボル入りtoolchainで試したログと差し替え) (edited)