|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Where are my core dump files? |
| 4 | +tags: |
| 5 | +- linux |
| 6 | +- ubuntu |
| 7 | +- debug |
| 8 | +published: true |
| 9 | +--- |
| 10 | + |
| 11 | +One day, on a Ubuntu 22.04 machine, I had to debug my application which segfaults with messages like: `corrupted double-linked list` or `free(): corrupted unsorted chunks`. |
| 12 | + |
| 13 | +I could see an error message: |
| 14 | + |
| 15 | +``` |
| 16 | +[1] 123456 abort (core dumped) my_faulty_application |
| 17 | +``` |
| 18 | + |
| 19 | +but could not find the corresponding core dump file anywhere. |
| 20 | + |
| 21 | +Where is it? |
| 22 | + |
| 23 | +---- |
| 24 | + |
| 25 | +## Ubuntu and core dumps |
| 26 | + |
| 27 | +After some googling, I could find some articles saying that core dumps are handled by Apport in Ubuntu, but they are not enabled in stable releases. |
| 28 | + |
| 29 | +There were a few solutions for this, and I chose to install `systemd-coredump`: |
| 30 | + |
| 31 | +{% highlight bash %} |
| 32 | +$ sudo apt-get install systemd-coredump |
| 33 | +{% endhighlight %} |
| 34 | + |
| 35 | +## Generating core dumps |
| 36 | + |
| 37 | +After installing systemd-coredump, and running my faulty application, it finally generated a core dump file. |
| 38 | + |
| 39 | +I could find it in `/var/lib/systemd/coredump/`: |
| 40 | + |
| 41 | +{% highlight bash %} |
| 42 | +$ ls /var/lib/systemd/coredump/ |
| 43 | + |
| 44 | +core.my_faulty_application.9999.abcdefghijklmnopqrstuvwxyz012345.123456.0000000000000000.zst |
| 45 | +{% endhighlight %} |
| 46 | + |
| 47 | +## Using the core dump file |
| 48 | + |
| 49 | +List the dumped files, |
| 50 | + |
| 51 | +{% highlight bash %} |
| 52 | +$ coredumpctl list |
| 53 | + |
| 54 | +TIME PID UID GID SIG COREFILE EXE SIZE |
| 55 | +Thu 2022-11-10 15:59:05 KST 123456 9999 9999 SIGABRT present /path/to/my_faulty_application 2.0M |
| 56 | +{% endhighlight %} |
| 57 | + |
| 58 | +dump desired one into the current directory, |
| 59 | + |
| 60 | +{% highlight bash %} |
| 61 | +$ coredumpctl dump 123456 --output ./coredump |
| 62 | +{% endhighlight %} |
| 63 | + |
| 64 | +and debug it with: |
| 65 | + |
| 66 | +{% highlight bash %} |
| 67 | +$ gdb /path/to/my_faulty_application ./coredump |
| 68 | +{% endhighlight %} |
| 69 | + |
| 70 | +or debug directly with coredumpctl: |
| 71 | + |
| 72 | +{% highlight bash %} |
| 73 | +$ coredumpctl debug 123456 |
| 74 | +{% endhighlight %} |
| 75 | + |
| 76 | +---- |
| 77 | + |
| 78 | +## Wrap-Up |
| 79 | + |
| 80 | +Some linux distributions don't enable core dumps due to security or storage issues. |
| 81 | + |
| 82 | +When needed, they can be enabled and help debugging things. |
| 83 | + |
0 commit comments