How to Get a Core Dump for a Segfault on Linux

38

This week at work I spent all week trying to debug a segfault. I’d never done this before, and some of the basic things involved (get a core dump! find the line number that segfaulted!) took me a long time to figure out. So here’s a blog post explaining how to do those things!

At the end of this blog post, you should know how to go from “oh no my program is segfaulting and I have no idea what is happening” to “well I know what its stack / line number was when it segfaulted at at least!“.

what’s a segfault?

A “segmentation fault” is when your program tries to access memory that it’s not allowed to access, or tries to. This can be caused by:

  • trying to dereference a null pointer (you’re not allowed to access the memory address 0)
  • trying to dereference some other pointer that isn’t in your memory

Read more at Julia Evans