Annotation of XNU/osfmk/kern/debug.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * The contents of this file constitute Original Code as defined in and
        !             7:  * are subject to the Apple Public Source License Version 1.1 (the
        !             8:  * "License").  You may not use this file except in compliance with the
        !             9:  * License.  Please obtain a copy of the License at
        !            10:  * http://www.apple.com/publicsource and read it before using this file.
        !            11:  * 
        !            12:  * This Original Code and all software distributed under the License are
        !            13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            17:  * License for the specific language governing rights and limitations
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: /*
        !            23:  * @OSF_COPYRIGHT@
        !            24:  */
        !            25: /* 
        !            26:  * Mach Operating System
        !            27:  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
        !            28:  * All Rights Reserved.
        !            29:  * 
        !            30:  * Permission to use, copy, modify and distribute this software and its
        !            31:  * documentation is hereby granted, provided that both the copyright
        !            32:  * notice and this permission notice appear in all copies of the
        !            33:  * software, derivative works or modified versions, and any portions
        !            34:  * thereof, and that both notices appear in supporting documentation.
        !            35:  * 
        !            36:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
        !            37:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
        !            38:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
        !            39:  * 
        !            40:  * Carnegie Mellon requests users of this software to return to
        !            41:  * 
        !            42:  *  Software Distribution Coordinator  or  [email protected]
        !            43:  *  School of Computer Science
        !            44:  *  Carnegie Mellon University
        !            45:  *  Pittsburgh PA 15213-3890
        !            46:  * 
        !            47:  * any improvements or extensions that they make and grant Carnegie Mellon
        !            48:  * the rights to redistribute these changes.
        !            49:  */
        !            50: 
        !            51: #include <mach_assert.h>
        !            52: #include <mach_kdb.h>
        !            53: #include <dipc.h>
        !            54: #include <mach_kgdb.h>
        !            55: #include <mach_kdp.h>
        !            56: #include <cpus.h>
        !            57: 
        !            58: #include <kern/cpu_number.h>
        !            59: #include <kern/lock.h>
        !            60: #include <kern/spl.h>
        !            61: #include <kern/thread.h>
        !            62: #include <kern/assert.h>
        !            63: #include <kern/sched_prim.h>
        !            64: #include <kern/misc_protos.h>
        !            65: #include <stdarg.h>
        !            66: 
        !            67: unsigned int   halt_in_debugger = 0;
        !            68: unsigned int   switch_debugger = 0;
        !            69: unsigned int   current_debugger = 0;
        !            70: unsigned int   active_debugger = 0;
        !            71: unsigned int   debug_mode=0;
        !            72: unsigned int   disableDebugOuput = TRUE;
        !            73: 
        !            74: int mach_assert = 1;
        !            75: 
        !            76: const char             *panicstr;
        !            77: decl_simple_lock_data(,panic_lock)
        !            78: int                    paniccpu;
        !            79: volatile int           panicwait;
        !            80: volatile int           nestedpanic= 0;
        !            81: unsigned int           panic_is_inited = 0;
        !            82: unsigned int           return_on_panic = 0;
        !            83: 
        !            84: void
        !            85: Assert(
        !            86:        const char      *file,
        !            87:        int             line,
        !            88:        const char      *expression)
        !            89: {
        !            90:        if (!mach_assert) {
        !            91:                return;
        !            92:        }
        !            93:        panic("{%d} Assertion failed: file \"%s\", line %d: %s\n", 
        !            94:               cpu_number(), file, line, expression);
        !            95: }
        !            96: 
        !            97: /*
        !            98:  *     Carefully use the panic_lock.  There's always a chance that
        !            99:  *     somehow we'll call panic before getting to initialize the
        !           100:  *     panic_lock -- in this case, we'll assume that the world is
        !           101:  *     in uniprocessor mode and just avoid using the panic lock.
        !           102:  */
        !           103: #define        PANIC_LOCK()                                                    \
        !           104: MACRO_BEGIN                                                            \
        !           105:        if (panic_is_inited)                                            \
        !           106:                simple_lock(&panic_lock);                               \
        !           107: MACRO_END
        !           108: 
        !           109: #define        PANIC_UNLOCK()                                                  \
        !           110: MACRO_BEGIN                                                            \
        !           111:        if (panic_is_inited)                                            \
        !           112:                simple_unlock(&panic_lock);                             \
        !           113: MACRO_END
        !           114: 
        !           115: 
        !           116: void
        !           117: panic_init(void)
        !           118: {
        !           119:        simple_lock_init(&panic_lock, ETAP_NO_TRACE);
        !           120:        panic_is_inited = 1;
        !           121: }
        !           122: 
        !           123: void
        !           124: panic(const char *str, ...)
        !           125: {
        !           126:        va_list listp;
        !           127:        spl_t   s = splhigh();
        !           128: 
        !           129:        mp_disable_preemption();
        !           130:        disableDebugOuput = FALSE;
        !           131:        debug_mode = TRUE;
        !           132: restart:
        !           133:        PANIC_LOCK();
        !           134:        if (panicstr) {
        !           135:                if (cpu_number() != paniccpu) {
        !           136:                        PANIC_UNLOCK();
        !           137:                        /*
        !           138:                         * Wait until message has been printed to identify correct
        !           139:                         * cpu that made the first panic.
        !           140:                         */
        !           141:                        while (panicwait)
        !           142:                                continue;
        !           143:                        goto restart;
        !           144:            } else {
        !           145:                        nestedpanic +=1;
        !           146:                        PANIC_UNLOCK();
        !           147:                        Debugger("double panic");
        !           148:                        mp_enable_preemption();
        !           149:                        splx(s);
        !           150:                        printf("double panic:  We are hanging here...\n");
        !           151:                        while(1);
        !           152:                        /* NOTREACHED */
        !           153:                }
        !           154:        }
        !           155:        panicstr = str;
        !           156:        paniccpu = cpu_number();
        !           157:        panicwait = 1;
        !           158: 
        !           159:        PANIC_UNLOCK();
        !           160:        printf("panic(cpu %d): ", (unsigned) paniccpu);
        !           161:        va_start(listp, str);
        !           162:        _doprnt(str, &listp, cnputc, 0);
        !           163:        va_end(listp);
        !           164:        printf("\n");
        !           165: 
        !           166:        /*
        !           167:         * Release panicwait indicator so that other cpus may call Debugger().
        !           168:         */
        !           169:        panicwait = 0;
        !           170:        Debugger("panic");
        !           171:        /*
        !           172:         * Release panicstr so that we can handle normally other panics.
        !           173:         */
        !           174:        PANIC_LOCK();
        !           175:        panicstr = (char *)0;
        !           176:        PANIC_UNLOCK();
        !           177:        mp_enable_preemption();
        !           178:        splx(s);
        !           179:        if (return_on_panic)
        !           180:                return;
        !           181:        printf("panic: We are hanging here...\n");
        !           182:        while(1);
        !           183:        /* NOTREACHED */
        !           184: }
        !           185: 
        !           186: void
        !           187: log(int level, char *fmt, ...)
        !           188: {
        !           189:        va_list listp;
        !           190:        extern void conslog_putc(char);
        !           191: 
        !           192: #ifdef lint
        !           193:        level++;
        !           194: #endif /* lint */
        !           195: #ifdef MACH_BSD
        !           196:        disable_preemption();
        !           197:        va_start(listp, fmt);
        !           198:        _doprnt(fmt, &listp, conslog_putc, 0);
        !           199:        va_end(listp);
        !           200:        enable_preemption();
        !           201: #endif
        !           202: }

unix.superglobalmegacorp.com

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