Annotation of Gnu-Mach/kern/debug.c, revision 1.1.1.4

1.1       root        1: /* 
                      2:  * Mach Operating System
                      3:  * Copyright (c) 1993 Carnegie Mellon University
                      4:  * All Rights Reserved.
                      5:  * 
                      6:  * Permission to use, copy, modify and distribute this software and its
                      7:  * documentation is hereby granted, provided that both the copyright
                      8:  * notice and this permission notice appear in all copies of the
                      9:  * software, derivative works or modified versions, and any portions
                     10:  * thereof, and that both notices appear in supporting documentation.
                     11:  * 
                     12:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     13:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
                     14:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                     15:  * 
                     16:  * Carnegie Mellon requests users of this software to return to
                     17:  * 
                     18:  *  Software Distribution Coordinator  or  [email protected]
                     19:  *  School of Computer Science
                     20:  *  Carnegie Mellon University
                     21:  *  Pittsburgh PA 15213-3890
                     22:  * 
                     23:  * any improvements or extensions that they make and grant Carnegie Mellon
                     24:  * the rights to redistribute these changes.
                     25:  */
                     26: 
1.1.1.4 ! root       27: #include <mach/xen.h>
1.1.1.3   root       28: 
1.1.1.4 ! root       29: #include <kern/printf.h>
        !            30: #include <stdarg.h>
1.1       root       31: 
                     32: #include "cpu_number.h"
                     33: #include <kern/lock.h>
                     34: #include <kern/thread.h>
                     35: 
1.1.1.4 ! root       36: #include <kern/debug.h>
1.1       root       37: 
1.1.1.4 ! root       38: #include <machine/loose_ends.h>
        !            39: #include <machine/model_dep.h>
1.1       root       40: 
                     41: extern void cnputc();
                     42: 
                     43: #if    MACH_KDB
                     44: extern int db_breakpoints_inserted;
                     45: #endif
                     46: 
                     47: #if NCPUS>1
                     48: simple_lock_data_t Assert_print_lock; /* uninited, we take our chances */
                     49: #endif
                     50: 
1.1.1.4 ! root       51: static void
        !            52: do_cnputc(char c, vm_offset_t offset)
        !            53: {
        !            54:        cnputc(c);
        !            55: }
        !            56: 
1.1       root       57: void
                     58: Assert(char *exp, char *file, int line)
                     59: {
                     60: #if NCPUS > 1
                     61:        simple_lock(&Assert_print_lock);
                     62:        printf("{%d} Assertion failed: file \"%s\", line %d\n", 
                     63:               cpu_number(), file, line);
                     64:        simple_unlock(&Assert_print_lock);
                     65: #else
                     66:        printf("Assertion `%s' failed in file \"%s\", line %d\n",
                     67:                exp, file, line);
                     68: #endif
                     69: 
                     70: #if    MACH_KDB
                     71:        if (db_breakpoints_inserted)
                     72: #endif
                     73:        Debugger("assertion failure");
                     74: }
                     75: 
1.1.1.4 ! root       76: void SoftDebugger(message)
1.1       root       77:        char *  message;
                     78: {
1.1.1.4 ! root       79:        printf("Debugger invoked: %s\n", message);
        !            80: 
1.1       root       81: #if    !MACH_KDB
1.1.1.4 ! root       82:        printf("But no debugger, continuing.\n");
        !            83:        return;
1.1       root       84: #endif
                     85: 
                     86: #if    defined(vax) || defined(PC532)
                     87:        asm("bpt");
                     88: #endif /* vax */
                     89: 
                     90: #ifdef sun3
                     91:        current_thread()->pcb->flag |= TRACE_KDB;
                     92:        asm("orw  #0x00008000,sr");
                     93: #endif /* sun3 */
                     94: #ifdef sun4
                     95:        current_thread()->pcb->pcb_flag |= TRACE_KDB;
                     96:        asm("ta 0x81");
                     97: #endif /* sun4 */
                     98: 
1.1.1.4 ! root       99: #if    defined(mips ) || defined(i860) || defined(alpha)
1.1       root      100:        gimmeabreak();
                    101: #endif
                    102: 
1.1.1.4 ! root      103: #if defined(__i386__)
1.1       root      104:        asm("int3");
                    105: #endif
                    106: }
                    107: 
1.1.1.4 ! root      108: void Debugger(message)
        !           109:        char *  message;
        !           110: {
        !           111: #if    !MACH_KDB
        !           112:        panic("Debugger invoked, but there isn't one!");
        !           113: #endif
        !           114: 
        !           115:        SoftDebugger(message);
        !           116: 
        !           117:        panic("Debugger returned!");
        !           118: }
        !           119: 
1.1       root      120: /* Be prepared to panic anytime,
                    121:    even before panic_init() gets called from the "normal" place in kern/startup.c.
                    122:    (panic_init() still needs to be called from there
                    123:    to make sure we get initialized before starting multiple processors.)  */
                    124: boolean_t              panic_lock_initialized = FALSE;
                    125: decl_simple_lock_data(,        panic_lock)
                    126: 
1.1.1.3   root      127: const char                     *panicstr;
1.1       root      128: int                    paniccpu;
                    129: 
                    130: void
1.1.1.4 ! root      131: panic_init(void)
1.1       root      132: {
                    133:        if (!panic_lock_initialized)
                    134:        {
                    135:                panic_lock_initialized = TRUE;
                    136:                simple_lock_init(&panic_lock);
                    137:        }
                    138: }
                    139: 
1.1.1.4 ! root      140: #if ! MACH_KBD
        !           141: extern boolean_t reboot_on_panic;
        !           142: #endif
        !           143: 
1.1       root      144: /*VARARGS1*/
                    145: void
1.1.1.3   root      146: panic(const char *s, ...)
1.1       root      147: {
                    148:        va_list listp;
                    149: 
                    150:        panic_init();
                    151: 
                    152:        simple_lock(&panic_lock);
                    153:        if (panicstr) {
                    154:            if (cpu_number() != paniccpu) {
                    155:                simple_unlock(&panic_lock);
                    156:                halt_cpu();
                    157:                /* NOTREACHED */
                    158:            }
                    159:        }
                    160:        else {
                    161:            panicstr = s;
                    162:            paniccpu = cpu_number();
                    163:        }
                    164:        simple_unlock(&panic_lock);
                    165:        printf("panic");
                    166: #if    NCPUS > 1
                    167:        printf("(cpu %U)", paniccpu);
                    168: #endif
                    169:        printf(": ");
1.1.1.3   root      170:        va_start(listp, s);
1.1.1.4 ! root      171:        _doprnt(s, listp, do_cnputc, 0, 0);
1.1       root      172:        va_end(listp);
                    173:        printf("\n");
                    174: 
1.1.1.4 ! root      175: #if    MACH_KDB
        !           176:        Debugger("panic");
        !           177: #else
        !           178: # ifdef        MACH_HYP
        !           179:        hyp_crash();
        !           180: # else
1.1       root      181:        /* Give the user time to see the message */
                    182:        {
1.1.1.2   root      183:          int i = 1000;         /* seconds */
1.1       root      184:          while (i--)
                    185:            delay (1000000);    /* microseconds */
                    186:        }
                    187: 
1.1.1.4 ! root      188:        halt_all_cpus (reboot_on_panic);
        !           189: # endif        /* MACH_HYP */
1.1       root      190: #endif
                    191: }
                    192: 
                    193: /*
                    194:  * We'd like to use BSD's log routines here...
                    195:  */
                    196: /*VARARGS2*/
                    197: void
1.1.1.3   root      198: log(int level, const char *fmt, ...)
1.1       root      199: {
                    200:        va_list listp;
                    201: 
                    202: #ifdef lint
                    203:        level++;
                    204: #endif
1.1.1.3   root      205:        va_start(listp, fmt);
1.1.1.4 ! root      206:        _doprnt(fmt, listp, do_cnputc, 0, 0);
1.1       root      207:        va_end(listp);
                    208: }
1.1.1.4 ! root      209: 
        !           210: unsigned char __stack_chk_guard [ sizeof (vm_offset_t) ] =
        !           211: {
        !           212:        [ sizeof (vm_offset_t) - 3 ] = '\r',
        !           213:        [ sizeof (vm_offset_t) - 2 ] = '\n',
        !           214:        [ sizeof (vm_offset_t) - 1 ] = 0xff,
        !           215: };
        !           216: 
        !           217: void
        !           218: __stack_chk_fail (void)
        !           219: {
        !           220:        panic("stack smashing detected");
        !           221: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.