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"
34 #include "genesis/simple-fun.h"
35 #include "genesis/fdefn.h"
36 #include "genesis/symbol.h"
37 #include "genesis/static-symbols.h"
39 static void skip_ws(char **ptr
)
41 while (**ptr
<= ' ' && **ptr
!= '\0')
45 static boolean
string_to_long(char *token
, long *value
)
55 if (token
[1] == 'x') {
63 else if (token
[0] == '#') {
84 while (*ptr
!= '\0') {
85 if (*ptr
>= 'a' && *ptr
<= 'f')
86 digit
= *ptr
+ 10 - 'a';
87 else if (*ptr
>= 'A' && *ptr
<= 'F')
88 digit
= *ptr
+ 10 - 'A';
89 else if (*ptr
>= '0' && *ptr
<= '9')
93 if (digit
< 0 || digit
>= base
)
97 num
= num
* base
+ digit
;
104 static boolean
lookup_variable(char *name
, lispobj
*result
)
106 struct var
*var
= lookup_by_name(name
);
111 *result
= var_value(var
);
128 char *parse_token(ptr
)
152 static boolean
number_p(token
)
160 okay
= "abcdefABCDEF987654321d0";
163 if (token
[1] == 'x' || token
[1] == 'X')
169 else if (token
[0] == '#') {
185 while (*token
!= '\0')
186 if (index(okay
, *token
++) == NULL
)
192 long parse_number(ptr
)
195 char *token
= parse_token(ptr
);
199 printf("expected a number\n");
202 else if (string_to_long(token
, &result
))
205 printf("invalid number: ``%s''\n", token
);
211 char *parse_addr(ptr
)
214 char *token
= parse_token(ptr
);
218 printf("expected an address\n");
221 else if (token
[0] == '$') {
222 if (!lookup_variable(token
+1, (lispobj
*)&result
)) {
223 printf("unknown variable: ``%s''\n", token
);
229 if (!string_to_long(token
, &result
)) {
230 printf("invalid number: ``%s''\n", token
);
236 if (!is_valid_lisp_addr((os_vm_address_t
)result
)) {
237 printf("invalid Lisp-level address: 0x%lx\n", result
);
241 return (char *)result
;
244 static boolean
lookup_symbol(char *name
, lispobj
*result
)
249 /* Search static space. */
250 headerptr
= (lispobj
*)STATIC_SPACE_START
;
252 (lispobj
*)SymbolValue(STATIC_SPACE_FREE_POINTER
,0) -
253 (lispobj
*)STATIC_SPACE_START
;
254 if (search_for_symbol(name
, &headerptr
, &count
)) {
255 *result
= make_lispobj(headerptr
,OTHER_POINTER_LOWTAG
);
259 /* Search dynamic space. */
260 headerptr
= (lispobj
*)DYNAMIC_SPACE_START
;
261 #if !defined(__i386__)
263 dynamic_space_free_pointer
-
264 (lispobj
*)DYNAMIC_SPACE_START
;
267 (lispobj
*)SymbolValue(ALLOCATION_POINTER
,0) -
268 (lispobj
*)DYNAMIC_SPACE_START
;
270 if (search_for_symbol(name
, &headerptr
, &count
)) {
271 *result
= make_lispobj(headerptr
, OTHER_POINTER_LOWTAG
);
279 parse_regnum(char *s
)
281 if ((s
[1] == 'R') || (s
[1] == 'r')) {
287 /* skip the $R part and call atoi on the number */
288 regnum
= atoi(s
+ 2);
289 if ((regnum
>= 0) && (regnum
< NREGS
))
296 for (i
= 0; i
< NREGS
; i
++)
297 if (strcasecmp(s
+ 1, lisp_register_names
[i
]) == 0)
308 lispobj
parse_lispobj(ptr
)
311 struct thread
*thread
=arch_os_get_current_thread();
312 char *token
= parse_token(ptr
);
317 printf("expected an object\n");
319 } else if (token
[0] == '$') {
320 if (isalpha(token
[1])) {
323 os_context_t
*context
;
325 free
= SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX
,thread
)>>2;
328 printf("Variable ``%s'' is not valid -- there is no current interrupt context.\n", token
);
332 context
= thread
->interrupt_contexts
[free
- 1];
334 regnum
= parse_regnum(token
);
336 printf("bogus register: ``%s''\n", token
);
340 result
= *os_context_register_addr(context
, regnum
);
341 } else if (!lookup_variable(token
+1, &result
)) {
342 printf("unknown variable: ``%s''\n", token
);
345 } else if (token
[0] == '@') {
346 if (string_to_long(token
+1, &pointer
)) {
348 if (is_valid_lisp_addr((os_vm_address_t
)pointer
))
349 result
= *(lispobj
*)pointer
;
351 printf("invalid Lisp-level address: ``%s''\n", token
+1);
356 printf("invalid address: ``%s''\n", token
+1);
360 else if (string_to_long(token
, (long *)&result
))
362 else if (lookup_symbol(token
, &result
))
365 printf("invalid Lisp object: ``%s''\n", token
);
372 #endif /* defined(LISP_FEATURE_SB_LDB) */