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[] = "@(#)trcond.c	8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11 
12 /*
13  * trace condition list -- a list of conditions that are to be
14  * checked before printing out the current source line or stopping.
15  */
16 
17 #include "defs.h"
18 #include "breakpoint.h"
19 
20 typedef struct tr_cond_list {
21 	TRTYPE trtype;
22 	NODE *trace_condition;
23 	struct tr_cond_list *next_condition;
24 } TR_COND_LIST;
25 
26 LOCAL TR_COND_LIST *cond_list;
27 
28 /*
29  * add a condition to be checked before giving single stepping information
30  */
31 
32 addcond(trtype, p)
33 TRTYPE trtype;
34 NODE *p;
35 {
36 	register TR_COND_LIST *c;
37 
38 	if (p == NIL) {
39 		return;
40 	}
41 	c = alloc(1, TR_COND_LIST);
42 	c->trtype = trtype;
43 	c->trace_condition = p;
44 	c->next_condition = cond_list;
45 	cond_list = c;
46 }
47 
48 /*
49  * delete a condition from the list
50  */
51 
52 delcond(trtype, p)
53 TRTYPE trtype;
54 NODE *p;
55 {
56 	register TR_COND_LIST *c, *last;
57 
58 	if (p == NIL) {
59 		return;
60 	}
61 	last = NIL;
62 	for (c = cond_list; c != NIL; c = c->next_condition) {
63 		if (c->trtype == trtype && c->trace_condition == p) {
64 			break;
65 		}
66 	}
67 	if (c == NIL) {
68 		panic("tried to delete non-existent condition");
69 	}
70 	if (last == NIL) {
71 		cond_list = c->next_condition;
72 	} else {
73 		last->next_condition = c->next_condition;
74 	}
75 	free(c);
76 }
77 
78 /*
79  * Determine if any trace condition on the list is true.
80  * If the list is empty, return TRUE.
81  */
82 
83 BOOLEAN trcond()
84 {
85 	register TR_COND_LIST *c;
86 	BOOLEAN foundcond;
87 
88 	foundcond = FALSE;
89 	for (c = cond_list; c != NIL; c = c->next_condition) {
90 		if (c->trtype == TRPRINT) {
91 			if (cond(c->trace_condition)) {
92 				return(TRUE);
93 			} else {
94 				foundcond = TRUE;
95 			}
96 		}
97 	}
98 	return !foundcond;
99 }
100 
101 /*
102  * Determine if any stop condition on the list is true.
103  * If the list is empty, return FALSE.
104  */
105 
106 BOOLEAN stopcond()
107 {
108 	register TR_COND_LIST *c;
109 
110 	for (c = cond_list; c != NIL; c = c->next_condition) {
111 		if (c->trtype == TRSTOP && cond(c->trace_condition)) {
112 			return(TRUE);
113 		}
114 	}
115 	return FALSE;
116 }
117 
118 /*
119  * Free all existing breakpoints.
120  * Trace conditions have been freed elsewhere.
121  */
122 
123 condfree()
124 {
125 	TR_COND_LIST *c, *next;
126 
127 	for (c = cond_list; c != NIL; c = next) {
128 		next = c->next_condition;
129 		dispose(c);
130 	}
131 	cond_list = NIL;
132 }
133