The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/ddb/db_output.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* 
    2  * Mach Operating System
    3  * Copyright (c) 1991,1990 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  Software.Distribution@CS.CMU.EDU
   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 /*
   27  * HISTORY
   28  * $Log:        db_output.c,v $
   29  * Revision 2.11  93/05/13  14:39:34  rvb
   30  *      db_putc is used by the luna; rename it here.
   31  *      [93/05/13            rvb]
   32  * 
   33  * Revision 2.10  93/05/10  17:45:56  rvb
   34  *      _doprint assumes 1st arg of putc type function is char not int.
   35  *      Make db_id_putc conform.
   36  *      [93/04/27            Ian Dall <DALL@hfrd.dsto.gov.au>]
   37  * 
   38  *      Call _doprnt with the right number of arguments. Define db_id_putc
   39  *      which has an extra dummy argument cf db_putchar. Use db_id_putc
   40  *      instead of db_putchar in call to _doprnt.
   41  *      [93/04/25            Ian Dall <DALL@hfrd.dsto.gov.au>]
   42  * 
   43  * Revision 2.9  93/01/14  17:25:24  danner
   44  *      64bit cleanup.
   45  *      [92/11/30            af]
   46  * 
   47  * Revision 2.8  92/08/03  17:31:38  jfriedl
   48  *      removed silly prototypes
   49  *      [92/08/02            jfriedl]
   50  * 
   51  * Revision 2.7  92/05/21  17:07:20  jfriedl
   52  *      Added void type to functions that needed it.
   53  *      [92/05/16            jfriedl]
   54  * 
   55  * Revision 2.6  91/10/09  16:01:26  af
   56  *       Revision 2.5.2.1  91/10/05  13:06:46  jeffreyh
   57  *              Added "more" like function.
   58  *              [91/08/29            tak]
   59  * 
   60  * Revision 2.5.2.1  91/10/05  13:06:46  jeffreyh
   61  *      Added "more" like function.
   62  *      [91/08/29            tak]
   63  * 
   64  * Revision 2.5  91/07/09  23:15:54  danner
   65  *      Include machine/db_machdep.c.
   66  *      When db_printf is invoked, call db_printing on luna. This is used
   67  *       to trigger a screen clear. Under luna88k conditional.
   68  *      [91/07/08            danner]
   69  *
   70  * Revision 2.4  91/05/14  15:34:51  mrt
   71  *      Correcting copyright
   72  * 
   73  * Revision 2.3  91/02/05  17:06:45  mrt
   74  *      Changed to new Mach copyright
   75  *      [91/01/31  16:18:41  mrt]
   76  * 
   77  * Revision 2.2  90/08/27  21:51:25  dbg
   78  *      Put extra features of db_doprnt in _doprnt.
   79  *      [90/08/20            dbg]
   80  *      Reduce lint.
   81  *      [90/08/07            dbg]
   82  *      Created.
   83  *      [90/07/25            dbg]
   84  * 
   85  */
   86 /*
   87  *      Author: David B. Golub, Carnegie Mellon University
   88  *      Date:   7/90
   89  */
   90 
   91 /*
   92  * Printf and character output for debugger.
   93  */
   94 
   95 #include <mach/boolean.h>
   96 #include <sys/varargs.h>
   97 #include <machine/db_machdep.h>
   98 #include <ddb/db_lex.h>
   99 #include <ddb/db_output.h>
  100 
  101 /*
  102  *      Character output - tracks position in line.
  103  *      To do this correctly, we should know how wide
  104  *      the output device is - then we could zero
  105  *      the line position when the output device wraps
  106  *      around to the start of the next line.
  107  *
  108  *      Instead, we count the number of spaces printed
  109  *      since the last printing character so that we
  110  *      don't print trailing spaces.  This avoids most
  111  *      of the wraparounds.
  112  */
  113 
  114 #ifndef DB_MAX_LINE
  115 #define DB_MAX_LINE             24      /* maximum line */
  116 #define DB_MAX_WIDTH            80      /* maximum width */
  117 #endif  DB_MAX_LINE
  118 
  119 #define DB_MIN_MAX_WIDTH        20      /* minimum max width */
  120 #define DB_MIN_MAX_LINE         3       /* minimum max line */
  121 #define CTRL(c)                 ((c) & 0xff)
  122 
  123 int     db_output_position = 0;         /* output column */
  124 int     db_output_line = 0;             /* output line number */
  125 int     db_last_non_space = 0;          /* last non-space character */
  126 int     db_tab_stop_width = 8;          /* how wide are tab stops? */
  127 #define NEXT_TAB(i) \
  128         ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
  129 int     db_max_line = DB_MAX_LINE;      /* output max lines */
  130 int     db_max_width = DB_MAX_WIDTH;    /* output line width */
  131 
  132 extern void     db_check_interrupt();
  133 
  134 /*
  135  * Force pending whitespace.
  136  */
  137 void
  138 db_force_whitespace()
  139 {
  140         register int last_print, next_tab;
  141 
  142         last_print = db_last_non_space;
  143         while (last_print < db_output_position) {
  144             next_tab = NEXT_TAB(last_print);
  145             if (next_tab <= db_output_position) {
  146                 cnputc('\t');
  147                 last_print = next_tab;
  148             }
  149             else {
  150                 cnputc(' ');
  151                 last_print++;
  152             }
  153         }
  154         db_last_non_space = db_output_position;
  155 }
  156 
  157 static void
  158 db_more()
  159 {
  160         register  char *p;
  161         boolean_t quit_output = FALSE;
  162 
  163         for (p = "--db_more--"; *p; p++)
  164             cnputc(*p);
  165         switch(cngetc()) {
  166         case ' ':
  167             db_output_line = 0;
  168             break;
  169         case 'q':
  170         case CTRL('c'):
  171             db_output_line = 0;
  172             quit_output = TRUE;
  173             break;
  174         default:
  175             db_output_line--;
  176             break;
  177         }
  178         p = "\b\b\b\b\b\b\b\b\b\b\b           \b\b\b\b\b\b\b\b\b\b\b";
  179         while (*p)
  180             cnputc(*p++);
  181         if (quit_output) {
  182             db_error(0);
  183             /* NOTREACHED */
  184         }
  185 }
  186 
  187 /*
  188  * Output character.  Buffer whitespace.
  189  */
  190 void
  191 db_putchar(c)
  192         int     c;              /* character to output */
  193 {
  194         if (db_max_line >= DB_MIN_MAX_LINE && db_output_line >= db_max_line-1)
  195             db_more();
  196         if (c > ' ' && c <= '~') {
  197             /*
  198              * Printing character.
  199              * If we have spaces to print, print them first.
  200              * Use tabs if possible.
  201              */
  202             db_force_whitespace();
  203             cnputc(c);
  204             db_output_position++;
  205             if (db_max_width >= DB_MIN_MAX_WIDTH
  206                 && db_output_position >= db_max_width-1) {
  207                 /* auto new line */
  208                 cnputc('\n');
  209                 db_output_position = 0;
  210                 db_last_non_space = 0;
  211                 db_output_line++;
  212             }
  213             db_last_non_space = db_output_position;
  214         }
  215         else if (c == '\n') {
  216             /* Return */
  217             cnputc(c);
  218             db_output_position = 0;
  219             db_last_non_space = 0;
  220             db_output_line++;
  221             db_check_interrupt();
  222         }
  223         else if (c == '\t') {
  224             /* assume tabs every 8 positions */
  225             db_output_position = NEXT_TAB(db_output_position);
  226         }
  227         else if (c == ' ') {
  228             /* space */
  229             db_output_position++;
  230         }
  231         else if (c == '\007') {
  232             /* bell */
  233             cnputc(c);
  234         }
  235         /* other characters are assumed non-printing */
  236 }
  237 
  238 void
  239 db_id_putc(char c, vm_offset_t dummy)
  240 {
  241   db_putchar(c);
  242 }
  243 
  244 /*
  245  * Return output position
  246  */
  247 int
  248 db_print_position()
  249 {
  250         return (db_output_position);
  251 }
  252 
  253 /*
  254  * End line if too long.
  255  */
  256 void db_end_line()
  257 {
  258         if (db_output_position >= db_max_width-1)
  259             db_printf("\n");
  260 }
  261 
  262 /*
  263  * Printing
  264  */
  265 extern void     _doprnt();
  266 
  267 /*VARARGS1*/
  268 void
  269 db_printf( fmt, va_alist)
  270         char *  fmt;
  271         va_dcl
  272 {
  273         va_list listp;
  274 
  275 #ifdef  db_printf_enter
  276         db_printf_enter();      /* optional multiP serialization */
  277 #endif
  278         va_start(listp);
  279         _doprnt(fmt, &listp, db_id_putc, db_radix, 0);
  280         va_end(listp);
  281 }
  282 
  283 /* alternate name */
  284 
  285 /*VARARGS1*/
  286 void
  287 kdbprintf(fmt, va_alist)
  288         char *  fmt;
  289         va_dcl
  290 {
  291         va_list listp;
  292         va_start(listp);
  293         _doprnt(fmt, &listp, db_id_putc, db_radix, 0);
  294         va_end(listp);
  295 }

Cache object: 0eb0be5bee439b08cc3c15804ca60e55


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.