Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift debugging on Linux - Missing Backtrace

Tags:

linux

swift

I have a crash which I am trying to locate, and even building the application as debug and executing it I don't seem to get any symbolic information.

The output I receive at the console is:

fatal error: unexpectedly found nil while unwrapping an Optional value
Current stack trace:
0    libswiftCore.so                    0x00007f1c51ca51c0 swift_reportError + 120
1    libswiftCore.so                    0x00007f1c51cbfbe0 _swift_stdlib_reportFatalError + 62
2    libswiftCore.so                    0x00007f1c51ab9be6 <unavailable> + 1186790
3    libswiftCore.so                    0x00007f1c51c18ead <unavailable> + 2625197
4    libswiftCore.so                    0x00007f1c51ab9be6 <unavailable> + 1186790
5    libswiftCore.so                    0x00007f1c51bd4060 specialized _fatalErrorMessage(StaticString, StaticString, file : StaticString, line : UInt, flags : UInt32) -> Never + 96
6    myProgram                          0x000000000045909e <unavailable> + 364702
7    myProgram                          0x0000000000423f37 <unavailable> + 147255
8    libdispatch.so                     0x00007f1c5276e177 <unavailable> + 278903
9    libdispatch.so                     0x00007f1c52779edd <unavailable> + 327389
10   libdispatch.so                     0x00007f1c5277a890 <unavailable> + 329872
11   libdispatch.so                     0x00007f1c5277c5f4 <unavailable> + 337396
12   libdispatch.so                     0x00007f1c5279aa18 <unavailable> + 461336
13   libpthread.so.0                    0x00007f1c50c6f6ba <unavailable> + 30394
14   libc.so.6                          0x00007f1c4f7b9370 clone + 109
Illegal instruction (core dumped)

I simply cannot find any way to expand on this information, and although I could go looking through a map file. I feel that we have moved very much beyond that territory now with modern tooling.

Does anyone have any pointers, or indeed knows how to produce a build with more information in it.

Ubuntu 16.04, Swift 3.1.1

like image 949
Adrian_H Avatar asked Jul 06 '17 16:07

Adrian_H


1 Answers

So, sadly this seems to be a bug in lldb, which uses local symbols in ELF executables, and dladdr cannot find them on linux platforms.

See the bug report here: https://bugs.swift.org/browse/SR-755

ATTENTION:

Great news though, there is a bash script which does all the work for you. Instruction's are slight, but this is what you need to do:

Download this script: https://raw.githubusercontent.com/apple/swift/master/utils/symbolicate-linux-fatal

Exectute your crashing app.

$ myApp &> crash.log

Then execute the script.

$ ./symbolicate-linux-fatal myApp crash.log

It has helped me out no end.

Using LLDB

You can also use the swift debugger to help if still in the development stage.

Also if you execute lldb yourexecutable, then run. You will pause and able to fully debug your application.

like image 166
Adrian_H Avatar answered Sep 30 '22 07:09

Adrian_H