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