One thought at a time, all the time

Find out which Python program did a core dump

This morning, while casually looking at my syslogs, I saw a big red stacktrace about a Python process. I got curious and wanted to look at which script crashed like that. However, the name of the faulty script was nowhere to be found in the trace.

09:48:24 kernel: python3[2550364]: segfault at 0 ip 00007fd9f65cb8d9 sp 00007fffc69143d0 error 4 in libgtk-3.so.0.2404.30[7fd9f65ad000+382000]
09:48:24 systemd-coredump[2563786]: [/] Process 2550364 (python3) of user 1000 dumped core.
                                    Module /home/romain/.local/lib/python3.10/site-packages/Pillow.libs/libXau-154567c4.so.6.0.0 without build-id.
                                    Module /home/romain/.local/lib/python3.10/site-packages/Pillow.libs/liblzma-96284f0d.so.5.2.5 without build-id.
                                    Module /home/romain/.local/lib/python3.10/site-packages/Pillow.libs/libtiff-f706b4a5.so.5.8.0 without build-id.
                                    Module /home/romain/.local/lib/python3.10/site-packages/Pillow.libs/libopenjp2-8fa4ced9.so.2.5.0 without build-id.
                                    Module /home/romain/.local/lib/python3.10/site-packages/Pillow.libs/libjpeg-a4c3d5e9.so.62.3.0 without build-id.
                                    [...]
                                    Stack trace of thread 2550400:
                                    #0  0x00007fd9f8e250bf __poll (libc.so.6 + 0xfb0bf)
                                    #1  0x00007fd9e8de08c7 n/a (libpulse.so.0 + 0x338c7)
                                    #2  0x00007fd9e8dca46c pa_mainloop_poll (libpulse.so.0 + 0x1d46c)
                                    #3  0x00007fd9e8dd442c pa_mainloop_iterate (libpulse.so.0 + 0x2742c)
                                    #4  0x00007fd9e8dd44e1 pa_mainloop_run (libpulse.so.0 + 0x274e1)
                                    #5  0x00007fd9e8de4c02 n/a (libpulse.so.0 + 0x37c02)
                                    #6  0x00007fd9e8d81c57 n/a (libpulsecommon-16.1.so + 0x5bc57)
                                    #7  0x00007fd9f8db08fd n/a (libc.so.6 + 0x868fd)
                                    #8  0x00007fd9f8e32a60 n/a (libc.so.6 + 0x108a60)
                                    ELF object binary architecture: AMD x86-64

To get an idea of what went wrong, I needed the script path and other args given to Python. Looking at the logs, we can see the PID of the crashed process: 2550364. As I just want the basic info, coredumpctl info <PID> is just fine. But if I needed to do a deep dive into the stacktrace, I could have used coredumpctl debug <PID> to open a debugger and trace the problem back to its origin.