1 /* parsing for LDB monitor */
4 * This software is part of the SBCL system. See the README file for
7 * This software is derived from the CMU CL system, which was
8 * written at Carnegie Mellon University and released into the
9 * public domain. The software is in the public domain and is
10 * provided with absolutely no warranty. See the COPYING and CREDITS
11 * files for more information.
21 #if defined(LISP_FEATURE_SB_LDB)
27 #include "interrupt.h"
33 #include "genesis/simple-fun.h"
34 #include "genesis/fdefn.h"
35 #include "genesis/symbol.h"
36 #include "genesis/static-symbols.h"
38 static void skip_ws(char **ptr)
40 while (**ptr <= ' ' && **ptr != '\0')
44 static boolean string_to_long(char *token, long *value)
54 if (token[1] == 'x') {
62 else if (token[0] == '#') {
83 while (*ptr != '\0') {
84 if (*ptr >= 'a' && *ptr <= 'f')
85 digit = *ptr + 10 - 'a';
86 else if (*ptr >= 'A' && *ptr <= 'F')
87 digit = *ptr + 10 - 'A';
88 else if (*ptr >= '0' && *ptr <= '9')
92 if (digit < 0 || digit >= base)
96 num = num * base + digit;
103 static boolean lookup_variable(char *name, lispobj *result)
105 struct var *var = lookup_by_name(name);
110 *result = var_value(var);
127 char *parse_token(ptr)
151 static boolean number_p(token)
159 okay = "abcdefABCDEF987654321d0";
162 if (token[1] == 'x' || token[1] == 'X')
168 else if (token[0] == '#') {
184 while (*token != '\0')
185 if (index(okay, *token++) == NULL)
191 long parse_number(ptr)
194 char *token = parse_token(ptr);
198 printf("expected a number\n");
201 else if (string_to_long(token, &result))
204 printf("invalid number: ``%s''\n", token);
210 char *parse_addr(ptr)
213 char *token = parse_token(ptr);
217 printf("expected an address\n");
220 else if (token[0] == '$') {
221 if (!lookup_variable(token+1, (lispobj *)&result)) {
222 printf("unknown variable: ``%s''\n", token);
228 if (!string_to_long(token, &result)) {
229 printf("invalid number: ``%s''\n", token);
235 if (!is_valid_lisp_addr((os_vm_address_t)result)) {
236 printf("invalid Lisp-level address: 0x%lx\n", result);
240 return (char *)result;
243 static boolean lookup_symbol(char *name, lispobj *result)
248 /* Search static space. */
249 headerptr = (lispobj *)STATIC_SPACE_START;
251 (lispobj *)SymbolValue(STATIC_SPACE_FREE_POINTER) -
252 (lispobj *)STATIC_SPACE_START;
253 if (search_for_symbol(name, &headerptr, &count)) {
254 *result = make_lispobj(headerptr,OTHER_POINTER_LOWTAG);
258 /* Search dynamic space. */
259 headerptr = (lispobj *)DYNAMIC_SPACE_START;
260 #if !defined(__i386__)
262 dynamic_space_free_pointer -
263 (lispobj *)DYNAMIC_SPACE_START;
266 (lispobj *)SymbolValue(ALLOCATION_POINTER) -
267 (lispobj *)DYNAMIC_SPACE_START;
269 if (search_for_symbol(name, &headerptr, &count)) {
270 *result = make_lispobj(headerptr, OTHER_POINTER_LOWTAG);
278 parse_regnum(char *s)
280 if ((s[1] == 'R') || (s[1] == 'r')) {
286 /* skip the $R part and call atoi on the number */
287 regnum = atoi(s + 2);
288 if ((regnum >= 0) && (regnum < NREGS))
295 for (i = 0; i < NREGS ; i++)
296 if (strcasecmp(s + 1, lisp_register_names[i]) == 0)
307 lispobj parse_lispobj(ptr)
310 char *token = parse_token(ptr);
315 printf("expected an object\n");
317 } else if (token[0] == '$') {
318 if (isalpha(token[1])) {
321 os_context_t *context;
323 free = SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX)>>2;
326 printf("Variable ``%s'' is not valid -- there is no current interrupt context.\n", token);
330 context = lisp_interrupt_contexts[free - 1];
332 regnum = parse_regnum(token);
334 printf("bogus register: ``%s''\n", token);
338 result = *os_context_register_addr(context, regnum);
339 } else if (!lookup_variable(token+1, &result)) {
340 printf("unknown variable: ``%s''\n", token);
343 } else if (token[0] == '@') {
344 if (string_to_long(token+1, &pointer)) {
346 if (is_valid_lisp_addr((os_vm_address_t)pointer))
347 result = *(lispobj *)pointer;
349 printf("invalid Lisp-level address: ``%s''\n", token+1);
354 printf("invalid address: ``%s''\n", token+1);
358 else if (string_to_long(token, (long *)&result))
360 else if (lookup_symbol(token, &result))
363 printf("invalid Lisp object: ``%s''\n", token);
370 #endif /* defined(LISP_FEATURE_SB_LDB) */