]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
d7e50217 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
d7e50217 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
d7e50217 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * @OSF_COPYRIGHT@ | |
27 | */ | |
28 | /* | |
29 | * Mach Operating System | |
30 | * Copyright (c) 1991,1990 Carnegie Mellon University | |
31 | * All Rights Reserved. | |
32 | * | |
33 | * Permission to use, copy, modify and distribute this software and its | |
34 | * documentation is hereby granted, provided that both the copyright | |
35 | * notice and this permission notice appear in all copies of the | |
36 | * software, derivative works or modified versions, and any portions | |
37 | * thereof, and that both notices appear in supporting documentation. | |
38 | * | |
39 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
40 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
41 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
42 | * | |
43 | * Carnegie Mellon requests users of this software to return to | |
44 | * | |
45 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
46 | * School of Computer Science | |
47 | * Carnegie Mellon University | |
48 | * Pittsburgh PA 15213-3890 | |
49 | * | |
50 | * any improvements or extensions that they make and grant Carnegie Mellon | |
51 | * the rights to redistribute these changes. | |
52 | */ | |
53 | /* | |
54 | */ | |
55 | /* | |
56 | * Author: David B. Golub, Carnegie Mellon University | |
57 | * Date: 7/90 | |
58 | */ | |
59 | ||
60 | /* | |
61 | * Printf and character output for debugger. | |
62 | */ | |
63 | ||
64 | #include <mach/boolean.h> | |
65 | #include <kern/misc_protos.h> | |
66 | #include <stdarg.h> | |
67 | #include <machine/db_machdep.h> | |
68 | #include <ddb/db_command.h> | |
69 | #include <ddb/db_lex.h> | |
70 | #include <ddb/db_input.h> | |
71 | #include <ddb/db_output.h> | |
72 | #include <ddb/db_task_thread.h> | |
73 | ||
74 | /* | |
75 | * Character output - tracks position in line. | |
76 | * To do this correctly, we should know how wide | |
77 | * the output device is - then we could zero | |
78 | * the line position when the output device wraps | |
79 | * around to the start of the next line. | |
80 | * | |
81 | * Instead, we count the number of spaces printed | |
82 | * since the last printing character so that we | |
83 | * don't print trailing spaces. This avoids most | |
84 | * of the wraparounds. | |
85 | */ | |
86 | ||
87 | #ifndef DB_MAX_LINE | |
d7e50217 | 88 | #define DB_MAX_LINE 43 /* maximum line */ |
1c79356b A |
89 | #define DB_MAX_WIDTH 132 /* maximum width */ |
90 | #endif /* DB_MAX_LINE */ | |
91 | ||
92 | #define DB_MIN_MAX_WIDTH 20 /* minimum max width */ | |
93 | #define DB_MIN_MAX_LINE 3 /* minimum max line */ | |
94 | #define CTRL(c) ((c) & 0xff) | |
95 | ||
96 | int db_output_position = 0; /* output column */ | |
97 | int db_output_line = 0; /* output line number */ | |
98 | int db_last_non_space = 0; /* last non-space character */ | |
99 | int db_last_gen_return = 0; /* last character generated return */ | |
100 | int db_auto_wrap = 1; /* auto wrap at end of line ? */ | |
101 | int db_tab_stop_width = 8; /* how wide are tab stops? */ | |
102 | #define NEXT_TAB(i) \ | |
103 | ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width) | |
104 | int db_max_line = DB_MAX_LINE; /* output max lines */ | |
105 | int db_max_width = DB_MAX_WIDTH; /* output line width */ | |
106 | ||
107 | ||
108 | /* Prototypes for functions local to this file. XXX -- should be static! | |
109 | */ | |
110 | static void db_more(void); | |
111 | void db_advance_output_position(int new_output_position, | |
112 | int blank); | |
113 | ||
114 | ||
115 | /* | |
116 | * Force pending whitespace. | |
117 | */ | |
118 | void | |
119 | db_force_whitespace(void) | |
120 | { | |
121 | register int last_print, next_tab; | |
122 | ||
123 | last_print = db_last_non_space; | |
124 | while (last_print < db_output_position) { | |
125 | next_tab = NEXT_TAB(last_print); | |
126 | if (next_tab <= db_output_position) { | |
127 | cnputc('\t'); | |
128 | last_print = next_tab; | |
129 | } | |
130 | else { | |
131 | cnputc(' '); | |
132 | last_print++; | |
133 | } | |
134 | } | |
135 | db_last_non_space = db_output_position; | |
136 | } | |
137 | ||
138 | void | |
139 | db_reset_more() | |
140 | { | |
141 | db_output_line = 0; | |
142 | } | |
143 | ||
144 | static void | |
145 | db_more(void) | |
146 | { | |
147 | register char *p; | |
148 | boolean_t quit_output = FALSE; | |
149 | ||
1c79356b A |
150 | for (p = "--db_more--"; *p; p++) |
151 | cnputc(*p); | |
152 | switch(cngetc()) { | |
153 | case ' ': | |
154 | db_output_line = 0; | |
155 | break; | |
156 | case 'q': | |
157 | case CTRL('c'): | |
158 | db_output_line = 0; | |
159 | quit_output = TRUE; | |
160 | break; | |
161 | default: | |
162 | db_output_line--; | |
163 | break; | |
164 | } | |
165 | p = "\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b"; | |
166 | while (*p) | |
167 | cnputc(*p++); | |
168 | if (quit_output) { | |
169 | db_error((char *) 0); | |
170 | /* NOTREACHED */ | |
171 | } | |
172 | } | |
173 | ||
174 | void | |
175 | db_advance_output_position(int new_output_position, | |
176 | int blank) | |
177 | { | |
178 | if (db_max_width >= DB_MIN_MAX_WIDTH | |
179 | && new_output_position >= db_max_width) { | |
180 | /* auto new line */ | |
181 | if (!db_auto_wrap || blank) | |
182 | cnputc('\n'); | |
183 | db_output_position = 0; | |
184 | db_last_non_space = 0; | |
185 | db_last_gen_return = 1; | |
186 | db_output_line++; | |
187 | } else { | |
188 | db_output_position = new_output_position; | |
189 | } | |
190 | } | |
191 | ||
192 | boolean_t | |
193 | db_reserve_output_position(int increment) | |
194 | { | |
195 | if (db_max_width >= DB_MIN_MAX_WIDTH | |
196 | && db_output_position + increment >= db_max_width) { | |
197 | /* auto new line */ | |
198 | if (!db_auto_wrap || db_last_non_space != db_output_position) | |
199 | cnputc('\n'); | |
200 | db_output_position = 0; | |
201 | db_last_non_space = 0; | |
202 | db_last_gen_return = 1; | |
203 | db_output_line++; | |
204 | return TRUE; | |
205 | } | |
206 | return FALSE; | |
207 | } | |
208 | ||
209 | /* | |
210 | * Output character. Buffer whitespace. | |
211 | */ | |
212 | void | |
213 | db_putchar(char c) | |
214 | { | |
215 | if (db_max_line >= DB_MIN_MAX_LINE && db_output_line >= db_max_line-1) | |
216 | db_more(); | |
217 | if (c > ' ' && c <= '~') { | |
218 | /* | |
219 | * Printing character. | |
220 | * If we have spaces to print, print them first. | |
221 | * Use tabs if possible. | |
222 | */ | |
223 | db_force_whitespace(); | |
224 | cnputc(c); | |
225 | db_last_gen_return = 0; | |
226 | db_advance_output_position(db_output_position+1, 0); | |
227 | db_last_non_space = db_output_position; | |
228 | } | |
229 | else if (c == '\n') { | |
230 | /* Return */ | |
231 | if (db_last_gen_return) { | |
232 | db_last_gen_return = 0; | |
233 | } else { | |
234 | cnputc(c); | |
235 | db_output_position = 0; | |
236 | db_last_non_space = 0; | |
237 | db_output_line++; | |
238 | db_check_interrupt(); | |
239 | } | |
240 | } | |
241 | else if (c == '\t') { | |
242 | /* assume tabs every 8 positions */ | |
243 | db_advance_output_position(NEXT_TAB(db_output_position), 1); | |
244 | } | |
245 | else if (c == ' ') { | |
246 | /* space */ | |
247 | db_advance_output_position(db_output_position+1, 1); | |
248 | } | |
249 | else if (c == '\007') { | |
250 | /* bell */ | |
251 | cnputc(c); | |
252 | } | |
253 | /* other characters are assumed non-printing */ | |
254 | } | |
255 | ||
256 | /* | |
257 | * Return output position | |
258 | */ | |
259 | int | |
260 | db_print_position(void) | |
261 | { | |
262 | return (db_output_position); | |
263 | } | |
264 | ||
265 | /* | |
266 | * End line if too long. | |
267 | */ | |
268 | void | |
269 | db_end_line(void) | |
270 | { | |
271 | if (db_output_position >= db_max_width-1) { | |
272 | /* auto new line */ | |
273 | if (!db_auto_wrap) | |
274 | cnputc('\n'); | |
275 | db_output_position = 0; | |
276 | db_last_non_space = 0; | |
277 | db_last_gen_return = 1; | |
278 | db_output_line++; | |
279 | } | |
280 | } | |
281 | ||
282 | /* | |
283 | * Printing | |
284 | */ | |
285 | ||
286 | void | |
287 | db_printf(char *fmt, ...) | |
288 | { | |
289 | va_list listp; | |
290 | ||
1c79356b A |
291 | va_start(listp, fmt); |
292 | _doprnt(fmt, &listp, db_putchar, db_radix); | |
293 | va_end(listp); | |
294 | } | |
295 | ||
296 | /* alternate name */ | |
297 | ||
298 | void | |
299 | kdbprintf(char *fmt, ...) | |
300 | { | |
301 | va_list listp; | |
302 | ||
303 | va_start(listp, fmt); | |
304 | _doprnt(fmt, &listp, db_putchar, db_radix); | |
305 | va_end(listp); | |
306 | } | |
307 | ||
308 | int db_indent = 0; | |
309 | ||
310 | /* | |
311 | * Printing (to console) with indentation. | |
312 | */ | |
313 | void | |
314 | iprintf(char *fmt, ...) | |
315 | { | |
316 | va_list listp; | |
317 | register int i; | |
318 | ||
319 | for (i = db_indent; i > 0; ){ | |
320 | if (i >= 8) { | |
321 | kdbprintf("\t"); | |
322 | i -= 8; | |
323 | } | |
324 | else { | |
325 | kdbprintf(" "); | |
326 | i--; | |
327 | } | |
328 | } | |
329 | ||
330 | va_start(listp, fmt); | |
331 | _doprnt(fmt, &listp, db_putchar, db_radix); | |
332 | va_end(listp); | |
333 | } | |
334 | ||
335 | void | |
336 | db_output_prompt(void) | |
337 | { | |
338 | db_printf("db%s", (db_default_act) ? "t": ""); | |
1c79356b | 339 | db_printf("{%d}", cpu_number()); |
1c79356b A |
340 | db_printf("> "); |
341 | } | |
342 |