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 static void skip_ws(char **ptr)
35 while (**ptr <= ' ' && **ptr != '\0')
39 static boolean string_to_long(char *token, long *value)
49 if (token[1] == 'x') {
57 else if (token[0] == '#') {
78 while (*ptr != '\0') {
79 if (*ptr >= 'a' && *ptr <= 'f')
80 digit = *ptr + 10 - 'a';
81 else if (*ptr >= 'A' && *ptr <= 'F')
82 digit = *ptr + 10 - 'A';
83 else if (*ptr >= '0' && *ptr <= '9')
87 if (digit < 0 || digit >= base)
91 num = num * base + digit;
98 static boolean lookup_variable(char *name, lispobj *result)
100 struct var *var = lookup_by_name(name);
105 *result = var_value(var);
122 char *parse_token(ptr)
146 static boolean number_p(token)
154 okay = "abcdefABCDEF987654321d0";
157 if (token[1] == 'x' || token[1] == 'X')
163 else if (token[0] == '#') {
179 while (*token != '\0')
180 if (index(okay, *token++) == NULL)
186 long parse_number(ptr)
189 char *token = parse_token(ptr);
193 printf("expected a number\n");
196 else if (string_to_long(token, &result))
199 printf("invalid number: ``%s''\n", token);
205 char *parse_addr(ptr)
208 char *token = parse_token(ptr);
212 printf("expected an address\n");
215 else if (token[0] == '$') {
216 if (!lookup_variable(token+1, (lispobj *)&result)) {
217 printf("unknown variable: ``%s''\n", token);
223 if (!string_to_long(token, &result)) {
224 printf("invalid number: ``%s''\n", token);
230 if (!is_valid_lisp_addr((os_vm_address_t)result)) {
231 printf("invalid Lisp-level address: 0x%lx\n", result);
235 return (char *)result;
238 static boolean lookup_symbol(char *name, lispobj *result)
243 /* Search static space. */
244 headerptr = (lispobj *)STATIC_SPACE_START;
246 (lispobj *)SymbolValue(STATIC_SPACE_FREE_POINTER) -
247 (lispobj *)STATIC_SPACE_START;
248 if (search_for_symbol(name, &headerptr, &count)) {
249 *result = make_lispobj(headerptr,OTHER_POINTER_LOWTAG);
253 /* Search dynamic space. */
254 headerptr = (lispobj *)DYNAMIC_SPACE_START;
255 #if !defined(__i386__)
257 dynamic_space_free_pointer -
258 (lispobj *)DYNAMIC_SPACE_START;
261 (lispobj *)SymbolValue(ALLOCATION_POINTER) -
262 (lispobj *)DYNAMIC_SPACE_START;
264 if (search_for_symbol(name, &headerptr, &count)) {
265 *result = make_lispobj(headerptr, OTHER_POINTER_LOWTAG);
273 parse_regnum(char *s)
275 if ((s[1] == 'R') || (s[1] == 'r')) {
281 /* skip the $R part and call atoi on the number */
282 regnum = atoi(s + 2);
283 if ((regnum >= 0) && (regnum < NREGS))
290 for (i = 0; i < NREGS ; i++)
291 if (strcasecmp(s + 1, lisp_register_names[i]) == 0)
302 lispobj parse_lispobj(ptr)
305 char *token = parse_token(ptr);
310 printf("expected an object\n");
312 } else if (token[0] == '$') {
313 if (isalpha(token[1])) {
316 os_context_t *context;
318 free = SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX)>>2;
321 printf("Variable ``%s'' is not valid -- there is no current interrupt context.\n", token);
325 context = lisp_interrupt_contexts[free - 1];
327 regnum = parse_regnum(token);
329 printf("bogus register: ``%s''\n", token);
333 result = *os_context_register_addr(context, regnum);
334 } else if (!lookup_variable(token+1, &result)) {
335 printf("unknown variable: ``%s''\n", token);
338 } else if (token[0] == '@') {
339 if (string_to_long(token+1, &pointer)) {
341 if (is_valid_lisp_addr((os_vm_address_t)pointer))
342 result = *(lispobj *)pointer;
344 printf("invalid Lisp-level address: ``%s''\n", token+1);
349 printf("invalid address: ``%s''\n", token+1);
353 else if (string_to_long(token, (long *)&result))
355 else if (lookup_symbol(token, &result))
358 printf("invalid Lisp object: ``%s''\n", token);
365 #endif /* defined(LISP_FEATURE_SB_LDB) */