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