148103Sbostic /*-
2*62122Sbostic * Copyright (c) 1980, 1993
3*62122Sbostic * The Regents of the University of California. All rights reserved.
448103Sbostic *
548103Sbostic * %sccs.include.redist.c%
622281Sdist */
75469Slinton
822281Sdist #ifndef lint
9*62122Sbostic static char sccsid[] = "@(#)trcond.c 8.1 (Berkeley) 06/06/93";
1048103Sbostic #endif /* not lint */
115469Slinton
125469Slinton /*
135469Slinton * trace condition list -- a list of conditions that are to be
145469Slinton * checked before printing out the current source line or stopping.
155469Slinton */
165469Slinton
175469Slinton #include "defs.h"
185469Slinton #include "breakpoint.h"
195469Slinton
205469Slinton typedef struct tr_cond_list {
215469Slinton TRTYPE trtype;
225469Slinton NODE *trace_condition;
235469Slinton struct tr_cond_list *next_condition;
245469Slinton } TR_COND_LIST;
255469Slinton
265469Slinton LOCAL TR_COND_LIST *cond_list;
275469Slinton
285469Slinton /*
295469Slinton * add a condition to be checked before giving single stepping information
305469Slinton */
315469Slinton
addcond(trtype,p)325469Slinton addcond(trtype, p)
335469Slinton TRTYPE trtype;
345469Slinton NODE *p;
355469Slinton {
365469Slinton register TR_COND_LIST *c;
375469Slinton
385469Slinton if (p == NIL) {
395469Slinton return;
405469Slinton }
415469Slinton c = alloc(1, TR_COND_LIST);
425469Slinton c->trtype = trtype;
435469Slinton c->trace_condition = p;
445469Slinton c->next_condition = cond_list;
455469Slinton cond_list = c;
465469Slinton }
475469Slinton
485469Slinton /*
495469Slinton * delete a condition from the list
505469Slinton */
515469Slinton
delcond(trtype,p)525469Slinton delcond(trtype, p)
535469Slinton TRTYPE trtype;
545469Slinton NODE *p;
555469Slinton {
565469Slinton register TR_COND_LIST *c, *last;
575469Slinton
585469Slinton if (p == NIL) {
595469Slinton return;
605469Slinton }
615469Slinton last = NIL;
625469Slinton for (c = cond_list; c != NIL; c = c->next_condition) {
635469Slinton if (c->trtype == trtype && c->trace_condition == p) {
645469Slinton break;
655469Slinton }
665469Slinton }
675469Slinton if (c == NIL) {
685469Slinton panic("tried to delete non-existent condition");
695469Slinton }
705469Slinton if (last == NIL) {
715469Slinton cond_list = c->next_condition;
725469Slinton } else {
735469Slinton last->next_condition = c->next_condition;
745469Slinton }
755469Slinton free(c);
765469Slinton }
775469Slinton
785469Slinton /*
795469Slinton * Determine if any trace condition on the list is true.
805469Slinton * If the list is empty, return TRUE.
815469Slinton */
825469Slinton
trcond()835469Slinton BOOLEAN trcond()
845469Slinton {
855469Slinton register TR_COND_LIST *c;
865469Slinton BOOLEAN foundcond;
875469Slinton
885469Slinton foundcond = FALSE;
895469Slinton for (c = cond_list; c != NIL; c = c->next_condition) {
905469Slinton if (c->trtype == TRPRINT) {
915469Slinton if (cond(c->trace_condition)) {
925469Slinton return(TRUE);
935469Slinton } else {
945469Slinton foundcond = TRUE;
955469Slinton }
965469Slinton }
975469Slinton }
985469Slinton return !foundcond;
995469Slinton }
1005469Slinton
1015469Slinton /*
1025469Slinton * Determine if any stop condition on the list is true.
1035469Slinton * If the list is empty, return FALSE.
1045469Slinton */
1055469Slinton
stopcond()1065469Slinton BOOLEAN stopcond()
1075469Slinton {
1085469Slinton register TR_COND_LIST *c;
1095469Slinton
1105469Slinton for (c = cond_list; c != NIL; c = c->next_condition) {
1115469Slinton if (c->trtype == TRSTOP && cond(c->trace_condition)) {
1125469Slinton return(TRUE);
1135469Slinton }
1145469Slinton }
1155469Slinton return FALSE;
1165469Slinton }
1175469Slinton
1185469Slinton /*
1195469Slinton * Free all existing breakpoints.
1205469Slinton * Trace conditions have been freed elsewhere.
1215469Slinton */
1225469Slinton
condfree()1235469Slinton condfree()
1245469Slinton {
1255469Slinton TR_COND_LIST *c, *next;
1265469Slinton
1275469Slinton for (c = cond_list; c != NIL; c = next) {
1285469Slinton next = c->next_condition;
1295469Slinton dispose(c);
1305469Slinton }
1315469Slinton cond_list = NIL;
1325469Slinton }
133