--- Gnu-Mach/kern/debug.c 2020/09/02 04:42:44 1.1.1.3 +++ Gnu-Mach/kern/debug.c 2020/09/02 04:54:03 1.1.1.6 @@ -24,61 +24,58 @@ * the rights to redistribute these changes. */ -#include +#include -#include -#include -#include +#include +#include #include "cpu_number.h" #include #include -#warning missing include for panic() -void panic(const char *s, ...); - +#include -extern void cnputc(); -void Debugger(); +#include +#include -#if MACH_KDB -extern int db_breakpoints_inserted; -#endif +#include #if NCPUS>1 simple_lock_data_t Assert_print_lock; /* uninited, we take our chances */ #endif +static void +do_cnputc(char c, vm_offset_t offset) +{ + cnputc(c); +} + void -Assert(char *exp, char *file, int line) +Assert(const char *exp, const char *file, int line, const char *fun) { #if NCPUS > 1 simple_lock(&Assert_print_lock); - printf("{%d} Assertion failed: file \"%s\", line %d\n", - cpu_number(), file, line); + printf("{cpu%d} %s:%d: %s: Assertion `%s' failed.", + cpu_number(), file, line, fun, exp); simple_unlock(&Assert_print_lock); #else - printf("Assertion `%s' failed in file \"%s\", line %d\n", - exp, file, line); + printf("%s:%d: %s: Assertion `%s' failed.", + file, line, fun, exp); #endif -#if MACH_KDB - if (db_breakpoints_inserted) -#endif Debugger("assertion failure"); } -void Debugger(message) - char * message; +void SoftDebugger(message) + const char *message; { + printf("Debugger invoked: %s\n", message); + #if !MACH_KDB - panic("Debugger invoked, but there isn't one!"); + printf("But no debugger, continuing.\n"); + return; #endif -#ifdef lint - message++; -#endif /* lint */ - #if defined(vax) || defined(PC532) asm("bpt"); #endif /* vax */ @@ -92,15 +89,27 @@ void Debugger(message) asm("ta 0x81"); #endif /* sun4 */ -#if defined(mips ) || defined(luna88k) || defined(i860) || defined(alpha) +#if defined(mips ) || defined(i860) || defined(alpha) gimmeabreak(); #endif -#ifdef i386 +#if defined(__i386__) || defined(__x86_64__) asm("int3"); #endif } +void Debugger(message) + const char *message; +{ +#if !MACH_KDB + panic("Debugger invoked, but there isn't one!"); +#endif + + SoftDebugger(message); + + panic("Debugger returned!"); +} + /* Be prepared to panic anytime, even before panic_init() gets called from the "normal" place in kern/startup.c. (panic_init() still needs to be called from there @@ -112,7 +121,7 @@ const char *panicstr; int paniccpu; void -panic_init() +panic_init(void) { if (!panic_lock_initialized) { @@ -121,14 +130,15 @@ panic_init() } } +#if ! MACH_KBD +extern boolean_t reboot_on_panic; +#endif + /*VARARGS1*/ void -panic(const char *s, ...) +Panic(const char *file, int line, const char *fun, const char *s, ...) { va_list listp; -#if NORMA_IPC - extern int _node_self; /* node_self() may not be callable yet */ -#endif /* NORMA_IPC */ panic_init(); @@ -145,19 +155,22 @@ panic(const char *s, ...) paniccpu = cpu_number(); } simple_unlock(&panic_lock); - printf("panic"); -#if NORMA_IPC - printf("(node %U)", _node_self); -#endif + printf("panic "); #if NCPUS > 1 - printf("(cpu %U)", paniccpu); + printf("{cpu%d} ", paniccpu); #endif - printf(": "); + printf("%s:%d: %s: ",file, line, fun); va_start(listp, s); - _doprnt(s, &listp, cnputc, 0); + _doprnt(s, listp, do_cnputc, 16, 0); va_end(listp); printf("\n"); +#if MACH_KDB + Debugger("panic"); +#else +# ifdef MACH_HYP + hyp_crash(); +# else /* Give the user time to see the message */ { int i = 1000; /* seconds */ @@ -165,10 +178,8 @@ panic(const char *s, ...) delay (1000000); /* microseconds */ } -#if MACH_KDB - Debugger("panic"); -#else - halt_all_cpus (1); + halt_all_cpus (reboot_on_panic); +# endif /* MACH_HYP */ #endif } @@ -181,10 +192,21 @@ log(int level, const char *fmt, ...) { va_list listp; -#ifdef lint - level++; -#endif va_start(listp, fmt); - _doprnt(fmt, &listp, cnputc, 0); + _doprnt(fmt, listp, do_cnputc, 16, 0); va_end(listp); } + +/* GCC references this for stack protection. */ +unsigned char __stack_chk_guard [ sizeof (vm_offset_t) ] = +{ + [ sizeof (vm_offset_t) - 3 ] = '\r', + [ sizeof (vm_offset_t) - 2 ] = '\n', + [ sizeof (vm_offset_t) - 1 ] = 0xff, +}; + +void +__stack_chk_fail (void) +{ + panic("stack smashing detected"); +}