[swift-users] How to debug Segmentation Fault

Jens Alfke jens at mooseyard.com
Wed Feb 1 19:25:07 CST 2017


> On Feb 1, 2017, at 5:00 PM, Maxim Veksler via swift-users <swift-users at swift.org> wrote:
> 
> My method, though effective is probably barbaric. It's been years since I've touched code that can actually seg fault, and I'm rusty on how you approach debugging such cases, I'm wondering both Mac and Linux, even though my case is Linux only.

You run the program in a debugger, probably gdb if this is Linux. Just run "gdb /path/to/binary”. Then at the “(gdb)” prompt enter “run”. (You can type command-line arguments after “run" and they’ll be passed to your program.) If the process segfaults or otherwise crashes, gdb takes over and prints another prompt. Now you can start debugging. The usual first thing I do is enter “bt” which will dump the stack. That itself should produce enough output to submit a bug report. There are lots of docs and tutorials for gdb online if you want to learn more.

gdb is no longer used on Mac (we have lldb instead), so further discussion of it would be off-topic here :)

Another possibility, instead of gdb, is getting the OS to produce a crash report when the process terminates. On Mac this is enabled by default, but maybe you need to toggle some setting on Linux to get similar behavior.

—Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170201/60c71397/attachment.html>


More information about the swift-users mailing list