]>
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 * 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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * Mach Operating System
28 * Copyright (c) 1991,1990 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
54 * Author: David B. Golub, Carnegie Mellon University
59 * Printf and character output for debugger.
62 #include <mach/boolean.h>
63 #include <kern/misc_protos.h>
65 #include <machine/db_machdep.h>
66 #include <ddb/db_command.h>
67 #include <ddb/db_lex.h>
68 #include <ddb/db_input.h>
69 #include <ddb/db_output.h>
70 #include <ddb/db_task_thread.h>
73 * Character output - tracks position in line.
74 * To do this correctly, we should know how wide
75 * the output device is - then we could zero
76 * the line position when the output device wraps
77 * around to the start of the next line.
79 * Instead, we count the number of spaces printed
80 * since the last printing character so that we
81 * don't print trailing spaces. This avoids most
86 #define DB_MAX_LINE 43 /* maximum line */
87 #define DB_MAX_WIDTH 132 /* maximum width */
88 #endif /* DB_MAX_LINE */
90 #define DB_MIN_MAX_WIDTH 20 /* minimum max width */
91 #define DB_MIN_MAX_LINE 3 /* minimum max line */
92 #define CTRL(c) ((c) & 0xff)
94 int db_output_position
= 0; /* output column */
95 int db_output_line
= 0; /* output line number */
96 int db_last_non_space
= 0; /* last non-space character */
97 int db_last_gen_return
= 0; /* last character generated return */
98 int db_auto_wrap
= 1; /* auto wrap at end of line ? */
99 int db_tab_stop_width
= 8; /* how wide are tab stops? */
100 #define NEXT_TAB(i) \
101 ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
102 int db_max_line
= DB_MAX_LINE
; /* output max lines */
103 int db_max_width
= DB_MAX_WIDTH
; /* output line width */
106 /* Prototypes for functions local to this file. XXX -- should be static!
108 static void db_more(void);
109 void db_advance_output_position(int new_output_position
,
114 * Force pending whitespace.
117 db_force_whitespace(void)
119 register int last_print
, next_tab
;
121 last_print
= db_last_non_space
;
122 while (last_print
< db_output_position
) {
123 next_tab
= NEXT_TAB(last_print
);
124 if (next_tab
<= db_output_position
) {
126 last_print
= next_tab
;
133 db_last_non_space
= db_output_position
;
146 boolean_t quit_output
= FALSE
;
148 for (p
= "--db_more--"; *p
; p
++)
163 p
= "\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b";
167 db_error((char *) 0);
173 db_advance_output_position(int new_output_position
,
176 if (db_max_width
>= DB_MIN_MAX_WIDTH
177 && new_output_position
>= db_max_width
) {
179 if (!db_auto_wrap
|| blank
)
181 db_output_position
= 0;
182 db_last_non_space
= 0;
183 db_last_gen_return
= 1;
186 db_output_position
= new_output_position
;
191 db_reserve_output_position(int increment
)
193 if (db_max_width
>= DB_MIN_MAX_WIDTH
194 && db_output_position
+ increment
>= db_max_width
) {
196 if (!db_auto_wrap
|| db_last_non_space
!= db_output_position
)
198 db_output_position
= 0;
199 db_last_non_space
= 0;
200 db_last_gen_return
= 1;
208 * Output character. Buffer whitespace.
213 if (db_max_line
>= DB_MIN_MAX_LINE
&& db_output_line
>= db_max_line
-1)
215 if (c
> ' ' && c
<= '~') {
217 * Printing character.
218 * If we have spaces to print, print them first.
219 * Use tabs if possible.
221 db_force_whitespace();
223 db_last_gen_return
= 0;
224 db_advance_output_position(db_output_position
+1, 0);
225 db_last_non_space
= db_output_position
;
227 else if (c
== '\n') {
229 if (db_last_gen_return
) {
230 db_last_gen_return
= 0;
233 db_output_position
= 0;
234 db_last_non_space
= 0;
236 db_check_interrupt();
239 else if (c
== '\t') {
240 /* assume tabs every 8 positions */
241 db_advance_output_position(NEXT_TAB(db_output_position
), 1);
245 db_advance_output_position(db_output_position
+1, 1);
247 else if (c
== '\007') {
251 /* other characters are assumed non-printing */
255 * Return output position
258 db_print_position(void)
260 return (db_output_position
);
264 * End line if too long.
269 if (db_output_position
>= db_max_width
-1) {
273 db_output_position
= 0;
274 db_last_non_space
= 0;
275 db_last_gen_return
= 1;
285 db_printf(const char *fmt
, ...)
289 va_start(listp
, fmt
);
290 _doprnt(fmt
, &listp
, db_putchar
, db_radix
);
297 kdbprintf(const char *fmt
, ...)
301 va_start(listp
, fmt
);
302 _doprnt(fmt
, &listp
, db_putchar
, db_radix
);
309 * Printing (to console) with indentation.
312 iprintf(const char *fmt
, ...)
317 for (i
= db_indent
; i
> 0; ){
328 va_start(listp
, fmt
);
329 _doprnt(fmt
, &listp
, db_putchar
, db_radix
);
334 db_output_prompt(void)
336 db_printf("db%s", (db_default_act
) ? "t": "");
337 db_printf("{%d}", cpu_number());