xref: /csrg-svn/sys/deprecated/kdb/kdb_trap.c (revision 38917)
1 /*
2  * Copyright (c) 1986, 1989 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)kdb_trap.c	7.6 (Berkeley) 09/02/89
7  */
8 
9 /*
10  * Trap handler - command loop entry point.
11  */
12 #include "../kdb/defs.h"
13 
14 char	*NOEOR;
15 
16 int	executing;
17 char	*lp;
18 
19 char	lastc;
20 
21 ADDR	userpc;
22 int	lastcom;
23 
24 ADDR	maxoff = MAXOFF;
25 long	maxpos = MAXPOS;
26 
27 /*
28  * Kdb trap handler; entered on all fatal
29  * and/or debugger related traps or faults.
30  */
31 kdb(type, code, curproc)
32 	int type, code;
33 	struct proc *curproc;
34 {
35 
36 	var[varchk('t')] = type;
37 	var[varchk('c')] = code;
38 	var[varchk('p')] = (int)curproc;
39 	printtrap((long)type, (long)code);
40 	userpc = dot = pcb.pcb_pc;
41 	switch (setexit()) {
42 
43 	case SINGLE:
44 		setsstep();		/* hardware single step */
45 		/* fall thru... */
46 	case CONTIN:
47 		return (1);
48 	case PANIC:
49 		return (0);
50 	case 0:
51 		if (nextpcs(type))
52 			printf("breakpoint%16t");
53 		else
54 			printf("stopped at%16t");
55 		printpc();
56 		break;
57 	}
58 	if (executing)
59 		delbp();
60 	executing = 0;
61 	for (;;) {
62 		flushbuf();
63 		if (errflg) {
64 			printf("%s\n", errflg);
65 			errflg = 0;
66 		}
67 		if (mkfault) {
68 			mkfault=0;
69 			printc('\n');
70 			printf(DBNAME);
71 		}
72 		kdbwrite("kdb> ", 5);
73 		lp=0; (void) rdc(); lp--;
74 		(void) command((char *)0, lastcom);
75 		if (lp && lastc!='\n')
76 			error(NOEOR);
77 	}
78 }
79 
80 /*
81  * If there has been an error or a fault, take the error.
82  */
83 chkerr()
84 {
85 	if (errflg || mkfault)
86 		error(errflg);
87 }
88 
89 /*
90  * An error occurred; save the message for
91  * later printing, and reset to main command loop.
92  */
93 error(n)
94 	char *n;
95 {
96 
97 	errflg = n;
98 	reset(ERROR);
99 }
100