1 /*-
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)bp.c	8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11 
12 /*
13  * Direct management of bpinfo structures.
14  */
15 
16 #include "defs.h"
17 #include "breakpoint.h"
18 #include "tree.h"
19 #include "sym.h"
20 #include "main.h"
21 #include "source.h"
22 #include "object.h"
23 #include "bp.rep"
24 
25 unsigned int uniqueid;
26 
27 /*
28  * Add a breakpoint to the list, return a pointer to it.
29  */
30 
newbp(addr,type,block,cond,node,line)31 BPINFO *newbp(addr, type, block, cond, node, line)
32 ADDRESS addr;
33 BPTYPE type;
34 SYM *block;
35 NODE *cond;
36 NODE *node;
37 LINENO line;
38 {
39 	register BPINFO *p;
40 
41 	p = alloc(1, BPINFO);
42 	p->bpid = ++uniqueid;
43 	p->bpaddr = addr;
44 	p->bptype = type;
45 	p->bpblock = block;
46 	p->bpcond = cond;
47 	p->bpnode = node;
48 	p->bpline = line;
49 	p->bpnext = bphead;
50 	if (option('b')) {
51 		printf("new bp (%d) at %d, type %d\n", p->bpid, p->bpaddr, p->bptype);
52 		fflush(stdout);
53 	}
54 	bphead = p;
55 	return(p);
56 }
57 
58 /*
59  * Add a breakpoint, but don't return anything.
60  * Just for folks outside of "breakpoint" who don't know that
61  * a BPINFO exists.
62  */
63 
addbp(addr,type,block,cond,node,line)64 addbp(addr, type, block, cond, node, line)
65 ADDRESS addr;
66 BPTYPE type;
67 SYM *block;
68 NODE *cond;
69 NODE *node;
70 LINENO line;
71 {
72 
73 	(void) newbp(addr, type, block, cond, node, line);
74 }
75 
76 /*
77  * Delete a breakpoint.
78  *
79  * Print out a cryptic error message if it can't be found.
80  */
81 
delbp(id)82 delbp(id)
83 unsigned int id;
84 {
85 	register BPINFO *p, *last;
86 
87 	last = NIL;
88 	for (p = bphead; p != NIL; p = p->bpnext) {
89 		if (p->bpid == id) {
90 			break;
91 		}
92 		last = p;
93 	}
94 	if (p == NIL) {
95 		error("%d unknown", id);
96 	}
97 	switch (p->bptype) {
98 		case ALL_ON:
99 			if (p->bpline >= 0) {
100 				tracing--;
101 			} else {
102 				inst_tracing--;
103 			}
104 			break;
105 
106 		case STOP_ON:
107 			var_tracing--;
108 			break;
109 
110 		default:
111 			/* do nothing */
112 			break;
113 	}
114 	if (last == NIL) {
115 		bphead = p->bpnext;
116 	} else {
117 		last->bpnext = p->bpnext;
118 	}
119 	tfree(p->bpcond);
120 	tfree(p->bpnode);
121 	dispose(p);
122 }
123 
124 /*
125  * Free all storage in the breakpoint table.
126  */
127 
bpfree()128 bpfree()
129 {
130 	register BPINFO *p, *next;
131 
132 	fixbps();
133 	for (p = bphead; p != NIL; p = next) {
134 		next = p->bpnext;
135 		tfree(p->bpcond);
136 		tfree(p->bpnode);
137 		dispose(p);
138 	}
139 	bphead = NIL;
140 }
141