[9f79f7]: src / runtime / parse.c Maximize Restore History

Download this file

parse.c    373 lines (318 with data), 7.8 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/* parsing for LDB monitor */
/*
* This software is part of the SBCL system. See the README file for
* more information.
*
* This software is derived from the CMU CL system, which was
* written at Carnegie Mellon University and released into the
* public domain. The software is in the public domain and is
* provided with absolutely no warranty. See the COPYING and CREDITS
* files for more information.
*/
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
#include "sbcl.h"
#include "runtime.h"
#if defined(LISP_FEATURE_SB_LDB)
#include "globals.h"
#include "vars.h"
#include "parse.h"
#include "os.h"
#include "interrupt.h"
#include "lispregs.h"
#include "monitor.h"
#include "arch.h"
#include "search.h"
#include "thread.h"
#include "genesis/simple-fun.h"
#include "genesis/fdefn.h"
#include "genesis/symbol.h"
#include "genesis/static-symbols.h"
static void skip_ws(char **ptr)
{
while (**ptr <= ' ' && **ptr != '\0')
(*ptr)++;
}
static boolean string_to_long(char *token, long *value)
{
int base, digit;
long num;
char *ptr;
if (token == 0)
return 0;
if (token[0] == '0')
if (token[1] == 'x') {
base = 16;
token += 2;
}
else {
base = 8;
token++;
}
else if (token[0] == '#') {
switch (token[1]) {
case 'x':
case 'X':
base = 16;
token += 2;
break;
case 'o':
case 'O':
base = 8;
token += 2;
break;
default:
return 0;
}
}
else
base = 10;
num = 0;
ptr = token;
while (*ptr != '\0') {
if (*ptr >= 'a' && *ptr <= 'f')
digit = *ptr + 10 - 'a';
else if (*ptr >= 'A' && *ptr <= 'F')
digit = *ptr + 10 - 'A';
else if (*ptr >= '0' && *ptr <= '9')
digit = *ptr - '0';
else
return 0;
if (digit < 0 || digit >= base)
return 0;
ptr++;
num = num * base + digit;
}
*value = num;
return 1;
}
static boolean lookup_variable(char *name, lispobj *result)
{
struct var *var = lookup_by_name(name);
if (var == NULL)
return 0;
else {
*result = var_value(var);
return 1;
}
}
boolean more_p(ptr)
char **ptr;
{
skip_ws(ptr);
if (**ptr == '\0')
return 0;
else
return 1;
}
char *parse_token(ptr)
char **ptr;
{
char *token;
skip_ws(ptr);
if (**ptr == '\0')
return NULL;
token = *ptr;
while (**ptr > ' ')
(*ptr)++;
if (**ptr != '\0') {
**ptr = '\0';
(*ptr)++;
}
return token;
}
#if 0
static boolean number_p(token)
char *token;
{
char *okay;
if (token == NULL)
return 0;
okay = "abcdefABCDEF987654321d0";
if (token[0] == '0')
if (token[1] == 'x' || token[1] == 'X')
token += 2;
else {
token++;
okay += 14;
}
else if (token[0] == '#') {
switch (token[1]) {
case 'x':
case 'X':
break;
case 'o':
case 'O':
okay += 14;
break;
default:
return 0;
}
}
else
okay += 12;
while (*token != '\0')
if (index(okay, *token++) == NULL)
return 0;
return 1;
}
#endif
long parse_number(ptr)
char **ptr;
{
char *token = parse_token(ptr);
long result;
if (token == NULL) {
printf("expected a number\n");
throw_to_monitor();
}
else if (string_to_long(token, &result))
return result;
else {
printf("invalid number: ``%s''\n", token);
throw_to_monitor();
}
return 0;
}
char *parse_addr(ptr)
char **ptr;
{
char *token = parse_token(ptr);
long result;
if (token == NULL) {
printf("expected an address\n");
throw_to_monitor();
}
else if (token[0] == '$') {
if (!lookup_variable(token+1, (lispobj *)&result)) {
printf("unknown variable: ``%s''\n", token);
throw_to_monitor();
}
result &= ~7;
}
else {
if (!string_to_long(token, &result)) {
printf("invalid number: ``%s''\n", token);
throw_to_monitor();
}
result &= ~3;
}
if (!is_valid_lisp_addr((os_vm_address_t)result)) {
printf("invalid Lisp-level address: 0x%lx\n", result);
throw_to_monitor();
}
return (char *)result;
}
static boolean lookup_symbol(char *name, lispobj *result)
{
int count;
lispobj *headerptr;
/* Search static space. */
headerptr = (lispobj *)STATIC_SPACE_START;
count =
(lispobj *)SymbolValue(STATIC_SPACE_FREE_POINTER,0) -
(lispobj *)STATIC_SPACE_START;
if (search_for_symbol(name, &headerptr, &count)) {
*result = make_lispobj(headerptr,OTHER_POINTER_LOWTAG);
return 1;
}
/* Search dynamic space. */
headerptr = (lispobj *)DYNAMIC_SPACE_START;
#if !(defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64))
count =
dynamic_space_free_pointer -
(lispobj *)DYNAMIC_SPACE_START;
#else
count =
(lispobj *)SymbolValue(ALLOCATION_POINTER,0) -
(lispobj *)DYNAMIC_SPACE_START;
#endif
if (search_for_symbol(name, &headerptr, &count)) {
*result = make_lispobj(headerptr, OTHER_POINTER_LOWTAG);
return 1;
}
return 0;
}
static int
parse_regnum(char *s)
{
if ((s[1] == 'R') || (s[1] == 'r')) {
int regnum;
if (s[2] == '\0')
return -1;
/* skip the $R part and call atoi on the number */
regnum = atoi(s + 2);
if ((regnum >= 0) && (regnum < NREGS))
return regnum;
else
return -1;
} else {
int i;
for (i = 0; i < NREGS ; i++)
if (strcasecmp(s + 1, lisp_register_names[i]) == 0)
#ifdef LISP_FEATURE_X86
return i*2;
#else
return i;
#endif
return -1;
}
}
lispobj parse_lispobj(ptr)
char **ptr;
{
struct thread *thread=arch_os_get_current_thread();
char *token = parse_token(ptr);
long pointer;
lispobj result;
if (token == NULL) {
printf("expected an object\n");
throw_to_monitor();
} else if (token[0] == '$') {
if (isalpha(token[1])) {
int free;
int regnum;
os_context_t *context;
free = SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX,thread)>>2;
if (free == 0) {
printf("Variable ``%s'' is not valid -- there is no current interrupt context.\n", token);
throw_to_monitor();
}
context = thread->interrupt_contexts[free - 1];
regnum = parse_regnum(token);
if (regnum < 0) {
printf("bogus register: ``%s''\n", token);
throw_to_monitor();
}
result = *os_context_register_addr(context, regnum);
} else if (!lookup_variable(token+1, &result)) {
printf("unknown variable: ``%s''\n", token);
throw_to_monitor();
}
} else if (token[0] == '@') {
if (string_to_long(token+1, &pointer)) {
pointer &= ~3;
if (is_valid_lisp_addr((os_vm_address_t)pointer))
result = *(lispobj *)pointer;
else {
printf("invalid Lisp-level address: ``%s''\n", token+1);
throw_to_monitor();
}
}
else {
printf("invalid address: ``%s''\n", token+1);
throw_to_monitor();
}
}
else if (string_to_long(token, (long *)&result))
;
else if (lookup_symbol(token, &result))
;
else {
printf("invalid Lisp object: ``%s''\n", token);
throw_to_monitor();
}
return result;
}
#endif /* defined(LISP_FEATURE_SB_LDB) */