If you can reproduce it, and run it under lldb, it will print the source line 
for you:

$ lldb .build/debug/main
(lldb) target create ".build/debug/main"
ruCurrent executable set to '.build/debug/main' (x86_64).
(lldb) run
Process 19013 launched: '/private/tmp/main/.build/debug/main' (x86_64)
Hello, world!
fatal error: unexpectedly found nil while unwrapping an Optional value
2017-05-02 09:17:11.351608+0100 asdf[19013:54205130] fatal error: unexpectedly 
found nil while unwrapping an Optional value
Current stack trace:
0    libswiftCore.dylib                 0x00000001002c1160 swift_reportError + 
125
1    libswiftCore.dylib                 0x00000001002ddac0 
_swift_stdlib_reportFatalError + 60
2    libswiftCore.dylib                 0x00000001000ce260 specialized 
specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) 
-> A + 342
3    libswiftCore.dylib                 0x0000000100249120 partial apply for 
(_fatalErrorMessage(StaticString, StaticString, file : StaticString, line : 
UInt, flags : UInt32) -> Never).(closure #2) + 109
4    libswiftCore.dylib                 0x00000001000ce260 specialized 
specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) 
-> A + 342
5    libswiftCore.dylib                 0x00000001001fbd00 specialized 
_fatalErrorMessage(StaticString, StaticString, file : StaticString, line : 
UInt, flags : UInt32) -> Never + 96
6    main                               0x0000000100001340 say(message : 
String?) -> () + 248
7    main                               0x00000001000011e0 main + 328
8    libdyld.dylib                      0x00007fffb444d234 start + 1
Process 19013 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION 
(code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x00000001001fbd60 libswiftCore.dylib`function signature 
specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of 
Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, file : 
Swift.StaticString, line : Swift.UInt, flags : Swift.UInt32) -> Swift.Never + 96
libswiftCore.dylib`function signature specialization <preserving fragile 
attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage 
(Swift.StaticString, Swift.StaticString, file : Swift.StaticString, line : 
Swift.UInt, flags : Swift.UInt32) -> Swift.Never:
->  0x1001fbd60 <+96>: ud2    
    0x1001fbd62 <+98>: nopw   %cs:(%rax,%rax)

libswiftCore.dylib`protocol witness table accessor for <A> Swift.AnySequence<A> 
: Swift.Sequence in Swift:
    0x1001fbd70 <+0>:  pushq  %rbp
    0x1001fbd71 <+1>:  movq   %rsp, %rbp

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION 
(code=EXC_I386_INVOP, subcode=0x0)
  * frame #0: 0x00000001001fbd60 libswiftCore.dylib`function signature 
specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of 
Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, file : 
Swift.StaticString, line : Swift.UInt, flags : Swift.UInt32) -> Swift.Never + 96
    frame #1: 0x0000000100001438 main`say(message=nil) -> () at main.swift:5
    frame #2: 0x0000000100001328 main`main at main.swift:8
    frame #3: 0x00007fffb444d235 libdyld.dylib`start + 1
    frame #4: 0x00007fffb444d235 libdyld.dylib`start + 1

There is a symbolication tool available for Linux in the 
~/swift/utils/symbolicate-linux-fatal, and Xcode can do the same symbolication 
for you as well.

Alex

> On 28 Apr 2017, at 22:28, Nick Snyder via swift-users <swift-users@swift.org> 
> wrote:
> 
> I have a simple main.swift that looks like this:
> 
> ```
> print("Hello, world!")
> let x: String? = nil
> 
> func say(message: String?) {
>     print(x!) // intentional crash
> }
> 
> say(message: x)
> ```
> 
> Running this results in the crash
> 
> ```
> $ swift build && ./.build/debug/hello
> Hello, world!
> fatal error: unexpectedly found nil while unwrapping an Optional value
> Current stack trace:
> 0    libswiftCore.dylib                 0x0000000110120130 swift_reportError 
> + 129
> 1    libswiftCore.dylib                 0x000000011013cb50 
> _swift_stdlib_reportFatalError + 60
> 2    libswiftCore.dylib                 0x000000010ff2d250 specialized 
> specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> 
> A) -> A + 342
> 3    libswiftCore.dylib                 0x00000001100a7e90 partial apply for 
> (_fatalErrorMessage(StaticString, StaticString, file : StaticString, line : 
> UInt, flags : UInt32) -> Never).(closure #2) + 109
> 4    libswiftCore.dylib                 0x000000010ff2d250 specialized 
> specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> 
> A) -> A + 342
> 5    libswiftCore.dylib                 0x000000011005a9a0 specialized 
> _fatalErrorMessage(StaticString, StaticString, file : StaticString, line : 
> UInt, flags : UInt32) -> Never + 96
> 6    hello                              0x000000010fee6200 main + 345
> 7    libdyld.dylib                      0x00007fffe0375234 start + 1
> Illegal instruction: 4
> ```
> 
> From the crash, how do I map back line 6 to an actual line in main.swift?
> _______________________________________________
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to