14e1a
![]() |
|
|
|
|
|||||||
| FreeBSD Development Kernel development, writing drivers, coding, and questions regarding FreeBSD internals. |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
I try to get a little more experience in kernel debugging. How can I cause a kernel crash?
I put Code:
dumpdev="AUTO" Code:
dumpdir=/var/crash Code:
#include <sys/types.h>
#include <sys/systm.h>
main() {
panic();
}
Last edited by DutchDaemon; April 17th, 2012 at 18:53. Reason: Formatting & Style: http://forums.freebsd.org/showthread.php?t=8816 / http://forums.freebsd.org/showthread.php?t=18043 |
|
#3
|
|||
|
|||
|
Just do
# sysctl debug.kdb.panic=1 as root.
Last edited by DutchDaemon; April 22nd, 2012 at 01:27. |
|
#4
|
|||
|
|||
|
There is no crash dump in this case.
|
|
#6
|
|||
|
|||
|
Interesting,
I've tried to compile the same program too and I got the following: Code:
~> uname -a
FreeBSD bsdmag 8.2-RELEASE FreeBSD 8.2-RELEASE #0:
Fri Feb 18 02:24:46 UTC 2011
root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386
~> cat panic.c
#include <sys/types.h>
#include <sys/systm.h>
main() {
panic("Hello World!");
}
~> gcc panic.c
In file included from panic.c:2:
/usr/include/sys/systm.h:239: error: expected declaration specifiers or '...' before 'uintfptr_t'
/usr/include/sys/systm.h:243: error: expected declaration specifiers or '...' before 'uintfptr_t'
In file included from panic.c:2:
/usr/include/sys/systm.h:300: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splbio'
/usr/include/sys/systm.h:301: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splcam'
/usr/include/sys/systm.h:302: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splclock'
/usr/include/sys/systm.h:303: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splhigh'
/usr/include/sys/systm.h:304: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splimp'
/usr/include/sys/systm.h:305: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splnet'
/usr/include/sys/systm.h:306: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splsoftcam'
/usr/include/sys/systm.h:307: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splsoftclock'
/usr/include/sys/systm.h:308: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splsofttty'
/usr/include/sys/systm.h:309: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splsoftvm'
/usr/include/sys/systm.h:310: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splsofttq'
/usr/include/sys/systm.h:311: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splstatclock'
/usr/include/sys/systm.h:312: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'spltty'
/usr/include/sys/systm.h:313: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splvm'
/usr/include/sys/systm.h:314: error: expected ')' before 'ipl'
|
|
#7
|
|||
|
|||
|
What you're trying to do - calling panic() - won't work, because panic() is a kernel routine, and you're trying to use it in a userland program. You would have to write a kernel module that calls it.
I have no idea why the panic syscall doesn't create crashdump. Last edited by DutchDaemon; April 27th, 2012 at 01:27. |
|
#8
|
|||
|
|||
|
Quote:
Now, for the sake of experimentation, I have written a very very simple module to test the panic system call: each time the panicBin module is unloaded the system panics. Please do not run the module on a production system, and at least make your file systems read only! In my system it generates correctly the crash dump, but please note that if you don't have the dumpdev option in /etc/rc.conf you will need to run savecore(8) to manually extract and store the crash out of the swap. This is my little module code: load and the unload it to crash your system. Code:
// panic.c
#include <sys/param.h>
#include <sys/module.h>
#include <sys/kernel.h>
#include <sys/types.h>
#include <sys/systm.h>
static int
panicEventHandler(
struct module *st_module,
int event,
void* argv
)
{
int error = 0;
switch( event ){
case MOD_LOAD:
uprintf("\nLoading the panic module: unload to panic the system!\n");
break;
case MOD_UNLOAD:
uprintf("\nPanic-ing the system!!!!\n");
panic("Panic Module!");
break;
default:
error = EOPNOTSUPP;
break;
}
return error;
}
static moduledata_t panic_module = {
"panicModule",
panicEventHandler,
NULL
};
DECLARE_MODULE( panicModuleBin,
panic_module,
SI_SUB_DRIVERS,
SI_ORDER_MIDDLE
);
// Makefile
KMOD= panicBin
SRCS= panic.c
.include <bsd.kmod.mk>
|
|
#9
|
|||
|
|||
|
Thanks for answer.
I tried to compile your module but it doesn't compile with the following errors. Code:
In file included from panic.c:5: /usr/include/sys/kernel.h:373: error: expected specifier-qualifier-list before 'TAILQ_ENTRY' In file included from panic.c:7: /usr/include/sys/systm.h:240: error: expected declaration specifiers or '...' before 'uintfptr_t' /usr/include/sys/systm.h:246: error: expected declaration specifiers or '...' before 'uintfptr_t' In file included from panic.c:7: /usr/include/sys/systm.h:312: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splbio' /usr/include/sys/systm.h:313: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splcam' /usr/include/sys/systm.h:314: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splclock' /usr/include/sys/systm.h:315: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splhigh' /usr/include/sys/systm.h:316: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splimp' /usr/include/sys/systm.h:317: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splnet' /usr/include/sys/systm.h:318: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splsoftcam' /usr/include/sys/systm.h:319: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splsoftclock' /usr/include/sys/systm.h:320: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splsofttty' /usr/include/sys/systm.h:321: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splsoftvm' /usr/include/sys/systm.h:322: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splsofttq' /usr/include/sys/systm.h:323: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splstatclock' /usr/include/sys/systm.h:324: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'spltty' /usr/include/sys/systm.h:325: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'splvm' /usr/include/sys/systm.h:326: error: expected ')' before 'ipl' panic.c: In function 'panicEventHandler': panic.c:30: error: 'EOPNOTSUPP' undeclared (first use in this function) panic.c:30: error: (Each undeclared identifier is reported only once panic.c:30: error: for each function it appears in.) panic.c: At top level: panic.c:51: warning: data definition has no type or storage class panic.c:51: warning: parameter names (without types) in function declaration panic.c:57: warning: data definition has no type or storage class panic.c:57: error: 'panicBin' undeclared here (not in a function) panic.c:58: error: expected ',' or ';' before 'SRCS' |
|
#10
|
|||
|
|||
|
How are you compiling the module? It requires the Makefile I wrote to compile.
Last edited by DutchDaemon; May 4th, 2012 at 18:03. |
|
#11
|
|||
|
|||
|
Thanks for the answer. I'am newbie in compiling so I can't detect that your last post has a Makefile in it. I compiled your module and it works great.
Last edited by DutchDaemon; May 4th, 2012 at 18:03. Reason: It's "I", not "i" |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Apparent crash when creating lots of files on UFS | ctengel | Installation and Maintenance of FreeBSD Ports or Packages | 4 | March 12th, 2012 04:01 |
| [Solved] Can KTR crash kernel? | amolsaurabh | General | 7 | February 19th, 2012 08:19 |
| ipfw, dummynet, kernel nat = kernel panic | romeor | Networking | 3 | August 28th, 2010 11:29 |
| Crash dump prob. - sleeping thread owns a non-sleepable lock during crash dump write | Terry_Kennedy | General | 2 | May 14th, 2010 00:28 |
| [Solved] freebsd server crashing (crash dump) | Lem0nHead | General | 12 | August 23rd, 2009 19:27 |