xref: /csrg-svn/sys/deprecated/kdb/kdb_trap.c (revision 30123)
1 /*	kdb_trap.c	7.2	86/11/20	*/
2 
3 /*
4  * Trap handler - command loop entry point.
5  */
6 #include "../kdb/defs.h"
7 
8 char	*NOEOR;
9 
10 int	executing;
11 char	*lp;
12 
13 char	lastc;
14 
15 ADDR	userpc;
16 int	lastcom;
17 
18 ADDR	maxoff = MAXOFF;
19 long	maxpos = MAXPOS;
20 
21 kdb(type, sp, curproc)
22 	int type, *sp;
23 	struct proc *curproc;
24 {
25 
26 	userpc = dot = pcb.pcb_pc;
27 	var[varchk('t')] = (int)sp;
28 	switch (setexit()) {
29 
30 	case SINGLE:
31 		pcb.pcb_psl |= TBIT;
32 		/* fall thru... */
33 	case CONTIN:
34 		return (1);
35 	case 0:
36 		if (nextpcs(type, 0))
37 			printf("breakpoint%16t");
38 		else
39 			printf("stopped at%16t");
40 		printpc();
41 		break;
42 	}
43 	if (executing)
44 		delbp();
45 	executing = 0;
46 	for (;;) {
47 		flushbuf();
48 		if (errflg) {
49 			printf("%s\n", errflg);
50 			errflg = 0;
51 		}
52 		if (mkfault) {
53 			mkfault=0;
54 			printc('\n');
55 			printf(DBNAME);
56 		}
57 		kdbwrite("kdb> ", 5);
58 		lp=0; rdc(); lp--;
59 		command(0, lastcom);
60 		if (lp && lastc!='\n')
61 			error(NOEOR);
62 	}
63 }
64 
65 /*
66  * If there has been an error or a fault, take the error.
67  */
68 chkerr()
69 {
70 	if (errflg || mkfault)
71 		error(errflg);
72 }
73 
74 /*
75  * An error occurred; save the message for
76  * later printing, and reset to main command loop.
77  */
78 error(n)
79 	char *n;
80 {
81 
82 	errflg = n;
83 	reset(ERROR);
84 }
85