1995-05-30 08:16:23 +00:00
|
|
|
/*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Mach Operating System
|
|
|
|
* Copyright (c) 1991,1990 Carnegie Mellon University
|
|
|
|
* All Rights Reserved.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* 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.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
|
1993-06-12 14:58:17 +00:00
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Carnegie Mellon requests users of this software to return to
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Author: David B. Golub, Carnegie Mellon University
|
|
|
|
* Date: 7/90
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Printf and character output for debugger.
|
|
|
|
*/
|
|
|
|
|
2003-06-10 22:09:23 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1999-08-09 10:35:05 +00:00
|
|
|
#include <sys/cons.h>
|
2004-07-10 23:47:20 +00:00
|
|
|
#include <sys/kdb.h>
|
2004-01-28 06:51:18 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/sysctl.h>
|
1995-12-10 19:08:32 +00:00
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <machine/stdarg.h>
|
1995-12-10 19:08:32 +00:00
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <ddb/ddb.h>
|
1995-11-24 14:13:42 +00:00
|
|
|
#include <ddb/db_output.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* of the wraparounds.
|
|
|
|
*/
|
1995-11-29 10:25:50 +00:00
|
|
|
static int db_output_position = 0; /* output column */
|
|
|
|
static int db_last_non_space = 0; /* last non-space character */
|
1998-07-08 09:11:43 +00:00
|
|
|
db_expr_t db_tab_stop_width = 8; /* how wide are tab stops? */
|
1993-06-12 14:58:17 +00:00
|
|
|
#define NEXT_TAB(i) \
|
|
|
|
((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
|
1998-07-08 09:11:43 +00:00
|
|
|
db_expr_t db_max_width = 79; /* output line width */
|
2003-07-31 17:27:52 +00:00
|
|
|
static int db_newlines; /* # lines this page */
|
|
|
|
static int db_maxlines = -1; /* max lines per page */
|
|
|
|
static db_page_calloutfcn_t *db_page_callout = NULL;
|
|
|
|
static void *db_page_callout_arg = NULL;
|
2004-01-28 06:51:18 +00:00
|
|
|
static int ddb_use_printf = 0;
|
|
|
|
SYSCTL_INT(_debug, OID_AUTO, ddb_use_printf, CTLFLAG_RW, &ddb_use_printf, 0,
|
|
|
|
"use printf for all ddb output");
|
1993-06-12 14:58:17 +00:00
|
|
|
|
2004-01-28 06:51:18 +00:00
|
|
|
static void db_putchar(int c, void *arg);
|
1996-05-08 04:29:08 +00:00
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
/*
|
|
|
|
* Force pending whitespace.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
db_force_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!!! */
|
|
|
|
cnputc(' ');
|
|
|
|
last_print++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cnputc(' ');
|
|
|
|
last_print++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
db_last_non_space = db_output_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Output character. Buffer whitespace.
|
|
|
|
*/
|
1996-05-08 04:29:08 +00:00
|
|
|
static void
|
|
|
|
db_putchar(c, arg)
|
1993-06-12 14:58:17 +00:00
|
|
|
int c; /* character to output */
|
1996-05-08 04:29:08 +00:00
|
|
|
void * arg;
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
2003-07-31 17:27:52 +00:00
|
|
|
|
2004-01-28 06:51:18 +00:00
|
|
|
/*
|
|
|
|
* If not in the debugger or the user requests it, output data to
|
|
|
|
* both the console and the message buffer.
|
|
|
|
*/
|
2004-07-10 23:47:20 +00:00
|
|
|
if (!kdb_active || ddb_use_printf) {
|
2004-01-28 06:51:18 +00:00
|
|
|
printf("%c", c);
|
2004-07-10 23:47:20 +00:00
|
|
|
if (!kdb_active)
|
2004-01-28 06:51:18 +00:00
|
|
|
return;
|
|
|
|
if (c == '\r' || c == '\n')
|
|
|
|
db_check_interrupt();
|
|
|
|
if (c == '\n' && db_maxlines > 0 && db_page_callout != NULL) {
|
|
|
|
db_newlines++;
|
|
|
|
if (db_newlines >= db_maxlines) {
|
|
|
|
db_maxlines = -1;
|
|
|
|
db_page_callout(db_page_callout_arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, output data directly to the console. */
|
1993-06-12 14:58:17 +00:00
|
|
|
if (c > ' ' && c <= '~') {
|
|
|
|
/*
|
|
|
|
* Printing character.
|
|
|
|
* If we have spaces to print, print them first.
|
|
|
|
* Use tabs if possible.
|
|
|
|
*/
|
|
|
|
db_force_whitespace();
|
|
|
|
cnputc(c);
|
|
|
|
db_output_position++;
|
|
|
|
db_last_non_space = db_output_position;
|
|
|
|
}
|
|
|
|
else if (c == '\n') {
|
1994-08-27 16:14:39 +00:00
|
|
|
/* Newline */
|
|
|
|
cnputc(c);
|
|
|
|
db_output_position = 0;
|
|
|
|
db_last_non_space = 0;
|
|
|
|
db_check_interrupt();
|
2003-07-31 17:27:52 +00:00
|
|
|
if (db_maxlines > 0 && db_page_callout != NULL) {
|
|
|
|
db_newlines++;
|
|
|
|
if (db_newlines >= db_maxlines) {
|
|
|
|
db_maxlines = -1;
|
|
|
|
db_page_callout(db_page_callout_arg);
|
|
|
|
}
|
|
|
|
}
|
1994-08-27 16:14:39 +00:00
|
|
|
}
|
|
|
|
else if (c == '\r') {
|
1993-06-12 14:58:17 +00:00
|
|
|
/* Return */
|
|
|
|
cnputc(c);
|
|
|
|
db_output_position = 0;
|
|
|
|
db_last_non_space = 0;
|
|
|
|
db_check_interrupt();
|
|
|
|
}
|
|
|
|
else if (c == '\t') {
|
|
|
|
/* assume tabs every 8 positions */
|
|
|
|
db_output_position = NEXT_TAB(db_output_position);
|
|
|
|
}
|
|
|
|
else if (c == ' ') {
|
|
|
|
/* space */
|
|
|
|
db_output_position++;
|
|
|
|
}
|
|
|
|
else if (c == '\007') {
|
|
|
|
/* bell */
|
|
|
|
cnputc(c);
|
|
|
|
}
|
|
|
|
/* other characters are assumed non-printing */
|
|
|
|
}
|
|
|
|
|
2003-07-31 17:27:52 +00:00
|
|
|
/*
|
|
|
|
* Register callout for providing a pager for output.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
db_setup_paging(db_page_calloutfcn_t *callout, void *arg, int maxlines)
|
|
|
|
{
|
|
|
|
|
|
|
|
db_page_callout = callout;
|
|
|
|
db_page_callout_arg = arg;
|
|
|
|
db_maxlines = maxlines;
|
|
|
|
db_newlines = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A simple paging callout function. If the argument is not null, it
|
|
|
|
* points to an integer that will be set to 1 if the user asks to quit.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
db_simple_pager(void *arg)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
db_printf("--More--\r");
|
|
|
|
for (;;) {
|
|
|
|
c = cngetc();
|
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
|
|
|
/* Just one more line. */
|
|
|
|
db_setup_paging(db_simple_pager, arg, 1);
|
|
|
|
return;
|
|
|
|
case ' ':
|
|
|
|
/* Another page. */
|
|
|
|
db_setup_paging(db_simple_pager, arg,
|
|
|
|
DB_LINES_PER_PAGE);
|
|
|
|
return;
|
|
|
|
case 'q':
|
|
|
|
case 'Q':
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
/* Quit */
|
|
|
|
if (arg != NULL) {
|
|
|
|
*(int *)arg = 1;
|
|
|
|
db_printf("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
default:
|
|
|
|
cnputc('\007');
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
/*
|
|
|
|
* Return output position
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
db_print_position()
|
|
|
|
{
|
|
|
|
return (db_output_position);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Printing
|
|
|
|
*/
|
1993-11-25 01:38:01 +00:00
|
|
|
void
|
1997-04-01 14:31:06 +00:00
|
|
|
#if __STDC__
|
1993-11-25 01:38:01 +00:00
|
|
|
db_printf(const char *fmt, ...)
|
1997-04-01 14:31:06 +00:00
|
|
|
#else
|
|
|
|
db_printf(fmt)
|
|
|
|
const char *fmt;
|
|
|
|
#endif
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
va_list listp;
|
1996-09-14 11:54:59 +00:00
|
|
|
|
|
|
|
va_start(listp, fmt);
|
|
|
|
kvprintf (fmt, db_putchar, NULL, db_radix, listp);
|
|
|
|
va_end(listp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int db_indent;
|
|
|
|
|
|
|
|
void
|
1997-04-01 14:31:06 +00:00
|
|
|
#if __STDC__
|
1996-09-14 11:54:59 +00:00
|
|
|
db_iprintf(const char *fmt,...)
|
1997-04-01 14:31:06 +00:00
|
|
|
#else
|
|
|
|
db_iprintf(fmt)
|
|
|
|
const char *fmt;
|
|
|
|
#endif
|
1996-09-14 11:54:59 +00:00
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
va_list listp;
|
|
|
|
|
|
|
|
for (i = db_indent; i >= 8; i -= 8)
|
|
|
|
db_printf("\t");
|
|
|
|
while (--i >= 0)
|
|
|
|
db_printf(" ");
|
1993-06-12 14:58:17 +00:00
|
|
|
va_start(listp, fmt);
|
1996-01-15 22:41:03 +00:00
|
|
|
kvprintf (fmt, db_putchar, NULL, db_radix, listp);
|
1993-06-12 14:58:17 +00:00
|
|
|
va_end(listp);
|
|
|
|
}
|
|
|
|
|
1993-09-09 23:03:24 +00:00
|
|
|
/*
|
|
|
|
* End line if too long.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
db_end_line()
|
|
|
|
{
|
|
|
|
if (db_output_position >= db_max_width)
|
|
|
|
db_printf("\n");
|
|
|
|
}
|