Blame


1 ddc03123 2020-03-28 op Let's say you're debugging something on linux. Let's say that thing
2 ddc03123 2020-03-28 op crashed. What do you do? I will open gdb, load the executable and the
3 ddc03123 2020-03-28 op core file and try to figure it out why the thing crashed.
4 ddc03123 2020-03-28 op
5 ddc03123 2020-03-28 op Well, it's exactly what happened. But there was no core file for
6 ddc03123 2020-03-28 op me. Poor me.
7 ddc03123 2020-03-28 op
8 ddc03123 2020-03-28 op The defaults on OpenBSD, if I recall correctly, are to generate a core
9 ddc03123 2020-03-28 op file named `$prgname.core` in the directory where the program was
10 ddc03123 2020-03-28 op running before the crash. Also, but mind that I might be wrong, the
11 ddc03123 2020-03-28 op default ulimit settings is `unlimited` for the core files.
12 ddc03123 2020-03-28 op
13 ddc03123 2020-03-28 op So, here's a quick description on *how to get that cores* on linux,
14 ddc03123 2020-03-28 op primarly aimed at myself:
15 ddc03123 2020-03-28 op
16 ddc03123 2020-03-28 op #### ulimit
17 ddc03123 2020-03-28 op
18 ddc03123 2020-03-28 op A `ulimit -c unlimited` is needed since the default may be 0. This can
19 ddc03123 2020-03-28 op cause big core dumps in the `$HOME` if something like firefox or chrome
20 ddc03123 2020-03-28 op chrashes, but I prefer to have it in `.profile` than to have to remember
21 ddc03123 2020-03-28 op to execute the command.
22 ddc03123 2020-03-28 op
23 ddc03123 2020-03-28 op #### pattern
24 ddc03123 2020-03-28 op
25 ddc03123 2020-03-28 op On systems with systemd there should be a systemd-*somethingsomething*
26 ddc03123 2020-03-28 op daemon and *somethingsomething*-ctl to manage 'em. I prefer have those
27 ddc03123 2020-03-28 op cores in the directory I'm in. Bonus points if they are called like
28 ddc03123 2020-03-28 op I'm used.
29 ddc03123 2020-03-28 op
30 a3ab6f61 2020-09-22 op ```sh
31 a3ab6f61 2020-09-22 op echo %e.core | sudo tee /proc/sys/kernel/core_pattern
32 a3ab6f61 2020-09-22 op ```
33 ddc03123 2020-03-28 op
34 ddc03123 2020-03-28 op `%e` is replaced with the program name.
35 ddc03123 2020-03-28 op
36 a3ab6f61 2020-09-22 op However, on my machine, the core files are called
37 a3ab6f61 2020-09-22 op `$prgname.core.$pid`. To disable the `.pid` at the end
38 ddc03123 2020-03-28 op
39 a3ab6f61 2020-09-22 op ```sh
40 a3ab6f61 2020-09-22 op echo 0 | sudo tee /proc/sys/kernel/core_uses_pid
41 a3ab6f61 2020-09-22 op ```
42 ddc03123 2020-03-28 op
43 a3ab6f61 2020-09-22 op And that's all!