[BACK]Return to db_output.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / ddb

File: [cvs.NetBSD.org] / src / sys / ddb / db_output.c (download)

Revision 1.29, Sun Dec 11 12:20:53 2005 UTC (18 years, 4 months ago) by christos
Branch: MAIN
CVS Tags: yamt-x86pmap-base4, yamt-x86pmap-base3, yamt-x86pmap-base2, yamt-x86pmap-base, yamt-x86pmap, yamt-uio_vmspace-base5, yamt-uio_vmspace, yamt-splraiseipl-base5, yamt-splraiseipl-base4, yamt-splraiseipl-base3, yamt-splraiseipl-base2, yamt-splraiseipl-base, yamt-splraiseipl, yamt-pf42-baseX, yamt-pf42-base4, yamt-pf42-base3, yamt-pf42-base2, yamt-pf42-base, yamt-pf42, yamt-pdpolicy-base9, yamt-pdpolicy-base8, yamt-pdpolicy-base7, yamt-pdpolicy-base6, yamt-pdpolicy-base5, yamt-pdpolicy-base4, yamt-pdpolicy-base3, yamt-pdpolicy-base2, yamt-pdpolicy-base, yamt-pdpolicy, yamt-nfs-mp-base2, yamt-nfs-mp-base, yamt-lazymbuf-base15, yamt-lazymbuf-base14, yamt-kmem-base3, yamt-kmem-base2, yamt-kmem-base, yamt-kmem, yamt-idlelwp-base8, yamt-idlelwp, wrstuden-revivesa-base-4, wrstuden-revivesa-base-3, wrstuden-revivesa-base-2, wrstuden-revivesa-base-1, wrstuden-revivesa-base, wrstuden-revivesa, wrstuden-fixsa-newbase, wrstuden-fixsa-base-1, wrstuden-fixsa-base, wrstuden-fixsa, vmlocking2-base3, vmlocking2-base2, vmlocking2-base1, vmlocking2, vmlocking-nbase, vmlocking-base, vmlocking, thorpej-atomic-base, thorpej-atomic, simonb-wapbl-nbase, simonb-wapbl-base, simonb-wapbl, simonb-timecounters-base, simonb-timecounters, simonb-timcounters-final, rpaulo-netinet-merge-pcb-base, rpaulo-netinet-merge-pcb, reinoud-bufcleanup-nbase, reinoud-bufcleanup-base, reinoud-bufcleanup, post-newlock2-merge, peter-altq-base, peter-altq, nick-net80211-sync-base, nick-net80211-sync, nick-hppapmap-base2, nick-csl-alignment-base5, nick-csl-alignment-base, nick-csl-alignment, newlock2-nbase, newlock2-base, newlock2, netbsd-5-base, netbsd-5-2-RELEASE, netbsd-5-2-RC1, netbsd-5-2-3-RELEASE, netbsd-5-2-2-RELEASE, netbsd-5-2-1-RELEASE, netbsd-5-2, netbsd-5-1-RELEASE, netbsd-5-1-RC4, netbsd-5-1-RC3, netbsd-5-1-RC2, netbsd-5-1-RC1, netbsd-5-1-5-RELEASE, netbsd-5-1-4-RELEASE, netbsd-5-1-3-RELEASE, netbsd-5-1-2-RELEASE, netbsd-5-1-1-RELEASE, netbsd-5-1, netbsd-5-0-RELEASE, netbsd-5-0-RC4, netbsd-5-0-RC3, netbsd-5-0-RC2, netbsd-5-0-RC1, netbsd-5-0-2-RELEASE, netbsd-5-0-1-RELEASE, netbsd-5-0, netbsd-5, netbsd-4-base, netbsd-4-0-RELEASE, netbsd-4-0-RC5, netbsd-4-0-RC4, netbsd-4-0-RC3, netbsd-4-0-RC2, netbsd-4-0-RC1, netbsd-4-0-1-RELEASE, netbsd-4-0, netbsd-4, mjf-ufs-trans-base, mjf-ufs-trans, mjf-devfs2-base, mjf-devfs2, mjf-devfs-base, mjf-devfs, matt-nb5-pq3-base, matt-nb5-pq3, matt-nb5-mips64-u2-k2-k4-k7-k8-k9, matt-nb5-mips64-u1-k1-k5, matt-nb5-mips64-premerge-20101231, matt-nb5-mips64-premerge-20091211, matt-nb5-mips64-k15, matt-nb5-mips64, matt-nb4-mips64-k7-u2a-k9b, matt-nb4-arm-base, matt-nb4-arm, matt-mips64-base2, matt-mips64-base, matt-mips64, matt-armv6-prevmlocking, matt-armv6-nbase, matt-armv6-base, matt-armv6, keiichi-mipv6-nbase, keiichi-mipv6-base, keiichi-mipv6, jmcneill-pm-base, jmcneill-pm, jmcneill-base, hpcarm-cleanup-nbase, hpcarm-cleanup-base, hpcarm-cleanup, haad-nbase2, haad-dm-base2, haad-dm-base1, haad-dm-base, haad-dm, gdamore-uart-base, gdamore-uart, elad-kernelauth-base, elad-kernelauth, cube-autoconf-base, cube-autoconf, chap-midi-nbase, chap-midi-base, chap-midi, bouyer-xeni386-nbase, bouyer-xeni386-merge1, bouyer-xeni386-base, bouyer-xeni386, bouyer-xenamd64-base2, bouyer-xenamd64-base, bouyer-xenamd64, ad-socklock-base1, ad-audiomp2-base, ad-audiomp2, ad-audiomp-base, ad-audiomp, abandoned-netbsd-4-base, abandoned-netbsd-4
Branch point for: yamt-nfs-mp, nick-hppapmap, jym-xensuspend
Changes since 1.28: +2 -2 lines

merge ktrace-lwp.

/*	$NetBSD: db_output.c,v 1.29 2005/12/11 12:20:53 christos Exp $	*/

/*
 * Mach Operating System
 * Copyright (c) 1991,1990 Carnegie Mellon University
 * All Rights Reserved.
 *
 * 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 "AS IS"
 * 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.
 */

/*
 * Printf and character output for debugger.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_output.c,v 1.29 2005/12/11 12:20:53 christos Exp $");

#include <sys/param.h>
#include <sys/systm.h>

#include <machine/stdarg.h>

#include <dev/cons.h>

#include <machine/db_machdep.h>

#include <ddb/db_command.h>
#include <ddb/db_output.h>
#include <ddb/db_interface.h>
#include <ddb/db_sym.h>
#include <ddb/db_extern.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
 *	of the wraparounds.
 */

#ifndef	DB_MAX_LINE
#define	DB_MAX_LINE		24	/* maximum line */
#endif	/* DB_MAX_LINE */
#ifndef	DB_MAX_WIDTH
#define DB_MAX_WIDTH		80	/* maximum width */
#endif	/* DB_MAX_WIDTH */

#define DB_MIN_MAX_WIDTH	20	/* minimum max width */
#define DB_MIN_MAX_LINE		3	/* minimum max line */
#define CTRL(c)			((c) & 0xff)

int	db_output_line = 0;			/* output line number */
int	db_tab_stop_width = 8;			/* how wide are tab stops? */
int	db_max_line = DB_MAX_LINE;		/* output max lines */
int	db_max_width = DB_MAX_WIDTH;		/* output line width */

static int	db_output_position = 0;		/* output column */
static int	db_last_non_space = 0;		/* last non-space character */

static void db_more(void);

/*
 * Force pending whitespace.
 */
void
db_force_whitespace(void)
{
	int last_print, next_tab;

	last_print = db_last_non_space;
	while (last_print < db_output_position) {
		next_tab = DB_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;
}

static void
db_more(void)
{
	const char *p;
	int quit_output = 0;

	for (p = "--db_more--"; *p; p++)
		cnputc(*p);
	switch(cngetc()) {
	case ' ':
		db_output_line = 0;
		break;
	case 'q':
	case CTRL('c'):
		db_output_line = 0;
		quit_output = 1;
		break;
	default:
		db_output_line--;
		break;
	}
	p = "\b\b\b\b\b\b\b\b\b\b\b           \b\b\b\b\b\b\b\b\b\b\b";
	while (*p)
		cnputc(*p++);
	if (quit_output) {
		db_error(0);
		/* NOTREACHED */
	}
}

/*
 * Output character.  Buffer whitespace.
 */
void
db_putchar(int c)
{
	if (db_max_line >= DB_MIN_MAX_LINE && db_output_line >= db_max_line-1)
		db_more();
	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++;
		if (db_max_width >= DB_MIN_MAX_WIDTH
		    && db_output_position >= db_max_width) {
			/* auto new line */
			cnputc('\n');
			db_output_position = 0;
			db_last_non_space = 0;
			db_output_line++;
		}
		db_last_non_space = db_output_position;
	} else if (c == '\n') {
		/* Return */
		cnputc(c);
		db_output_position = 0;
		db_last_non_space = 0;
		db_output_line++;
		db_check_interrupt();
	} else if (c == '\t') {
		/* assume tabs every 8 positions */
		db_output_position = DB_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 */
}

/*
 * Return output position
 */
int
db_print_position(void)
{

	return (db_output_position);
}

/*
 * End line if too long.
 */
void
db_end_line(void)
{

	if (db_output_position >= db_max_width)
		db_printf("\n");
}

/*
 * Replacement for old '%r' kprintf format.
 */
void
db_format_radix(char *buf, size_t bufsiz, quad_t val, int altflag)
{
	const char *fmt;

	if (db_radix == 16) {
		db_format_hex(buf, bufsiz, val, altflag);
		return;
	}

	if (db_radix == 8)
		fmt = altflag ? "-%#qo" : "-%qo";
	else
		fmt = altflag ? "-%#qu" : "-%qu";

	if (val < 0)
		val = -val;
	else
		++fmt;

	snprintf(buf, bufsiz, fmt, val);
}

/*
 * Replacement for old '%z' kprintf format.
 */
void
db_format_hex(char *buf, size_t bufsiz, quad_t val, int altflag)
{
	/* Only use alternate form if val is nonzero. */
	const char *fmt = (altflag && val) ? "-%#qx" : "-%qx";

	if (val < 0)
		val = -val;
	else
		++fmt;

	snprintf(buf, bufsiz, fmt, val);
}