]>
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_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
61 * Author: David B. Golub, Carnegie Mellon University
66 * Printf and character output for debugger.
69 #include <mach/boolean.h>
70 #include <kern/misc_protos.h>
72 #include <machine/db_machdep.h>
73 #include <ddb/db_command.h>
74 #include <ddb/db_lex.h>
75 #include <ddb/db_input.h>
76 #include <ddb/db_output.h>
77 #include <ddb/db_task_thread.h>
80 * Character output - tracks position in line.
81 * To do this correctly, we should know how wide
82 * the output device is - then we could zero
83 * the line position when the output device wraps
84 * around to the start of the next line.
86 * Instead, we count the number of spaces printed
87 * since the last printing character so that we
88 * don't print trailing spaces. This avoids most
93 #define DB_MAX_LINE 43 /* maximum line */
94 #define DB_MAX_WIDTH 132 /* maximum width */
95 #endif /* DB_MAX_LINE */
97 #define DB_MIN_MAX_WIDTH 20 /* minimum max width */
98 #define DB_MIN_MAX_LINE 3 /* minimum max line */
99 #define CTRL(c) ((c) & 0xff)
101 int db_output_position
= 0; /* output column */
102 int db_output_line
= 0; /* output line number */
103 int db_last_non_space
= 0; /* last non-space character */
104 int db_last_gen_return
= 0; /* last character generated return */
105 int db_auto_wrap
= 1; /* auto wrap at end of line ? */
106 int db_tab_stop_width
= 8; /* how wide are tab stops? */
107 #define NEXT_TAB(i) \
108 ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
109 int db_max_line
= DB_MAX_LINE
; /* output max lines */
110 int db_max_width
= DB_MAX_WIDTH
; /* output line width */
113 /* Prototypes for functions local to this file. XXX -- should be static!
115 static void db_more(void);
116 void db_advance_output_position(int new_output_position
,
121 * Force pending whitespace.
124 db_force_whitespace(void)
126 register int last_print
, next_tab
;
128 last_print
= db_last_non_space
;
129 while (last_print
< db_output_position
) {
130 next_tab
= NEXT_TAB(last_print
);
131 if (next_tab
<= db_output_position
) {
133 last_print
= next_tab
;
140 db_last_non_space
= db_output_position
;
153 boolean_t quit_output
= FALSE
;
155 for (p
= "--db_more--"; *p
; p
++)
170 p
= "\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b";
174 db_error((char *) 0);
180 db_advance_output_position(int new_output_position
,
183 if (db_max_width
>= DB_MIN_MAX_WIDTH
184 && new_output_position
>= db_max_width
) {
186 if (!db_auto_wrap
|| blank
)
188 db_output_position
= 0;
189 db_last_non_space
= 0;
190 db_last_gen_return
= 1;
193 db_output_position
= new_output_position
;
198 db_reserve_output_position(int increment
)
200 if (db_max_width
>= DB_MIN_MAX_WIDTH
201 && db_output_position
+ increment
>= db_max_width
) {
203 if (!db_auto_wrap
|| db_last_non_space
!= db_output_position
)
205 db_output_position
= 0;
206 db_last_non_space
= 0;
207 db_last_gen_return
= 1;
215 * Output character. Buffer whitespace.
220 if (db_max_line
>= DB_MIN_MAX_LINE
&& db_output_line
>= db_max_line
-1)
222 if (c
> ' ' && c
<= '~') {
224 * Printing character.
225 * If we have spaces to print, print them first.
226 * Use tabs if possible.
228 db_force_whitespace();
230 db_last_gen_return
= 0;
231 db_advance_output_position(db_output_position
+1, 0);
232 db_last_non_space
= db_output_position
;
234 else if (c
== '\n') {
236 if (db_last_gen_return
) {
237 db_last_gen_return
= 0;
240 db_output_position
= 0;
241 db_last_non_space
= 0;
243 db_check_interrupt();
246 else if (c
== '\t') {
247 /* assume tabs every 8 positions */
248 db_advance_output_position(NEXT_TAB(db_output_position
), 1);
252 db_advance_output_position(db_output_position
+1, 1);
254 else if (c
== '\007') {
258 /* other characters are assumed non-printing */
262 * Return output position
265 db_print_position(void)
267 return (db_output_position
);
271 * End line if too long.
276 if (db_output_position
>= db_max_width
-1) {
280 db_output_position
= 0;
281 db_last_non_space
= 0;
282 db_last_gen_return
= 1;
292 db_printf(const char *fmt
, ...)
296 va_start(listp
, fmt
);
297 _doprnt(fmt
, &listp
, db_putchar
, db_radix
);
304 kdbprintf(const char *fmt
, ...)
308 va_start(listp
, fmt
);
309 _doprnt(fmt
, &listp
, db_putchar
, db_radix
);
316 * Printing (to console) with indentation.
319 iprintf(const char *fmt
, ...)
324 for (i
= db_indent
; i
> 0; ){
335 va_start(listp
, fmt
);
336 _doprnt(fmt
, &listp
, db_putchar
, db_radix
);
341 db_output_prompt(void)
343 db_printf("db%s", (db_default_act
) ? "t": "");
344 db_printf("{%d}", cpu_number());