]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ddb/db_output.c
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
53 * Author: David B. Golub, Carnegie Mellon University
58 * Printf and character output for debugger.
61 #include <mach/boolean.h>
62 #include <kern/misc_protos.h>
64 #include <machine/db_machdep.h>
65 #include <ddb/db_command.h>
66 #include <ddb/db_lex.h>
67 #include <ddb/db_input.h>
68 #include <ddb/db_output.h>
69 #include <ddb/db_task_thread.h>
72 * Character output - tracks position in line.
73 * To do this correctly, we should know how wide
74 * the output device is - then we could zero
75 * the line position when the output device wraps
76 * around to the start of the next line.
78 * Instead, we count the number of spaces printed
79 * since the last printing character so that we
80 * don't print trailing spaces. This avoids most
85 #define DB_MAX_LINE 43 /* maximum line */
86 #define DB_MAX_WIDTH 132 /* maximum width */
87 #endif /* DB_MAX_LINE */
89 #define DB_MIN_MAX_WIDTH 20 /* minimum max width */
90 #define DB_MIN_MAX_LINE 3 /* minimum max line */
91 #define CTRL(c) ((c) & 0xff)
93 int db_output_position
= 0; /* output column */
94 int db_output_line
= 0; /* output line number */
95 int db_last_non_space
= 0; /* last non-space character */
96 int db_last_gen_return
= 0; /* last character generated return */
97 int db_auto_wrap
= 1; /* auto wrap at end of line ? */
98 int db_tab_stop_width
= 8; /* how wide are tab stops? */
100 ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
101 int db_max_line
= DB_MAX_LINE
; /* output max lines */
102 int db_max_width
= DB_MAX_WIDTH
; /* output line width */
105 /* Prototypes for functions local to this file. XXX -- should be static!
107 static void db_more(void);
108 void db_advance_output_position(int new_output_position
,
113 * Force pending whitespace.
116 db_force_whitespace(void)
118 register int last_print
, next_tab
;
120 last_print
= db_last_non_space
;
121 while (last_print
< db_output_position
) {
122 next_tab
= NEXT_TAB(last_print
);
123 if (next_tab
<= db_output_position
) {
125 last_print
= next_tab
;
132 db_last_non_space
= db_output_position
;
145 boolean_t quit_output
= FALSE
;
147 for (p
= "--db_more--"; *p
; p
++)
162 p
= "\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b";
166 db_error((char *) 0);
172 db_advance_output_position(int new_output_position
,
175 if (db_max_width
>= DB_MIN_MAX_WIDTH
176 && new_output_position
>= db_max_width
) {
178 if (!db_auto_wrap
|| blank
)
180 db_output_position
= 0;
181 db_last_non_space
= 0;
182 db_last_gen_return
= 1;
185 db_output_position
= new_output_position
;
190 db_reserve_output_position(int increment
)
192 if (db_max_width
>= DB_MIN_MAX_WIDTH
193 && db_output_position
+ increment
>= db_max_width
) {
195 if (!db_auto_wrap
|| db_last_non_space
!= db_output_position
)
197 db_output_position
= 0;
198 db_last_non_space
= 0;
199 db_last_gen_return
= 1;
207 * Output character. Buffer whitespace.
212 if (db_max_line
>= DB_MIN_MAX_LINE
&& db_output_line
>= db_max_line
-1)
214 if (c
> ' ' && c
<= '~') {
216 * Printing character.
217 * If we have spaces to print, print them first.
218 * Use tabs if possible.
220 db_force_whitespace();
222 db_last_gen_return
= 0;
223 db_advance_output_position(db_output_position
+1, 0);
224 db_last_non_space
= db_output_position
;
226 else if (c
== '\n') {
228 if (db_last_gen_return
) {
229 db_last_gen_return
= 0;
232 db_output_position
= 0;
233 db_last_non_space
= 0;
235 db_check_interrupt();
238 else if (c
== '\t') {
239 /* assume tabs every 8 positions */
240 db_advance_output_position(NEXT_TAB(db_output_position
), 1);
244 db_advance_output_position(db_output_position
+1, 1);
246 else if (c
== '\007') {
250 /* other characters are assumed non-printing */
254 * Return output position
257 db_print_position(void)
259 return (db_output_position
);
263 * End line if too long.
268 if (db_output_position
>= db_max_width
-1) {
272 db_output_position
= 0;
273 db_last_non_space
= 0;
274 db_last_gen_return
= 1;
284 db_printf(const char *fmt
, ...)
288 va_start(listp
, fmt
);
289 _doprnt(fmt
, &listp
, db_putchar
, db_radix
);
296 kdbprintf(const char *fmt
, ...)
300 va_start(listp
, fmt
);
301 _doprnt(fmt
, &listp
, db_putchar
, db_radix
);
308 * Printing (to console) with indentation.
311 iprintf(const char *fmt
, ...)
316 for (i
= db_indent
; i
> 0; ){
327 va_start(listp
, fmt
);
328 _doprnt(fmt
, &listp
, db_putchar
, db_radix
);
333 db_output_prompt(void)
335 db_printf("db%s", (db_default_act
) ? "t": "");
336 db_printf("{%d}", cpu_number());