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.
22 #if defined(LISP_FEATURE_SB_LDB)
28 #include "interrupt.h"
35 #include "pseudo-atomic.h"
37 #include "genesis/simple-fun.h"
38 #include "genesis/fdefn.h"
39 #include "genesis/symbol.h"
40 #include "genesis/static-symbols.h"
42 static void skip_ws(char **ptr)
44 while (**ptr <= ' ' && **ptr != '\0')
48 static boolean string_to_long(char *token, long *value)
58 if (token[1] == 'x') {
66 else if (token[0] == '#') {
87 while (*ptr != '\0') {
88 if (*ptr >= 'a' && *ptr <= 'f')
89 digit = *ptr + 10 - 'a';
90 else if (*ptr >= 'A' && *ptr <= 'F')
91 digit = *ptr + 10 - 'A';
92 else if (*ptr >= '0' && *ptr <= '9')
96 if (digit < 0 || digit >= base)
100 num = num * base + digit;
107 static boolean lookup_variable(char *name, lispobj *result)
109 struct var *var = lookup_by_name(name);
114 *result = var_value(var);
131 char *parse_token(ptr)
155 static boolean number_p(token)
163 okay = "abcdefABCDEF987654321d0";
166 if (token[1] == 'x' || token[1] == 'X')
172 else if (token[0] == '#') {
188 while (*token != '\0')
189 if (index(okay, *token++) == NULL)
195 long parse_number(ptr)
198 char *token = parse_token(ptr);
202 printf("expected a number\n");
205 else if (string_to_long(token, &result))
208 printf("invalid number: ``%s''\n", token);
214 char *parse_addr(ptr)
217 char *token = parse_token(ptr);
221 printf("expected an address\n");
224 else if (token[0] == '$') {
225 if (!lookup_variable(token+1, &result)) {
226 printf("unknown variable: ``%s''\n", token);
233 if (!string_to_long(token, &value)) {
234 printf("invalid number: ``%s''\n", token);
237 result = (value & ~3);
240 if (!is_valid_lisp_addr((os_vm_address_t)result)) {
241 printf("invalid Lisp-level address: %p\n", (void *)result);
245 return (char *)result;
248 static boolean lookup_symbol(char *name, lispobj *result)
253 /* Search static space. */
254 headerptr = (lispobj *)STATIC_SPACE_START;
256 (lispobj *)SymbolValue(STATIC_SPACE_FREE_POINTER,0) -
257 (lispobj *)STATIC_SPACE_START;
258 if (search_for_symbol(name, &headerptr, &count)) {
259 *result = make_lispobj(headerptr,OTHER_POINTER_LOWTAG);
263 /* Search dynamic space. */
264 #if defined(LISP_FEATURE_GENCGC)
265 headerptr = (lispobj *)DYNAMIC_SPACE_START;
266 count = (lispobj *)get_alloc_pointer() - headerptr;
268 headerptr = (lispobj *)current_dynamic_space;
269 count = dynamic_space_free_pointer - headerptr;
272 if (search_for_symbol(name, &headerptr, &count)) {
273 *result = make_lispobj(headerptr, OTHER_POINTER_LOWTAG);
281 parse_regnum(char *s)
283 if ((s[1] == 'R') || (s[1] == 'r')) {
289 /* skip the $R part and call atoi on the number */
290 regnum = atoi(s + 2);
291 if ((regnum >= 0) && (regnum < NREGS))
298 for (i = 0; i < NREGS ; i++)
299 if (strcasecmp(s + 1, lisp_register_names[i]) == 0)
300 #ifdef LISP_FEATURE_X86
310 lispobj parse_lispobj(ptr)
313 struct thread *thread=arch_os_get_current_thread();
314 char *token = parse_token(ptr);
320 printf("expected an object\n");
322 } else if (token[0] == '$') {
323 if (isalpha(token[1])) {
326 os_context_t *context;
328 free_ici = fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX,thread));
331 printf("Variable ``%s'' is not valid -- there is no current interrupt context.\n", token);
335 context = thread->interrupt_contexts[free_ici - 1];
337 regnum = parse_regnum(token);
339 printf("bogus register: ``%s''\n", token);
343 result = *os_context_register_addr(context, regnum);
344 } else if (!lookup_variable(token+1, &result)) {
345 printf("unknown variable: ``%s''\n", token);
348 } else if (token[0] == '@') {
349 if (string_to_long(token+1, &pointer)) {
351 if (is_valid_lisp_addr((os_vm_address_t)pointer))
352 result = *(lispobj *)pointer;
354 printf("invalid Lisp-level address: ``%s''\n", token+1);
359 printf("invalid address: ``%s''\n", token+1);
363 else if (string_to_long(token, &value))
365 else if (lookup_symbol(token, &result))
368 printf("invalid Lisp object: ``%s''\n", token);
375 #endif /* defined(LISP_FEATURE_SB_LDB) */