* Copyright (c) 1991,1990 Carnegie Mellon University
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
* Carnegie Mellon requests users of this software to return to
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
* $Id: db_output.c,v 1.5 1993/11/25 01:30:08 wollman Exp $
* Author: David B. Golub, Carnegie Mellon University
* Printf and character output for debugger.
#include "machine/stdarg.h"
#include "machine/cons.h"
* Character output - tracks position in line.
* To do this correctly, we should know how wide
* the output device is - then we could zero
* the line position when the output device wraps
* around to the start of the next line.
* Instead, we count the number of spaces printed
* since the last printing character so that we
* don't print trailing spaces. This avoids most
int db_output_position
= 0; /* output column */
int db_last_non_space
= 0; /* last non-space character */
int db_tab_stop_width
= 8; /* how wide are tab stops? */
((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
int db_max_width
= 80; /* output line width */
static void db_printf_guts(const char *, va_list);
* Force pending whitespace.
register int last_print
, next_tab
;
last_print
= db_last_non_space
;
while (last_print
< db_output_position
) {
next_tab
= NEXT_TAB(last_print
);
if (next_tab
<= db_output_position
) {
while (last_print
< next_tab
) { /* DON'T send a tab!!! */
db_last_non_space
= db_output_position
;
* Output character. Buffer whitespace.
int c
; /* character to output */
if (c
> ' ' && c
<= '~') {
* If we have spaces to print, print them first.
db_last_non_space
= db_output_position
;
/* assume tabs every 8 positions */
db_output_position
= NEXT_TAB(db_output_position
);
/* other characters are assumed non-printing */
return (db_output_position
);
db_printf(const char *fmt
, ...)
db_printf_guts (fmt
, listp
);
kdbprintf(char *fmt
, ...)
db_printf_guts (fmt
, listp
);
if (db_output_position
>= db_max_width
)
* Put a number (base <= 16) in a buffer in reverse order; return an
* optional length and a pointer to the NULL terminated (preceded?)
db_ksprintn(ul
, base
, lenp
)
register int base
, *lenp
;
{ /* A long in base 8, plus NULL. */
static char buf
[sizeof(long) * NBBY
/ 3 + 2];
*++p
= "0123456789abcdef"[ul
% base
];
register const char *fmt
;
int base
, lflag
, tmp
, width
;
while ((ch
= *(u_char
*)fmt
++) != '%') {
reswitch
: switch (ch
= *(u_char
*)fmt
++) {
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
for (width
= 0;; ++fmt
) {
width
= width
* 10 + ch
- '0';
if (ch
< '0' || ch
> '9')
for (p
= db_ksprintn(ul
, *p
++, NULL
); ch
= *p
--;)
for (tmp
= 0; n
= *p
++;) {
if (ul
& (1 << (n
- 1))) {
db_putchar(tmp
? ',' : '<');
for (; (n
= *p
) > ' '; ++p
)
width
= va_arg (ap
, int);
db_putchar(va_arg(ap
, int));
if (!ladjust
&& width
> 0)
if (ladjust
&& width
> 0)
ul
= lflag
? va_arg(ap
, u_long
) : va_arg(ap
, u_int
);
if (base
< 8 || base
> 16)
ul
= lflag
? va_arg(ap
, u_long
) : va_arg(ap
, u_int
);
if (base
< 8 || base
> 16)
ul
= lflag
? va_arg(ap
, long) : va_arg(ap
, int);
ul
= lflag
? va_arg(ap
, u_long
) : va_arg(ap
, u_int
);
ul
= lflag
? va_arg(ap
, u_long
) : va_arg(ap
, u_int
);
ul
= lflag
? va_arg(ap
, u_long
) : va_arg(ap
, u_int
);
ul
= lflag
? va_arg(ap
, u_long
) : va_arg(ap
, u_int
);
number
: p
= (char *)db_ksprintn(ul
, base
, &tmp
);
if (sharpflag
&& ul
!= 0) {
if (!ladjust
&& width
&& (width
-= tmp
) > 0)
if (sharpflag
&& ul
!= 0) {
if (ladjust
&& width
&& (width
-= tmp
) > 0)