-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbttrace.cpp
More file actions
209 lines (172 loc) · 4.54 KB
/
bttrace.cpp
File metadata and controls
209 lines (172 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
IL : Intlog Language
Object Oriented Prolog Project
Copyright (C) 1992-2021 - Ing. Capelli Carlo
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
#include "defsys.h"
#include "qdata.h"
#include "tracer.h"
#include "builtin.h"
#include "bterr.h"
#include "argali.h"
//-------------------------------
// interface to builtin debugger
//-------------------------------
BtFDecl(trace);
BtFDecl(notrace);
BtFDecl(spy);
BtFDecl(nospy);
BtFDecl(debugging);
BtFDecl(nodebug);
BtFDecl(tracemode);
static int setspy(IntlogExec *, Term, int);
BuiltIn tracing_control[7] = {
{"trace", 0, trace},
{"notrace", 0, notrace},
{"spy", 1, spy},
{"nospy", 1, nospy},
{"debugging", 0, debugging},
{"nodebug", 0, nodebug},
{"tracemode", 1, tracemode}
};
//--------------------------
// enable extensive tracing
//
BtFImpl_P1(trace, p) {
p->tracer()->trace_on();
return 1;
}
//----------------------------
// disable extensive tracing
//
BtFImpl_P1(notrace, p) {
p->tracer()->trace_off();
return 1;
}
//-------------------------------
// create spy point specifier(s)
//
BtFImpl(spy, t, p) {
return setspy(p, t.getarg(0), 1);
}
//-------------------------------
// remove spy point specifier(s)
//
BtFImpl(nospy, t, p) {
return setspy(p, t.getarg(0), 0);
}
//-------------------------
// require spy points list
//
BtFImpl_P1(debugging, p) {
p->tracer()->debugging(p->out());
return 1;
}
//-----------------------
// remove all spy points
//
BtFImpl_P1(nodebug, p) {
p->tracer()->nodebug();
return 1;
}
//-----------------
// set tracer mode
//
BtFImpl(tracemode, t, p) {
Term cp = p->copy(t.getarg(0)), a;
static ArgALIter::aDesc keys[4] = {
{ "ext", f_INT },
{ "file", f_ATOM },
{ "on", f_NOTERM },
{ "off", f_NOTERM }
};
ArgALIter it(cp, keys, sizeof(keys) / sizeof(keys[0]));
unsigned ixk;
for ( ; ; ) {
switch (it.nextarg(&ixk, &a)) {
case ArgALIter::KeyValue:
if (ixk == 0) {
Int i = Int(a);
if (i > 0)
p->tracer()->etrace_on();
else
p->tracer()->etrace_off();
}
if (ixk == 1) {
ofstream *f = new ofstream(a);
if (f->good()) //is_open())
p->tracer()->setoutput(f);
else {
delete f;
goto err;
}
}
break;
case ArgALIter::Key:
if (ixk == 2)
p->tracer()->trace_on();
if (ixk == 3)
p->tracer()->trace_off();
break;
case ArgALIter::EndArgs:
cp.Destroy();
return 1;
default:
goto err;
}
}
err:
p->BtErr(BTERR_INVALID_ARG_TYPE);
cp.Destroy();
return 0;
}
//-------------------------
// scan argument specifier and
//
static int setspy(IntlogExec *p, Term t, int on) {
Term cp = p->copy(t), a, r;
ArgALIter it(cp, nullptr, 0);
for ( ; ; ) {
kstring funct;
int arity = -1;
switch (it.nextarg(nullptr, &a)) {
case ArgALIter::Pair:
if (!(r = a.getarg(1)).type(f_INT))
goto err;
arity = Int(r);
a = a.getarg(0);
// fall through!
[[clang::fallthrough]];
case ArgALIter::Single:
if (!a.type(f_ATOM))
goto err;
funct = a.kstr();
break;
default:
goto err;
case ArgALIter::EndArgs:
cp.Destroy();
return 1;
}
p->tracer()->spy(funct, on, arity);
}
err:
p->BtErr(BTERR_INVALID_ARG_TYPE);
cp.Destroy();
return 0;
}