Step by step guide

Compile following code.

#include <stdio.h>

int main() {
    int* ptr = NULL;
    *ptr = 10;
    return 0;
}
$ gcc -g -o cd_test core_dump_test.c
$ ll
total 32
drwxr-xr-x  8 josh josh  4096 Aug 25 14:39 ./
drwxr-xr-x  9 josh josh  4096 Aug 25 14:16 ../
-rwxr-xr-x  1 josh josh 16912 Aug 25 14:39 cd_test*
-rwxrwxrwx  1 josh josh    84 Aug 25 14:38 core_dump_test.c*

Run the binary and check the SegFault.

$ ./cd_test
Segmentation fault
$ ll
total 32
drwxr-xr-x  8 josh josh  4096 Aug 25 14:39 ./
drwxr-xr-x  9 josh josh  4096 Aug 25 14:16 ../
-rwxr-xr-x  1 josh josh 16912 Aug 25 14:39 cd_test*
-rwxrwxrwx  1 josh josh    84 Aug 25 14:38 core_dump_test.c*

Make the file size of the core unlimited.

$ ulimit -a
real-time non-blocking time  (microseconds, -R) unlimited
core file size              (blocks, -c) 0
data seg size               (kbytes, -d) unlimited
scheduling priority                 (-e) 0
file size                   (blocks, -f) unlimited
pending signals                     (-i) 31178
max locked memory           (kbytes, -l) 64
max memory size             (kbytes, -m) unlimited
open files                          (-n) 1048576
pipe size                (512 bytes, -p) 8
POSIX message queues         (bytes, -q) 819200
real-time priority                  (-r) 0
stack size                  (kbytes, -s) 8192
cpu time                   (seconds, -t) unlimited
max user processes                  (-u) 31178
virtual memory              (kbytes, -v) unlimited
file locks                          (-x) unlimited
$ ulimit -c unlimited
$ ulimit -a
real-time non-blocking time  (microseconds, -R) unlimited
core file size              (blocks, -c) unlimited
data seg size               (kbytes, -d) unlimited
scheduling priority                 (-e) 0
file size                   (blocks, -f) unlimited
pending signals                     (-i) 31178
max locked memory           (kbytes, -l) 64
max memory size             (kbytes, -m) unlimited
open files                          (-n) 1048576
pipe size                (512 bytes, -p) 8
POSIX message queues         (bytes, -q) 819200
real-time priority                  (-r) 0
stack size                  (kbytes, -s) 8192
cpu time                   (seconds, -t) unlimited
max user processes                  (-u) 31178
virtual memory              (kbytes, -v) unlimited
file locks                          (-x) unlimited

Run again and check the message with the core dump file.

$ ./cd_test 
Segmentation fault (core dumped)
$ ll
total 148
drwxr-xr-x 2 josh josh   4096 Aug 25 14:44 ./
drwxr-xr-x 9 josh josh   4096 Aug 25 14:41 ../
-rwxr-xr-x 1 josh josh  16912 Aug 25 14:39 cd_test*
-rw------- 1 josh josh 294912 Aug 25 14:44 core
-rwxrwxrwx 1 josh josh     84 Aug 25 14:38 core_dump_test.c*

Debug with the core dump using GDB

$ gdb cd_test core
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
--Type <RET> for more, q to quit, c to continue without paging--
Reading symbols from cd_test...
[New LWP 10011]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./cd_test'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000562ee5dec13d in main () at core_dump_test.c:5
5           *ptr = 10;
(gdb) 

Simple GDB commands

(gdb) print ptr
$1 = (int *) 0x0
(gdb) info locals
ptr = 0x0
(gdb) info args 
No arguments.
(gdb) info reg
rax            0x0                 0
rbx            0x0                 0
rcx            0x562ee5deedf8      94759425076728
rdx            0x7ffc889cb388      140722600457096
rsi            0x7ffc889cb378      140722600457080
rdi            0x1                 1
rbp            0x7ffc889cb260      0x7ffc889cb260
rsp            0x7ffc889cb260      0x7ffc889cb260
r8             0x7f8068441f10      140189481836304
r9             0x7f806845c040      140189481943104
r10            0x7f8068456908      140189481920776
r11            0x7f8068471680      140189482030720
r12            0x7ffc889cb378      140722600457080
r13            0x562ee5dec129      94759425065257
r14            0x562ee5deedf8      94759425076728
r15            0x7f8068490040      140189482156096
rip            0x562ee5dec13d      0x562ee5dec13d <main+20>
eflags         0x10246             [ PF ZF IF RF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0
(gdb) backtrace
#0  0x0000562ee5dec13d in main () at core_dump_test.c:5
(gdb) disas main 
Dump of assembler code for function main:
   0x0000562ee5dec129 <+0>:     endbr64 
   0x0000562ee5dec12d <+4>:     push   %rbp
   0x0000562ee5dec12e <+5>:     mov    %rsp,%rbp
   0x0000562ee5dec131 <+8>:     movq   $0x0,-0x8(%rbp)
   0x0000562ee5dec139 <+16>:    mov    -0x8(%rbp),%rax
=> 0x0000562ee5dec13d <+20>:    movl   $0xa,(%rax)
   0x0000562ee5dec143 <+26>:    mov    $0x0,%eax
   0x0000562ee5dec148 <+31>:    pop    %rbp
   0x0000562ee5dec149 <+32>:    ret    
End of assembler dump.
(gdb) i proc m
Mapped address spaces:

          Start Addr           End Addr       Size     Offset objfile
      0x562ee5deb000     0x562ee5dec000     0x1000        0x0 /home/josh/workspace/Workspace/Sandbox/CoreDump/cd_test
      0x562ee5dec000     0x562ee5ded000     0x1000     0x1000 /home/josh/workspace/Workspace/Sandbox/CoreDump/cd_test
      0x562ee5ded000     0x562ee5dee000     0x1000     0x2000 /home/josh/workspace/Workspace/Sandbox/CoreDump/cd_test
      0x562ee5dee000     0x562ee5def000     0x1000     0x2000 /home/josh/workspace/Workspace/Sandbox/CoreDump/cd_test
      0x562ee5def000     0x562ee5df0000     0x1000     0x3000 /home/josh/workspace/Workspace/Sandbox/CoreDump/cd_test
      0x7f8068227000     0x7f806824f000    0x28000        0x0 /usr/lib/x86_64-linux-gnu/libc.so.6
      0x7f806824f000     0x7f80683e4000   0x195000    0x28000 /usr/lib/x86_64-linux-gnu/libc.so.6
      0x7f80683e4000     0x7f806843c000    0x58000   0x1bd000 /usr/lib/x86_64-linux-gnu/libc.so.6
      0x7f806843c000     0x7f8068440000     0x4000   0x214000 /usr/lib/x86_64-linux-gnu/libc.so.6
      0x7f8068440000     0x7f8068442000     0x2000   0x218000 /usr/lib/x86_64-linux-gnu/libc.so.6
      0x7f8068456000     0x7f8068458000     0x2000        0x0 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
      0x7f8068458000     0x7f8068482000    0x2a000     0x2000 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
      0x7f8068482000     0x7f806848d000     0xb000    0x2c000 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
      0x7f806848e000     0x7f8068490000     0x2000    0x37000 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
      0x7f8068490000     0x7f8068492000     0x2000    0x39000 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2