-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDebug.cpp
More file actions
175 lines (131 loc) · 3.92 KB
/
Copy pathDebug.cpp
File metadata and controls
175 lines (131 loc) · 3.92 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
////////////////////////////////////////////////////////////////////////////
//
// ccli : The Computation and Control Language Tools
// -------------------------------------------------
//
// Copyright (c) 2003 Eric Klavins, California Institute of Technology
// For more information, email klavins@caltech.edu
//
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//
#include <stdio.h>
#include <stdlib.h>
#ifndef WIN
#include <readline/readline.h>
#include <readline/history.h>
#endif
#include "Program.h"
void Command::debug_apply ( Scope * s ) {
printf ( "\n\n%s, %d:\n",
rhs->file_name() == NULL ? "no file info" : rhs->file_name(),
rhs->line_num() );
print();
printf ( "\n" );
Clause::get_debug_command(s);
Value * answer = rhs->eval ( s );
if ( lhs == NULL )
delete answer;
else
s->set ( lhs, answer );
}
void Clause::debug_execute ( Scope * s ) {
printf ( "\n%s, %d:\n",
guard->file_name() == NULL ? "no file info" : guard->file_name(),
guard->line_num() );
guard->print();
printf ( " <<guard>>\n" );
get_debug_command(s);
Value * gval = guard->eval ( s );
if ( gval == NULL ) {
fprintf ( stderr, "Clause::execute: gval = NULL\n" );
exit ( -1 );
}
if ( gval->bool_value() ) {
printf ( "guard evaluated to true, executing clauses" );
for ( i = commands->begin(); i != commands->end(); i++ )
(*i)->debug_apply ( s );
} else {
printf ( "\nguard evaluated to false, continuing\n" );
}
delete gval;
}
void Clause::get_debug_command ( Scope * s ) {
char * com;
while ( 1 ) {
#ifndef WIN
com = readline ( "> " );
if ( com && *com )
add_history ( com );
#endif
switch ( com[0] ) {
case 's': // step
case ' ':
case 0:
free ( com );
return;
case 'p': // print a symbol
if ( strlen ( com ) > 2 ) {
Value * v = s->get ( com+2 );
if ( v == NULL )
printf ( "symbol '%s' not found\n", com+2 );
else {
printf ( "%s: " );
v->print();
printf ( "\n" );
}
} else {
printf ( "command 'p' requires an argument\n" );
}
break;
case 't': // print top level symbol tables
{
int n = atoi ( com + 2 ), i = 0;
SymbolTable * temp = s->get_top();
while ( i < n && temp != NULL ) {
temp->print_names ( stdout, 2*i );
temp = temp->next;
i++;
}
}
break;
case 'T': // print scope
s->print_names ( stdout );
break;
case 'q': // quit
exit ( 0 );
break;
case 'l': // clear screen
system ( "clear" );
break;
case 'h': // help
printf ( "\n" );
printf ( " debugger commands\n" );
printf ( " ---------------------------------------------------\n" );
printf ( " s step ( also ' ' and \\n )\n" );
printf ( " p var print the value of the variable var\n" );
printf ( " t n print symbols in top n scopes\n" );
printf ( " T print symbols in all scopes\n" );
printf ( " q quit\n" );
printf ( " l clear the screen\n" );
printf ( " h this help message\n\n" );
break;
default:
printf ( "unrecongnized command: '%s'\n", com );
break;
}
free ( com );
}
}