-This chapter should give you an introduction how to obtain a crash dump after a kernel panic and how to extract useful information for the developers out of the dump.\r

-\r

+# Debug the DragonFly kernel

+

+

+

+This chapter should give you an introduction how to obtain a crash dump after a kernel panic and how to extract useful information for the developers out of the dump.

+

+

+

[[!toc levels=3 ]]

-*** Contributed by Matthias Schmidt***\r

-\r

-## Configure your system \r

-Normally a crash dump is saved in your swap partition after a crash. If you reboot your machine the next time the dump is extracted by [savecore(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#savecore&section8) from the partition and stored into `/var/crash`. Due to the fact that `/var` is a relatively small partition it could be possible that the dump isn't saved, because the dump size is larger than the remaining size.\r

-\r

-To circumvent this problem you can change the default settings in `/etc/rc.conf`:\r

-\r

+***Contributed by Matthias Schmidt***

+

+

+

+## Configure your system

+

+Normally a crash dump is saved in your swap partition after a crash. If you reboot your machine the next time the dump is extracted by [savecore(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#savecore&section8) from the partition and stored into `/var/crash`. Due to the fact that `/var` is a relatively small partition it could be possible that the dump isn't saved, because the dump size is larger than the remaining size.

+

+

+

+To circumvent this problem you can change the default settings in `/etc/rc.conf`:

+

+

+

[[!table data="""

| `dumpdev` | Indicates the device (usually a swap partition) to which a crash dump should be written in the event of a system crash.

- `dumpdir` | savecore(8) will save that crash dump and a copy of the kernel to the directory specified by the dumpdir variable. The default value is /var/crash. You can set this to another directory on another partition with more space available to safely obtain the dump. |\r

-"""]]\r

-If you are unsure about your swap partition device, use [swapinfo(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#swapinfo&section8) or look into `/etc/fstab` :\r

- \r

- # swapinfo \r

- Device 1K-blocks Used Avail Capacity Type\r

- /dev/ad0s1b 1048448 0 1048448 0% Interleaved\r

- \r

- # cat /etc/fstab | grep swap\r

- /dev/ad0s1b none swap sw 0 0\r

-\r

-\r

-### Enable debugging options in your kernel config \r

-\r

-If you don't know how to configure a custom kernel, look into [Configuring the DragonFly Kernel](kernelconfig.html). You have to add the following lines to compile your kernel with debugging symbols:\r

- \r

- makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols\r

-\r

-If you want additional support for the interactive kernel debugger [ddb(4)](http://leaf.dragonflybsd.org/cgi/web-man?command#ddb&section4) and invariant debugging, also add these lines:\r

-Before your machine reboots a crash dump is saved into your swap partition (if you have one and don't disabled crash dumps). Writing the dump to disk takes some time depending on your machine and the amount of RAM installed. This might look like this:\r

-Now your machine reboots, checks its file system and finally extracts the crash dump from the swap partition to your `dumpdir` (see `rc.conf` setting above). If your `/var` partition is to small, you'll see an error similar to the following:\r

-If this happens, you have to extract the crash dump yourselves. See next Section how to do this.\r

-### Extract a crash dump manually \r

-You can use [savecore(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#savecore&section8) to copy your currently running kernel and the associated crash dump to a particular directory you have to specify (we use `/usr/crash` here in the example):\r

- \r

- # mkdir -p /usr/crash\r

- # chmod 700 /usr/crash\r

- # savecore /usr/crash/\r

- [...]\r

-\r

-This will take some time dependent on the speed of your machine. See the man page of savecore(8) for more available options.\r

-### Upload the crash dump \r

-If you don't have the ability or skills to debug are crash yourselves, please upload the complete content of your crash directory to a public available location (HTTP, FTP web space or your leaf account) and send a detailed bug report to the bugs@dragonflybsd.org list. If its possible please tar and compress (gzip, bzip2) the directory to save disk space and bandwith.\r

-\r

-## Debug the crash dump with kgdb \r

-The [kgdb(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#kgdb&section1) utility is a debugger based on gdb(1) that allows debugging of kernel core files.\r

-### kgdb extesions \r

-To get some handy helper command execute the following command before starting kgdb:\r

- \r

- source /usr/src/test/debug/gdb.kernel\r

-\r

-This gives you several new commands like kldstat (displays all loaded modules) or psx (displays all running processes).\r

-Start kgdb as follows:\r

- \r

- # cd /usr/crash\r

- # ls -l\r

- -rw-r--r-- 1 root wheel 2B Jan 7 17:07 bounds\r

- -rw-r--r-- 1 root wheel 17M Jan 7 17:08 kernel.0\r

- -rw------- 1 root wheel 512M Jan 7 17:08 vmcore.0\r

- # kgdb kernel.0 vmcore.0\r

-\r

-kgdb(1) will show you the panic message after start. The first thing to do is to obtain a ***backtrace*** with the ***bt*** command:\r

+ `dumpdir` | savecore(8) will save that crash dump and a copy of the kernel to the directory specified by the dumpdir variable. The default value is /var/crash. You can set this to another directory on another partition with more space available to safely obtain the dump. |

+

+"""]]

+

+If you are unsure about your swap partition device, use [swapinfo(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#swapinfo&section8) or look into `/etc/fstab` :

+

+

+

+ # swapinfo

+

+ Device 1K-blocks Used Avail Capacity Type

+

+ /dev/ad0s1b 1048448 0 1048448 0% Interleaved

+

+

+

+ # cat /etc/fstab | grep swap

+

+ /dev/ad0s1b none swap sw 0 0

+

+

+

+

+

+### Enable debugging options in your kernel config

+

+

+

+If you don't know how to configure a custom kernel, look into [Configuring the DragonFly Kernel](kernelconfig.html). You have to add the following lines to compile your kernel with debugging symbols:

+

+

+

+ makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols

+

+

+

+If you want additional support for the interactive kernel debugger [ddb(4)](http://leaf.dragonflybsd.org/cgi/web-man?command#ddb&section4) and invariant debugging, also add these lines:

+Before your machine reboots a crash dump is saved into your swap partition (if you have one and don't disabled crash dumps). Writing the dump to disk takes some time depending on your machine and the amount of RAM installed. This might look like this:

+Now your machine reboots, checks its file system and finally extracts the crash dump from the swap partition to your `dumpdir` (see `rc.conf` setting above). If your `/var` partition is to small, you'll see an error similar to the following:

+If this happens, you have to extract the crash dump yourselves. See next Section how to do this.

+

+### Extract a crash dump manually

+

+You can use [savecore(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#savecore&section8) to copy your currently running kernel and the associated crash dump to a particular directory you have to specify (we use `/usr/crash` here in the example):

+

+

+

+ # mkdir -p /usr/crash

+

+ # chmod 700 /usr/crash

+

+ # savecore /usr/crash/

+

+ [...]

+

+

+

+This will take some time dependent on the speed of your machine. See the man page of savecore(8) for more available options.

+

+### Upload the crash dump

+

+If you don't have the ability or skills to debug are crash yourselves, please upload the complete content of your crash directory to a public available location (HTTP, FTP web space or your leaf account) and send a detailed bug report to the bugs@dragonflybsd.org list. If its possible please tar and compress (gzip, bzip2) the directory to save disk space and bandwith.

+

+

+

+## Debug the crash dump with kgdb

+

+The [kgdb(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#kgdb&section1) utility is a debugger based on gdb(1) that allows debugging of kernel core files.

+

+### kgdb extesions

+

+To get some handy helper command execute the following command before starting kgdb:

+

+

+

+ source /usr/src/test/debug/gdb.kernel

+

+

+

+This gives you several new commands like kldstat (displays all loaded modules) or psx (displays all running processes).

+

+Start kgdb as follows:

+

+

+

+ # cd /usr/crash

+

+ # ls -l

+

+ -rw-r--r-- 1 root wheel 2B Jan 7 17:07 bounds

+

+ -rw-r--r-- 1 root wheel 17M Jan 7 17:08 kernel.0

+

+ -rw------- 1 root wheel 512M Jan 7 17:08 vmcore.0

+

+ # kgdb kernel.0 vmcore.0

+

+

+

+kgdb(1) will show you the panic message after start. The first thing to do is to obtain a ***backtrace*** with the ***bt*** command: