2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
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.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
26 * $FreeBSD: src/sys/ddb/db_output.c,v 1.26 1999/08/28 00:41:09 peter Exp $
27 * $DragonFly: src/sys/ddb/db_output.c,v 1.5 2003/11/09 02:22:34 dillon Exp $
31 * Author: David B. Golub, Carnegie Mellon University
36 * Printf and character output for debugger.
39 #include <sys/param.h>
40 #include <sys/systm.h>
43 #include <machine/stdarg.h>
46 #include <ddb/db_output.h>
49 * Character output - tracks position in line.
50 * To do this correctly, we should know how wide
51 * the output device is - then we could zero
52 * the line position when the output device wraps
53 * around to the start of the next line.
55 * Instead, we count the number of spaces printed
56 * since the last printing character so that we
57 * don't print trailing spaces. This avoids most
60 static int db_output_position = 0; /* output column */
61 static int db_last_non_space = 0; /* last non-space character */
62 db_expr_t db_tab_stop_width = 8; /* how wide are tab stops? */
64 ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
65 db_expr_t db_max_width = 79; /* output line width */
67 static void db_putchar (int c, void *arg);
70 * Force pending whitespace.
75 int last_print, next_tab;
77 last_print = db_last_non_space;
78 while (last_print < db_output_position) {
79 next_tab = NEXT_TAB(last_print);
80 if (next_tab <= db_output_position) {
81 while (last_print < next_tab) { /* DON'T send a tab!!! */
91 db_last_non_space = db_output_position;
95 * Output character. Buffer whitespace.
99 int c; /* character to output */
102 if (c > ' ' && c <= '~') {
104 * Printing character.
105 * If we have spaces to print, print them first.
106 * Use tabs if possible.
108 db_force_whitespace();
110 db_output_position++;
111 db_last_non_space = db_output_position;
113 else if (c == '\n') {
116 db_output_position = 0;
117 db_last_non_space = 0;
118 db_check_interrupt();
120 else if (c == '\r') {
123 db_output_position = 0;
124 db_last_non_space = 0;
125 db_check_interrupt();
127 else if (c == '\t') {
128 /* assume tabs every 8 positions */
129 db_output_position = NEXT_TAB(db_output_position);
133 db_output_position++;
135 else if (c == '\007') {
139 /* other characters are assumed non-printing */
143 * Return output position
148 return (db_output_position);
155 db_printf(const char *fmt, ...)
159 __va_start(listp, fmt);
160 kvprintf (fmt, db_putchar, NULL, db_radix, listp);
167 db_iprintf(const char *fmt,...)
172 for (i = db_indent; i >= 8; i -= 8)
176 __va_start(listp, fmt);
177 kvprintf (fmt, db_putchar, NULL, db_radix, listp);
182 * End line if too long.
187 if (db_output_position >= db_max_width)