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"
36 #include "genesis/simple-fun.h"
37 #include "genesis/fdefn.h"
38 #include "genesis/symbol.h"
39 #include "genesis/static-symbols.h"
41 static void skip_ws(char **ptr
)
43 while (**ptr
<= ' ' && **ptr
!= '\0')
47 static boolean
string_to_long(char *token
, long *value
)
57 if (token
[1] == 'x') {
65 else if (token
[0] == '#') {
86 while (*ptr
!= '\0') {
87 if (*ptr
>= 'a' && *ptr
<= 'f')
88 digit
= *ptr
+ 10 - 'a';
89 else if (*ptr
>= 'A' && *ptr
<= 'F')
90 digit
= *ptr
+ 10 - 'A';
91 else if (*ptr
>= '0' && *ptr
<= '9')
95 if (digit
< 0 || digit
>= base
)
99 num
= num
* base
+ digit
;
106 static boolean
lookup_variable(char *name
, lispobj
*result
)
108 struct var
*var
= lookup_by_name(name
);
113 *result
= var_value(var
);
130 char *parse_token(ptr
)
154 static boolean
number_p(token
)
162 okay
= "abcdefABCDEF987654321d0";
165 if (token
[1] == 'x' || token
[1] == 'X')
171 else if (token
[0] == '#') {
187 while (*token
!= '\0')
188 if (index(okay
, *token
++) == NULL
)
194 long parse_number(ptr
)
197 char *token
= parse_token(ptr
);
201 printf("expected a number\n");
204 else if (string_to_long(token
, &result
))
207 printf("invalid number: ``%s''\n", token
);
213 char *parse_addr(ptr
)
216 char *token
= parse_token(ptr
);
220 printf("expected an address\n");
223 else if (token
[0] == '$') {
224 if (!lookup_variable(token
+1, &result
)) {
225 printf("unknown variable: ``%s''\n", token
);
232 if (!string_to_long(token
, &value
)) {
233 printf("invalid number: ``%s''\n", token
);
236 result
= (value
& ~3);
239 if (!is_valid_lisp_addr((os_vm_address_t
)result
)) {
240 printf("invalid Lisp-level address: %p\n", (void *)result
);
244 return (char *)result
;
247 static boolean
lookup_symbol(char *name
, lispobj
*result
)
252 /* Search static space. */
253 headerptr
= (lispobj
*)STATIC_SPACE_START
;
255 (lispobj
*)SymbolValue(STATIC_SPACE_FREE_POINTER
,0) -
256 (lispobj
*)STATIC_SPACE_START
;
257 if (search_for_symbol(name
, &headerptr
, &count
)) {
258 *result
= make_lispobj(headerptr
,OTHER_POINTER_LOWTAG
);
262 /* Search dynamic space. */
263 #if defined(LISP_FEATURE_GENCGC)
264 headerptr
= (lispobj
*)DYNAMIC_SPACE_START
;
265 count
= (lispobj
*)get_alloc_pointer() - headerptr
;
267 headerptr
= (lispobj
*)current_dynamic_space
;
268 count
= dynamic_space_free_pointer
- headerptr
;
271 if (search_for_symbol(name
, &headerptr
, &count
)) {
272 *result
= make_lispobj(headerptr
, OTHER_POINTER_LOWTAG
);
280 parse_regnum(char *s
)
282 if ((s
[1] == 'R') || (s
[1] == 'r')) {
288 /* skip the $R part and call atoi on the number */
289 regnum
= atoi(s
+ 2);
290 if ((regnum
>= 0) && (regnum
< NREGS
))
297 for (i
= 0; i
< NREGS
; i
++)
298 if (strcasecmp(s
+ 1, lisp_register_names
[i
]) == 0)
299 #ifdef LISP_FEATURE_X86
309 lispobj
parse_lispobj(ptr
)
312 struct thread
*thread
=arch_os_get_current_thread();
313 char *token
= parse_token(ptr
);
319 printf("expected an object\n");
321 } else if (token
[0] == '$') {
322 if (isalpha(token
[1])) {
325 os_context_t
*context
;
327 free_ici
= fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX
,thread
));
330 printf("Variable ``%s'' is not valid -- there is no current interrupt context.\n", token
);
334 context
= thread
->interrupt_contexts
[free_ici
- 1];
336 regnum
= parse_regnum(token
);
338 printf("bogus register: ``%s''\n", token
);
342 result
= *os_context_register_addr(context
, regnum
);
343 } else if (!lookup_variable(token
+1, &result
)) {
344 printf("unknown variable: ``%s''\n", token
);
347 } else if (token
[0] == '@') {
348 if (string_to_long(token
+1, &pointer
)) {
350 if (is_valid_lisp_addr((os_vm_address_t
)pointer
))
351 result
= *(lispobj
*)pointer
;
353 printf("invalid Lisp-level address: ``%s''\n", token
+1);
358 printf("invalid address: ``%s''\n", token
+1);
362 else if (string_to_long(token
, &value
))
364 else if (lookup_symbol(token
, &result
))
367 printf("invalid Lisp object: ``%s''\n", token
);
374 #endif /* defined(LISP_FEATURE_SB_LDB) */