14e1a Generate kernel panic with crash dump creating - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Development > FreeBSD Development

FreeBSD Development Kernel development, writing drivers, coding, and questions regarding FreeBSD internals.

Reply
 
Thread Tools Display Modes
  #1  
Old April 17th, 2012, 07:17
blitzkrieg blitzkrieg is offline
Junior Member
 
Join Date: Apr 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Generate kernel panic with crash dump creating

I try to get a little more experience in kernel debugging. How can I cause a kernel crash?
I put
Code:
dumpdev="AUTO"
and
Code:
dumpdir=/var/crash
into my rc.conf and set debug.kdb.panic to 1. There is no kernel dump in /var/crash. Then I try to use the panic() function:
Code:
#include <sys/types.h>
#include <sys/systm.h>
main() {
panic();
}
But it doesn't compile. What can I to do to crash kernel?

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
Reply With Quote
  #2  
Old April 19th, 2012, 11:08
fluca1978 fluca1978 is offline
Member
 
Join Date: May 2010
Posts: 663
Thanks: 27
Thanked 60 Times in 57 Posts
Default

It does not compile because panic(9) wants a printf-like argument list.
Reply With Quote
  #3  
Old April 21st, 2012, 22:11
trasz@ trasz@ is offline
FreeBSD Developer
 
Join Date: Feb 2008
Location: Warszawa, Poland
Posts: 178
Thanks: 7
Thanked 37 Times in 29 Posts
Default

Just do # sysctl debug.kdb.panic=1 as root.

Last edited by DutchDaemon; April 22nd, 2012 at 01:27.
Reply With Quote
  #4  
Old April 22nd, 2012, 06:10
blitzkrieg blitzkrieg is offline
Junior Member
 
Join Date: Apr 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by trasz@ View Post
Just do # sysctl debug.kdb.panic=1 as root.
There is no crash dump in this case.
Reply With Quote
  #5  
Old April 22nd, 2012, 06:11
blitzkrieg blitzkrieg is offline
Junior Member
 
Join Date: Apr 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by fluca1978 View Post
It does not compile because panic(9) wants a printf-like argument list.
I've tried with
Code:
panic("iam in panic");
It doesn't compile either.

Last edited by DutchDaemon; April 22nd, 2012 at 17:08.
Reply With Quote
  #6  
Old April 26th, 2012, 13:19
fluca1978 fluca1978 is offline
Member
 
Join Date: May 2010
Posts: 663
Thanks: 27
Thanked 60 Times in 57 Posts
Default

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'
It seems the types defined in types.h are not processed right by the pre-processor. Is this the same error you get? Can anyone suggest a solution?
Reply With Quote
  #7  
Old April 26th, 2012, 13:48
trasz@ trasz@ is offline
FreeBSD Developer
 
Join Date: Feb 2008
Location: Warszawa, Poland
Posts: 178
Thanks: 7
Thanked 37 Times in 29 Posts
Default

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.
Reply With Quote
  #8  
Old April 26th, 2012, 15:51
fluca1978 fluca1978 is offline
Member
 
Join Date: May 2010
Posts: 663
Thanks: 27
Thanked 60 Times in 57 Posts
Default

Quote:
Originally Posted by trasz@ View Post
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.
Right, the problem was that, and it was so simple.....sgrunt!

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>
Reply With Quote
  #9  
Old April 27th, 2012, 07:31
blitzkrieg blitzkrieg is offline
Junior Member
 
Join Date: Apr 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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'
Reply With Quote
  #10  
Old May 3rd, 2012, 07:04
fluca1978 fluca1978 is offline
Member
 
Join Date: May 2010
Posts: 663
Thanks: 27
Thanked 60 Times in 57 Posts
Default

How are you compiling the module? It requires the Makefile I wrote to compile.

Last edited by DutchDaemon; May 4th, 2012 at 18:03.
Reply With Quote
  #11  
Old May 4th, 2012, 06:43
blitzkrieg blitzkrieg is offline
Junior Member
 
Join Date: Apr 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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"
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT +1. The time now is 18:35.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0