xref: /csrg-svn/sys/deprecated/kdb/kdb_trap.c (revision 30296)
1*30296Ssam /*
2*30296Ssam  * Copyright (c) 1986 Regents of the University of California.
3*30296Ssam  * All rights reserved.  The Berkeley software License Agreement
4*30296Ssam  * specifies the terms and conditions for redistribution.
5*30296Ssam  *
6*30296Ssam  *	@(#)kdb_trap.c	7.5 (Berkeley) 12/15/86
7*30296Ssam  */
830113Ssam 
930113Ssam /*
1030113Ssam  * Trap handler - command loop entry point.
1130113Ssam  */
1230113Ssam #include "../kdb/defs.h"
1330113Ssam 
1430113Ssam char	*NOEOR;
1530113Ssam 
1630113Ssam int	executing;
1730113Ssam char	*lp;
1830113Ssam 
1930113Ssam char	lastc;
2030113Ssam 
2130113Ssam ADDR	userpc;
2230113Ssam int	lastcom;
2330113Ssam 
2430113Ssam ADDR	maxoff = MAXOFF;
2530113Ssam long	maxpos = MAXPOS;
2630113Ssam 
2730127Ssam /*
2830127Ssam  * Kdb trap handler; entered on all fatal
2930127Ssam  * and/or debugger related traps or faults.
3030127Ssam  */
3130127Ssam kdb(type, code, curproc)
3230127Ssam 	int type, code;
3330113Ssam 	struct proc *curproc;
3430113Ssam {
3530113Ssam 
3630127Ssam 	var[varchk('t')] = type;
3730127Ssam 	var[varchk('c')] = code;
3830127Ssam 	var[varchk('p')] = (int)curproc;
39*30296Ssam 	printtrap((long)type, (long)code);
4030113Ssam 	userpc = dot = pcb.pcb_pc;
4130113Ssam 	switch (setexit()) {
4230113Ssam 
4330113Ssam 	case SINGLE:
4430136Ssam 		setsstep();		/* hardware single step */
4530113Ssam 		/* fall thru... */
4630113Ssam 	case CONTIN:
4730113Ssam 		return (1);
4830113Ssam 	case 0:
49*30296Ssam 		if (nextpcs(type))
5030113Ssam 			printf("breakpoint%16t");
5130113Ssam 		else
5230113Ssam 			printf("stopped at%16t");
5330113Ssam 		printpc();
5430113Ssam 		break;
5530113Ssam 	}
5630113Ssam 	if (executing)
5730113Ssam 		delbp();
5830113Ssam 	executing = 0;
5930113Ssam 	for (;;) {
6030113Ssam 		flushbuf();
6130113Ssam 		if (errflg) {
6230113Ssam 			printf("%s\n", errflg);
6330113Ssam 			errflg = 0;
6430113Ssam 		}
6530113Ssam 		if (mkfault) {
6630113Ssam 			mkfault=0;
6730113Ssam 			printc('\n');
6830113Ssam 			printf(DBNAME);
6930113Ssam 		}
7030113Ssam 		kdbwrite("kdb> ", 5);
71*30296Ssam 		lp=0; (void) rdc(); lp--;
72*30296Ssam 		(void) command((char *)0, lastcom);
7330113Ssam 		if (lp && lastc!='\n')
7430113Ssam 			error(NOEOR);
7530113Ssam 	}
7630113Ssam }
7730113Ssam 
7830113Ssam /*
7930113Ssam  * If there has been an error or a fault, take the error.
8030113Ssam  */
8130113Ssam chkerr()
8230113Ssam {
8330113Ssam 	if (errflg || mkfault)
8430113Ssam 		error(errflg);
8530113Ssam }
8630113Ssam 
8730113Ssam /*
8830113Ssam  * An error occurred; save the message for
8930113Ssam  * later printing, and reset to main command loop.
9030113Ssam  */
9130113Ssam error(n)
9230113Ssam 	char *n;
9330113Ssam {
9430113Ssam 
9530113Ssam 	errflg = n;
9630123Ssam 	reset(ERROR);
9730113Ssam }
98