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