]>
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_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
59 * Author: David B. Golub, Carnegie Mellon University
64 * Printf and character output for debugger.
67 #include <mach/boolean.h>
68 #include <kern/misc_protos.h>
70 #include <machine/db_machdep.h>
71 #include <ddb/db_command.h>
72 #include <ddb/db_lex.h>
73 #include <ddb/db_input.h>
74 #include <ddb/db_output.h>
75 #include <ddb/db_task_thread.h>
78 * Character output - tracks position in line.
79 * To do this correctly, we should know how wide
80 * the output device is - then we could zero
81 * the line position when the output device wraps
82 * around to the start of the next line.
84 * Instead, we count the number of spaces printed
85 * since the last printing character so that we
86 * don't print trailing spaces. This avoids most
91 #define DB_MAX_LINE 43 /* maximum line */
92 #define DB_MAX_WIDTH 132 /* maximum width */
93 #endif /* DB_MAX_LINE */
95 #define DB_MIN_MAX_WIDTH 20 /* minimum max width */
96 #define DB_MIN_MAX_LINE 3 /* minimum max line */
97 #define CTRL(c) ((c) & 0xff)
99 int db_output_position
= 0; /* output column */
100 int db_output_line
= 0; /* output line number */
101 int db_last_non_space
= 0; /* last non-space character */
102 int db_last_gen_return
= 0; /* last character generated return */
103 int db_auto_wrap
= 1; /* auto wrap at end of line ? */
104 int db_tab_stop_width
= 8; /* how wide are tab stops? */
105 #define NEXT_TAB(i) \
106 ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
107 int db_max_line
= DB_MAX_LINE
; /* output max lines */
108 int db_max_width
= DB_MAX_WIDTH
; /* output line width */
111 /* Prototypes for functions local to this file. XXX -- should be static!
113 static void db_more(void);
114 void db_advance_output_position(int new_output_position
,
119 * Force pending whitespace.
122 db_force_whitespace(void)
124 register int last_print
, next_tab
;
126 last_print
= db_last_non_space
;
127 while (last_print
< db_output_position
) {
128 next_tab
= NEXT_TAB(last_print
);
129 if (next_tab
<= db_output_position
) {
131 last_print
= next_tab
;
138 db_last_non_space
= db_output_position
;
151 boolean_t quit_output
= FALSE
;
153 for (p
= "--db_more--"; *p
; p
++)
168 p
= "\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b";
172 db_error((char *) 0);
178 db_advance_output_position(int new_output_position
,
181 if (db_max_width
>= DB_MIN_MAX_WIDTH
182 && new_output_position
>= db_max_width
) {
184 if (!db_auto_wrap
|| blank
)
186 db_output_position
= 0;
187 db_last_non_space
= 0;
188 db_last_gen_return
= 1;
191 db_output_position
= new_output_position
;
196 db_reserve_output_position(int increment
)
198 if (db_max_width
>= DB_MIN_MAX_WIDTH
199 && db_output_position
+ increment
>= db_max_width
) {
201 if (!db_auto_wrap
|| db_last_non_space
!= db_output_position
)
203 db_output_position
= 0;
204 db_last_non_space
= 0;
205 db_last_gen_return
= 1;
213 * Output character. Buffer whitespace.
218 if (db_max_line
>= DB_MIN_MAX_LINE
&& db_output_line
>= db_max_line
-1)
220 if (c
> ' ' && c
<= '~') {
222 * Printing character.
223 * If we have spaces to print, print them first.
224 * Use tabs if possible.
226 db_force_whitespace();
228 db_last_gen_return
= 0;
229 db_advance_output_position(db_output_position
+1, 0);
230 db_last_non_space
= db_output_position
;
232 else if (c
== '\n') {
234 if (db_last_gen_return
) {
235 db_last_gen_return
= 0;
238 db_output_position
= 0;
239 db_last_non_space
= 0;
241 db_check_interrupt();
244 else if (c
== '\t') {
245 /* assume tabs every 8 positions */
246 db_advance_output_position(NEXT_TAB(db_output_position
), 1);
250 db_advance_output_position(db_output_position
+1, 1);
252 else if (c
== '\007') {
256 /* other characters are assumed non-printing */
260 * Return output position
263 db_print_position(void)
265 return (db_output_position
);
269 * End line if too long.
274 if (db_output_position
>= db_max_width
-1) {
278 db_output_position
= 0;
279 db_last_non_space
= 0;
280 db_last_gen_return
= 1;
290 db_printf(const char *fmt
, ...)
294 va_start(listp
, fmt
);
295 _doprnt(fmt
, &listp
, db_putchar
, db_radix
);
302 kdbprintf(const char *fmt
, ...)
306 va_start(listp
, fmt
);
307 _doprnt(fmt
, &listp
, db_putchar
, db_radix
);
314 * Printing (to console) with indentation.
317 iprintf(const char *fmt
, ...)
322 for (i
= db_indent
; i
> 0; ){
333 va_start(listp
, fmt
);
334 _doprnt(fmt
, &listp
, db_putchar
, db_radix
);
339 db_output_prompt(void)
341 db_printf("db%s", (db_default_act
) ? "t": "");
342 db_printf("{%d}", cpu_number());