Annotation of XNU/osfmk/ddb/db_output.c, revision 1.1.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:  * HISTORY
                     27:  * 
                     28:  * Revision 1.1.1.1  1998/09/22 21:05:48  wsanchez
                     29:  * Import of Mac OS X kernel (~semeria)
                     30:  *
                     31:  * Revision 1.1.1.1  1998/03/07 02:26:09  wsanchez
                     32:  * Import of OSF Mach kernel (~mburg)
                     33:  *
                     34:  * Revision 1.3.17.6  1996/01/09  19:15:57  devrcs
                     35:  *     In db_more(), if using kdebug on Alpha, don't get input.
                     36:  *     [1995/12/01  21:42:17  jfraser]
                     37:  *
                     38:  *     Merged '64-bit safe' changes from DEC alpha port.
                     39:  *     [1995/11/21  18:03:19  jfraser]
                     40:  *
                     41:  * Revision 1.3.17.5  1995/08/21  20:29:18  devrcs
                     42:  *     Move the include out of db_output_prompt
                     43:  *     [1995/07/20  19:15:52  travos]
                     44:  * 
                     45:  * Revision 1.3.17.4  1995/02/23  21:43:30  alanl
                     46:  *     Merge with DIPC2_SHARED.
                     47:  *     [95/01/04            alanl]
                     48:  * 
                     49:  * Revision 1.3.22.1  1994/11/04  09:52:55  dwm
                     50:  *     mk6 CR668 - 1.3b26 merge
                     51:  *     * Revision 1.3.4.6  1994/05/06  18:39:31  tmt
                     52:  *     Merged osc1.3dec/shared with osc1.3b19
                     53:  *     Merge Alpha changes into osc1.312b source code.
                     54:  *     removed db_radix declaration.
                     55:  *     * End1.3merge
                     56:  *     [1994/11/04  08:49:42  dwm]
                     57:  * 
                     58:  * Revision 1.3.17.2  1994/09/23  01:20:36  ezf
                     59:  *     change marker to not FREE
                     60:  *     [1994/09/22  21:10:32  ezf]
                     61:  * 
                     62:  * Revision 1.3.17.1  1994/06/11  21:11:56  bolinger
                     63:  *     Merge up to NMK17.2.
                     64:  *     [1994/06/11  20:02:01  bolinger]
                     65:  * 
                     66:  * Revision 1.3.19.3  1994/12/06  19:42:52  alanl
                     67:  *     Change _node_self ref to KKT_NODE_SELF().
                     68:  *     [94/12/05            rwd]
                     69:  * 
                     70:  * Revision 1.3.19.2  1994/09/01  12:48:39  alanl
                     71:  *     Remove dead NORMA_IPC conditional.
                     72:  *     [94/08/29            alanl]
                     73:  * 
                     74:  * Revision 1.3.19.1  1994/08/04  01:42:27  mmp
                     75:  *     Added DIPC support for debugger prompt.
                     76:  *     [1994/08/03  13:37:21  mmp]
                     77:  * 
                     78:  * Revision 1.3.15.1  1994/02/08  10:58:09  bernadat
                     79:  *     Added db_output_prompt().
                     80:  *     [93/08/12            paire]
                     81:  * 
                     82:  *     Fixed db_end_line() for generating a pseudo end of line.
                     83:  *     [93/09/29            paire]
                     84:  * 
                     85:  *     Added db_reset_more() to restart more function.
                     86:  *     Added db_last_gen_return variable to determine if a '\n' has to be
                     87:  *     output (no if precedeed by a generated '\n').
                     88:  *     Added db_auto_wrap variable to define if the terminal automaticallly
                     89:  *     wraps up to the beginning of next line when the last character of the
                     90:  *     current line is output.
                     91:  *     [93/08/12            paire]
                     92:  * 
                     93:  *     Fixed db_advance_output_position() to go to the last character of
                     94:  *     each line (the last one generated a buggy '\n').
                     95:  *     Added db_reserve_output_position() to force a new_line if there is not
                     96:  *     enough place before end of line.
                     97:  *     [93/08/11            paire]
                     98:  *     [94/02/07            bernadat]
                     99:  * 
                    100:  * Revision 1.3.4.4  1993/08/11  20:38:03  elliston
                    101:  *     Add ANSI Prototypes.  CR #9523.
                    102:  *     [1993/08/11  03:33:38  elliston]
                    103:  * 
                    104:  * Revision 1.3.4.3  1993/07/27  18:27:50  elliston
                    105:  *     Add ANSI prototypes.  CR #9523.
                    106:  *     [1993/07/27  18:12:31  elliston]
                    107:  * 
                    108:  * Revision 1.3.4.2  1993/06/09  02:20:24  gm
                    109:  *     CR9176 - ANSI C violations: trailing tokens on CPP
                    110:  *     directives, extra semicolons after decl_ ..., asm keywords
                    111:  *     [1993/06/07  18:57:18  jeffc]
                    112:  * 
                    113:  *     Added to OSF/1 R1.3 from NMK15.0.
                    114:  *     [1993/06/02  20:56:45  jeffc]
                    115:  * 
                    116:  * Revision 1.3  1993/04/19  16:02:33  devrcs
                    117:  *     Added forward declaration for db_printf.
                    118:  *     [93/04/05            bernadat]
                    119:  * 
                    120:  *     Changes from mk78:
                    121:  *     Added void type to functions that needed it.
                    122:  *     [92/05/16            jfriedl]
                    123:  *     [93/02/02            bruel]
                    124:  * 
                    125:  *     Fixed tabs management for long lines. [[email protected]]
                    126:  *     [92/12/03            bernadat]
                    127:  * 
                    128:  * Revision 1.2  1992/11/25  01:04:34  robert
                    129:  *     integrate changes below for norma_14
                    130:  * 
                    131:  *     Philippe Bernadat (bernadat) at gr.osf.org
                    132:  *     Moved iprintf to here, result was horible for MPs (cpu number in
                    133:  *     front of each iprintf.)
                    134:  *     [1992/11/13  19:21:47  robert]
                    135:  * 
                    136:  * Revision 1.1  1992/09/30  02:01:14  robert
                    137:  *     Initial revision
                    138:  * 
                    139:  * $EndLog$
                    140:  */
                    141: /* CMU_HIST */
                    142: /*
                    143:  * Revision 2.6  91/10/09  16:01:26  af
                    144:  *      Revision 2.5.2.1  91/10/05  13:06:46  jeffreyh
                    145:  *             Added "more" like function.
                    146:  *             [91/08/29            tak]
                    147:  * 
                    148:  * Revision 2.5.2.1  91/10/05  13:06:46  jeffreyh
                    149:  *     Added "more" like function.
                    150:  *     [91/08/29            tak]
                    151:  * 
                    152:  * Revision 2.5  91/07/09  23:15:54  danner
                    153:  *     Include machine/db_machdep.c.
                    154:  *     When db_printf is invoked, call db_printing on luna. This is used
                    155:  *      to trigger a screen clear. Under luna88k conditional.
                    156:  *     [91/07/08            danner]
                    157:  *
                    158:  * Revision 2.4  91/05/14  15:34:51  mrt
                    159:  *     Correcting copyright
                    160:  * 
                    161:  * Revision 2.3  91/02/05  17:06:45  mrt
                    162:  *     Changed to new Mach copyright
                    163:  *     [91/01/31  16:18:41  mrt]
                    164:  * 
                    165:  * Revision 2.2  90/08/27  21:51:25  dbg
                    166:  *     Put extra features of db_doprnt in _doprnt.
                    167:  *     [90/08/20            dbg]
                    168:  *     Reduce lint.
                    169:  *     [90/08/07            dbg]
                    170:  *     Created.
                    171:  *     [90/07/25            dbg]
                    172:  * 
                    173:  */
                    174: /* CMU_ENDHIST */
                    175: /* 
                    176:  * Mach Operating System
                    177:  * Copyright (c) 1991,1990 Carnegie Mellon University
                    178:  * All Rights Reserved.
                    179:  * 
                    180:  * Permission to use, copy, modify and distribute this software and its
                    181:  * documentation is hereby granted, provided that both the copyright
                    182:  * notice and this permission notice appear in all copies of the
                    183:  * software, derivative works or modified versions, and any portions
                    184:  * thereof, and that both notices appear in supporting documentation.
                    185:  * 
                    186:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                    187:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
                    188:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                    189:  * 
                    190:  * Carnegie Mellon requests users of this software to return to
                    191:  * 
                    192:  *  Software Distribution Coordinator  or  [email protected]
                    193:  *  School of Computer Science
                    194:  *  Carnegie Mellon University
                    195:  *  Pittsburgh PA 15213-3890
                    196:  * 
                    197:  * any improvements or extensions that they make and grant Carnegie Mellon
                    198:  * the rights to redistribute these changes.
                    199:  */
                    200: /*
                    201:  */
                    202: /*
                    203:  *     Author: David B. Golub, Carnegie Mellon University
                    204:  *     Date:   7/90
                    205:  */
                    206: 
                    207: /*
                    208:  * Printf and character output for debugger.
                    209:  */
                    210: 
                    211: #include <dipc.h>
                    212: 
                    213: #include <mach/boolean.h>
                    214: #include <kern/misc_protos.h>
                    215: #include <stdarg.h>
                    216: #include <machine/db_machdep.h>
                    217: #include <ddb/db_command.h>
                    218: #include <ddb/db_lex.h>
                    219: #include <ddb/db_input.h>
                    220: #include <ddb/db_output.h>
                    221: #include <ddb/db_task_thread.h>
                    222: 
                    223: /*
                    224:  *     Character output - tracks position in line.
                    225:  *     To do this correctly, we should know how wide
                    226:  *     the output device is - then we could zero
                    227:  *     the line position when the output device wraps
                    228:  *     around to the start of the next line.
                    229:  *
                    230:  *     Instead, we count the number of spaces printed
                    231:  *     since the last printing character so that we
                    232:  *     don't print trailing spaces.  This avoids most
                    233:  *     of the wraparounds.
                    234:  */
                    235: 
                    236: #ifndef        DB_MAX_LINE
                    237: #define        DB_MAX_LINE             24      /* maximum line */
                    238: #define DB_MAX_WIDTH           80      /* maximum width */
                    239: #endif /* DB_MAX_LINE */
                    240: 
                    241: #define DB_MIN_MAX_WIDTH       20      /* minimum max width */
                    242: #define DB_MIN_MAX_LINE                3       /* minimum max line */
                    243: #define CTRL(c)                        ((c) & 0xff)
                    244: 
                    245: int    db_output_position = 0;         /* output column */
                    246: int    db_output_line = 0;             /* output line number */
                    247: int    db_last_non_space = 0;          /* last non-space character */
                    248: int    db_last_gen_return = 0;         /* last character generated return */
                    249: int    db_auto_wrap = 1;               /* auto wrap at end of line ? */
                    250: int    db_tab_stop_width = 8;          /* how wide are tab stops? */
                    251: #define        NEXT_TAB(i) \
                    252:        ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
                    253: int    db_max_line = DB_MAX_LINE;      /* output max lines */
                    254: int    db_max_width = DB_MAX_WIDTH;    /* output line width */
                    255: 
                    256: 
                    257: /* Prototypes for functions local to this file.  XXX -- should be static!
                    258:  */
                    259: static void db_more(void);
                    260: void db_advance_output_position(int new_output_position,
                    261:                                int blank);
                    262: 
                    263: 
                    264: /*
                    265:  * Force pending whitespace.
                    266:  */
                    267: void
                    268: db_force_whitespace(void)
                    269: {
                    270:        register int last_print, next_tab;
                    271: 
                    272:        last_print = db_last_non_space;
                    273:        while (last_print < db_output_position) {
                    274:            next_tab = NEXT_TAB(last_print);
                    275:            if (next_tab <= db_output_position) {
                    276:                cnputc('\t');
                    277:                last_print = next_tab;
                    278:            }
                    279:            else {
                    280:                cnputc(' ');
                    281:                last_print++;
                    282:            }
                    283:        }
                    284:        db_last_non_space = db_output_position;
                    285: }
                    286: 
                    287: void
                    288: db_reset_more()
                    289: {
                    290:        db_output_line = 0;
                    291: }
                    292: 
                    293: static void
                    294: db_more(void)
                    295: {
                    296:        register  char *p;
                    297:        boolean_t quit_output = FALSE;
                    298: 
                    299: #if defined(__alpha)
                    300:        extern boolean_t kdebug_mode;
                    301:        if (kdebug_mode) return;
                    302: #endif /* defined(__alpha) */
                    303:        for (p = "--db_more--"; *p; p++)
                    304:            cnputc(*p);
                    305:        switch(cngetc()) {
                    306:        case ' ':
                    307:            db_output_line = 0;
                    308:            break;
                    309:        case 'q':
                    310:        case CTRL('c'):
                    311:            db_output_line = 0;
                    312:            quit_output = TRUE;
                    313:            break;
                    314:        default:
                    315:            db_output_line--;
                    316:            break;
                    317:        }
                    318:        p = "\b\b\b\b\b\b\b\b\b\b\b           \b\b\b\b\b\b\b\b\b\b\b";
                    319:        while (*p)
                    320:            cnputc(*p++);
                    321:        if (quit_output) {
                    322:            db_error((char *) 0);
                    323:            /* NOTREACHED */
                    324:        }
                    325: }
                    326: 
                    327: void
                    328: db_advance_output_position(int new_output_position,
                    329:                           int blank)
                    330: {
                    331:        if (db_max_width >= DB_MIN_MAX_WIDTH 
                    332:            && new_output_position >= db_max_width) {
                    333:                /* auto new line */
                    334:                if (!db_auto_wrap || blank)
                    335:                    cnputc('\n');
                    336:                db_output_position = 0;
                    337:                db_last_non_space = 0;
                    338:                db_last_gen_return = 1;
                    339:                db_output_line++;
                    340:        } else {
                    341:                db_output_position = new_output_position;
                    342:        }
                    343: }
                    344: 
                    345: boolean_t
                    346: db_reserve_output_position(int increment)
                    347: {
                    348:        if (db_max_width >= DB_MIN_MAX_WIDTH
                    349:            && db_output_position + increment >= db_max_width) {
                    350:                /* auto new line */
                    351:                if (!db_auto_wrap || db_last_non_space != db_output_position)
                    352:                    cnputc('\n');
                    353:                db_output_position = 0;
                    354:                db_last_non_space = 0;
                    355:                db_last_gen_return = 1;
                    356:                db_output_line++;
                    357:                return TRUE;
                    358:        }
                    359:        return FALSE;
                    360: }
                    361: 
                    362: /*
                    363:  * Output character.  Buffer whitespace.
                    364:  */
                    365: void
                    366: db_putchar(char c)
                    367: {
                    368:        if (db_max_line >= DB_MIN_MAX_LINE && db_output_line >= db_max_line-1)
                    369:            db_more();
                    370:        if (c > ' ' && c <= '~') {
                    371:            /*
                    372:             * Printing character.
                    373:             * If we have spaces to print, print them first.
                    374:             * Use tabs if possible.
                    375:             */
                    376:            db_force_whitespace();
                    377:            cnputc(c);
                    378:            db_last_gen_return = 0;
                    379:            db_advance_output_position(db_output_position+1, 0);
                    380:            db_last_non_space = db_output_position;
                    381:        }
                    382:        else if (c == '\n') {
                    383:            /* Return */
                    384:            if (db_last_gen_return) {
                    385:                db_last_gen_return = 0;
                    386:            } else {
                    387:                cnputc(c);
                    388:                db_output_position = 0;
                    389:                db_last_non_space = 0;
                    390:                db_output_line++;
                    391:                db_check_interrupt();
                    392:            }
                    393:        }
                    394:        else if (c == '\t') {
                    395:            /* assume tabs every 8 positions */
                    396:            db_advance_output_position(NEXT_TAB(db_output_position), 1);
                    397:        }
                    398:        else if (c == ' ') {
                    399:            /* space */
                    400:            db_advance_output_position(db_output_position+1, 1);
                    401:        }
                    402:        else if (c == '\007') {
                    403:            /* bell */
                    404:            cnputc(c);
                    405:        }
                    406:        /* other characters are assumed non-printing */
                    407: }
                    408: 
                    409: /*
                    410:  * Return output position
                    411:  */
                    412: int
                    413: db_print_position(void)
                    414: {
                    415:        return (db_output_position);
                    416: }
                    417: 
                    418: /*
                    419:  * End line if too long.
                    420:  */
                    421: void
                    422: db_end_line(void)
                    423: {
                    424:        if (db_output_position >= db_max_width-1) {
                    425:            /* auto new line */
                    426:            if (!db_auto_wrap)
                    427:                cnputc('\n');
                    428:            db_output_position = 0;
                    429:            db_last_non_space = 0;
                    430:            db_last_gen_return = 1;
                    431:            db_output_line++;
                    432:        }
                    433: }
                    434: 
                    435: /*
                    436:  * Printing
                    437:  */
                    438: 
                    439: void
                    440: db_printf(char *fmt, ...)
                    441: {
                    442:        va_list listp;
                    443: 
                    444: #ifdef luna88k
                    445:        db_printing();
                    446: #endif
                    447:        va_start(listp, fmt);
                    448:        _doprnt(fmt, &listp, db_putchar, db_radix);
                    449:        va_end(listp);
                    450: }
                    451: 
                    452: /* alternate name */
                    453: 
                    454: void
                    455: kdbprintf(char *fmt, ...)
                    456: {
                    457:        va_list listp;
                    458: 
                    459:        va_start(listp, fmt);
                    460:        _doprnt(fmt, &listp, db_putchar, db_radix);
                    461:        va_end(listp);
                    462: }
                    463: 
                    464: int    db_indent = 0;
                    465: 
                    466: /*
                    467:  * Printing (to console) with indentation.
                    468:  */
                    469: void
                    470: iprintf(char *fmt, ...)
                    471: {
                    472:        va_list listp;
                    473:        register int i;
                    474: 
                    475:        for (i = db_indent; i > 0; ){
                    476:            if (i >= 8) {
                    477:                kdbprintf("\t");
                    478:                i -= 8;
                    479:            }
                    480:            else {
                    481:                kdbprintf(" ");
                    482:                i--;
                    483:            }
                    484:        }
                    485: 
                    486:        va_start(listp, fmt);
                    487:        _doprnt(fmt, &listp, db_putchar, db_radix);
                    488:        va_end(listp);
                    489: }
                    490: 
                    491: #if    DIPC
                    492: #include <mach/kkt_request.h>
                    493: #endif /* DIPC */
                    494: 
                    495: void
                    496: db_output_prompt(void)
                    497: {
                    498:        db_printf("db%s", (db_default_act) ? "t": "");
                    499: #if    DIPC
                    500:        db_printf("%d", KKT_NODE_SELF());
                    501: #endif /* DIPC */
                    502: #if    NCPUS > 1
                    503:        db_printf("{%d}", cpu_number());
                    504: #endif
                    505:        db_printf("> ");
                    506: }
                    507: 

unix.superglobalmegacorp.com

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