|
|
1.1 root 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[] = "@(#)trinfo.c 5.2 (Berkeley) 4/7/87";
9: #endif not lint
10:
11: /*
12: * Trace information management.
13: *
14: * The trace information is a list of variables that are being
15: * traced or whose value changing should cause a stop.
16: */
17:
18: #include "defs.h"
19: #include "breakpoint.h"
20: #include "process.h"
21: #include "machine.h"
22: #include "sym.h"
23: #include "tree.h"
24: #include "source.h"
25: #include "object.h"
26: #include "tree/tree.rep"
27: #include "process/process.rep"
28: #include "process/pxinfo.h"
29:
30: /*
31: * When tracing variables we keep a copy of their most recent value
32: * and compare it to the current one each time a breakpoint occurs.
33: * MAXTRSIZE is the maximum size variable we allow.
34: */
35:
36: #define MAXTRSIZE 512
37:
38: /*
39: * The tracing structure is a list of information about all the
40: * variables that are being traced.
41: */
42:
43: typedef struct trinfo {
44: TRTYPE trtype;
45: ADDRESS traddr;
46: SYM *trblock;
47: NODE *trvar;
48: NODE *trcond;
49: char *trvalue;
50: struct trinfo *trnext;
51: } TRINFO;
52:
53: LOCAL TRINFO *trhead;
54:
55: /*
56: * add a variable to be traced
57: */
58:
59: addvar(trtype, node, cond)
60: TRTYPE trtype;
61: NODE *node;
62: NODE *cond;
63: {
64: register TRINFO *tp;
65:
66: tp = alloc(1, TRINFO);
67: tp->trtype = trtype;
68: tp->traddr = (ADDRESS) -1;
69: tp->trblock = curfunc;
70: tp->trvar = node;
71: tp->trcond = cond;
72: tp->trvalue = NIL;
73: tp->trnext = trhead;
74: trhead = tp;
75: }
76:
77: /*
78: * remove a variable from the trace list
79: */
80:
81: delvar(trtype, node, cond)
82: TRTYPE trtype;
83: NODE *node;
84: NODE *cond;
85: {
86: register TRINFO *tp, *last;
87:
88: last = NIL;
89: for (tp = trhead; tp != NIL; tp = tp->trnext) {
90: if (tp->trtype == trtype &&
91: tr_equal(tp->trvar, node) &&
92: tr_equal(tp->trcond, cond)) {
93: break;
94: }
95: }
96: if (tp == NIL) {
97: trerror("can't delete term %t", node);
98: }
99: if (last == NIL) {
100: trhead = tp->trnext;
101: } else {
102: last->trnext = tp->trnext;
103: }
104: if (tp->trvalue != NIL) {
105: free(tp->trvalue);
106: }
107: free(tp);
108: }
109:
110: /*
111: * Print out any news about variables in the list whose
112: * values have changed.
113: */
114:
115: prvarnews()
116: {
117: register TRINFO *tp;
118: register NODE *p;
119: register int n;
120: SYM *s;
121: char buff[MAXTRSIZE];
122: static LINENO prevline;
123:
124: for (tp = trhead; tp != NIL; tp = tp->trnext) {
125: if (tp->trcond != NIL && !cond(tp->trcond)) {
126: continue;
127: }
128: s = curfunc;
129: while (s != NIL && s != tp->trblock) {
130: s = container(s);
131: }
132: if (s == NIL) {
133: continue;
134: }
135: p = tp->trvar;
136: if (tp->traddr == (ADDRESS) -1) {
137: tp->traddr = lval(p->left);
138: }
139: n = size(p->nodetype);
140: dread(buff, tp->traddr, n);
141: if (tp->trvalue == NIL) {
142: tp->trvalue = alloc(n, char);
143: mov(buff, tp->trvalue, n);
144: mov(buff, sp, n);
145: sp += n;
146: #ifdef tahoe
147: alignstack();
148: #endif
149: if (tp->trtype == TRPRINT) {
150: printf("initially (at ");
151: printwhere(curline, srcfilename(pc));
152: printf("):\t");
153: prtree(p);
154: printf(" = ");
155: printval(p->nodetype);
156: putchar('\n');
157: }
158: } else if (cmp(tp->trvalue, buff, n) != 0) {
159: mov(buff, tp->trvalue, n);
160: mov(buff, sp, n);
161: sp += n;
162: #ifdef tahoe
163: alignstack();
164: #endif
165: printf("after ");
166: printwhere(prevline, srcfilename(pc));
167: printf(":\t");
168: prtree(p);
169: printf(" = ");
170: printval(p->nodetype);
171: putchar('\n');
172: if (tp->trtype == TRSTOP) {
173: isstopped = TRUE;
174: curline = srcline(pc);
175: printstatus();
176: }
177: }
178: }
179: prevline = curline;
180: }
181:
182: /*
183: * Free the table. Note that trvar and trcond fields are not freed,
184: * this is because they are the same as in the breakpoint table and
185: * are freed by the bpfree routine.
186: */
187:
188: trfree()
189: {
190: register TRINFO *tp, *next;
191:
192: for (tp = trhead; tp != NIL; tp = next) {
193: next = tp->trnext;
194: if (tp->trvalue != NIL) {
195: free(tp->trvalue);
196: }
197: free(tp);
198: }
199: trhead = NIL;
200: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.