1 /* Scheme/Guile language support routines for GDB, the GNU debugger.
2 Copyright 1995, 2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
24 #include "expression.h"
25 #include "parser-defs.h"
32 /* FIXME: Should be in a header file that we import. */
33 extern int c_val_print (struct type
*, char *, int, CORE_ADDR
,
34 struct ui_file
*, int, int, int,
35 enum val_prettyprint
);
37 static void scm_ipruk (char *, LONGEST
, struct ui_file
*);
38 static void scm_scmlist_print (LONGEST
, struct ui_file
*, int, int,
39 int, enum val_prettyprint
);
40 static int scm_inferior_print (LONGEST
, struct ui_file
*, int, int,
41 int, enum val_prettyprint
);
43 /* Prints the SCM value VALUE by invoking the inferior, if appropraite.
44 Returns >= 0 on succes; retunr -1 if the inferior cannot/should not
48 scm_inferior_print (value
, stream
, format
, deref_ref
, recurse
, pretty
)
50 struct ui_file
*stream
;
54 enum val_prettyprint pretty
;
59 /* {Names of immediate symbols}
60 * This table must agree with the declarations in scm.h: {Immediate Symbols}.*/
62 static char *scm_isymnames
[] =
64 /* This table must agree with the declarations */
80 "literal-variable-ref",
81 "literal-variable-set!",
84 "call-with-current-continuation",
86 /* user visible ISYMS */
99 scm_scmlist_print (svalue
, stream
, format
, deref_ref
, recurse
, pretty
)
101 struct ui_file
*stream
;
105 enum val_prettyprint pretty
;
107 unsigned int more
= print_max
;
110 fputs_filtered ("...", stream
);
113 scm_scmval_print (SCM_CAR (svalue
), stream
, format
,
114 deref_ref
, recurse
+ 1, pretty
);
115 svalue
= SCM_CDR (svalue
);
116 for (; SCM_NIMP (svalue
); svalue
= SCM_CDR (svalue
))
118 if (SCM_NECONSP (svalue
))
120 fputs_filtered (" ", stream
);
123 fputs_filtered ("...", stream
);
126 scm_scmval_print (SCM_CAR (svalue
), stream
, format
,
127 deref_ref
, recurse
+ 1, pretty
);
129 if (SCM_NNULLP (svalue
))
131 fputs_filtered (" . ", stream
);
132 scm_scmval_print (svalue
, stream
, format
,
133 deref_ref
, recurse
+ 1, pretty
);
138 scm_ipruk (hdr
, ptr
, stream
)
141 struct ui_file
*stream
;
143 fprintf_filtered (stream
, "#<unknown-%s", hdr
);
144 #define SCM_SIZE TYPE_LENGTH (builtin_type_scm)
146 fprintf_filtered (stream
, " (0x%lx . 0x%lx) @",
147 (long) SCM_CAR (ptr
), (long) SCM_CDR (ptr
));
148 fprintf_filtered (stream
, " 0x%s>", paddr_nz (ptr
));
152 scm_scmval_print (svalue
, stream
, format
, deref_ref
, recurse
, pretty
)
154 struct ui_file
*stream
;
158 enum val_prettyprint pretty
;
161 switch (7 & (int) svalue
)
165 print_longest (stream
, format
? format
: 'd', 1, svalue
>> 2);
168 if (SCM_ICHRP (svalue
))
170 svalue
= SCM_ICHR (svalue
);
171 scm_printchar (svalue
, stream
);
174 else if (SCM_IFLAGP (svalue
)
175 && (SCM_ISYMNUM (svalue
)
176 < (sizeof scm_isymnames
/ sizeof (char *))))
178 fputs_filtered (SCM_ISYMCHARS (svalue
), stream
);
181 else if (SCM_ILOCP (svalue
))
183 fprintf_filtered (stream
, "#@%ld%c%ld",
184 (long) SCM_IFRAME (svalue
),
185 SCM_ICDRP (svalue
) ? '-' : '+',
186 (long) SCM_IDIST (svalue
));
194 svalue
= SCM_CAR (svalue
- 1);
198 scm_ipruk ("immediate", svalue
, stream
);
202 switch (SCM_TYP7 (svalue
))
204 case scm_tcs_cons_gloc
:
205 if (SCM_CDR (SCM_CAR (svalue
) - 1L) == 0)
210 fputs_filtered ("#<latte ", stream
);
212 fputs_filtered ("???", stream
);
214 name
= ((SCM n
*) (STRUCT_TYPE (exp
)))[struct_i_name
];
215 scm_lfwrite (CHARS (name
),
216 (sizet
) sizeof (char),
217 (sizet
) LENGTH (name
),
220 fprintf_filtered (stream
, " #X%s>", paddr_nz (svalue
));
223 case scm_tcs_cons_imcar
:
224 case scm_tcs_cons_nimcar
:
225 fputs_filtered ("(", stream
);
226 scm_scmlist_print (svalue
, stream
, format
,
227 deref_ref
, recurse
+ 1, pretty
);
228 fputs_filtered (")", stream
);
230 case scm_tcs_closures
:
231 fputs_filtered ("#<CLOSURE ", stream
);
232 scm_scmlist_print (SCM_CODE (svalue
), stream
, format
,
233 deref_ref
, recurse
+ 1, pretty
);
234 fputs_filtered (">", stream
);
238 int len
= SCM_LENGTH (svalue
);
239 CORE_ADDR addr
= (CORE_ADDR
) SCM_CDR (svalue
);
244 int truncate
= print_max
&& len
> (int) print_max
;
247 fputs_filtered ("\"", stream
);
248 for (; done
< len
; done
+= buf_size
)
250 buf_size
= min (len
- done
, 64);
251 read_memory (addr
+ done
, buffer
, buf_size
);
253 for (i
= 0; i
< buf_size
; ++i
)
258 fputs_filtered ("\\", stream
);
260 fprintf_filtered (stream
, "%c", buffer
[i
]);
263 fputs_filtered (truncate
? "...\"" : "\"", stream
);
267 case scm_tcs_symbols
:
269 int len
= SCM_LENGTH (svalue
);
271 char *str
= (char *) alloca (len
);
272 read_memory (SCM_CDR (svalue
), str
, len
+ 1);
273 /* Should handle weird characters FIXME */
275 fputs_filtered (str
, stream
);
280 int len
= SCM_LENGTH (svalue
);
282 LONGEST elements
= SCM_CDR (svalue
);
283 fputs_filtered ("#(", stream
);
284 for (i
= 0; i
< len
; ++i
)
287 fputs_filtered (" ", stream
);
288 scm_scmval_print (scm_get_field (elements
, i
), stream
, format
,
289 deref_ref
, recurse
+ 1, pretty
);
291 fputs_filtered (")", stream
);
299 hook
= scm_get_lvector_hook (exp
, LV_PRINT_FN
);
302 scm_puts ("#<locked-vector ", port
);
303 scm_intprint (CDR (exp
), 16, port
);
304 scm_puts (">", port
);
310 scm_listify (exp
, port
, (writing
? BOOL_T
: BOOL_F
),
313 if (result
== BOOL_F
)
325 scm_raprin1 (exp
, port
, writing
);
330 int index
= SCM_CAR (svalue
) >> 8;
333 sprintf (str
, "#%d", index
);
335 char *str
= index
? SCM_CHARS (scm_heap_org
+ index
) : "";
336 #define SCM_CHARS(x) ((char *)(SCM_CDR(x)))
337 char *str
= CHARS (SNAME (exp
));
339 fprintf_filtered (stream
, "#<primitive-procedure %s>",
346 scm_puts ("#<compiled-closure ", port
);
347 scm_iprin1 (CCLO_SUBR (exp
), port
, writing
);
348 scm_putc ('>', port
);
352 fprintf_filtered (stream
, "#<continuation %d @ #X%lx >",
354 (long) CHARS (svalue
));
358 if (i
< scm_numptob
&& scm_ptobs
[i
].print
&& (scm_ptobs
[i
].print
) (exp
, port
, writing
))
363 if (i
< scm_numsmob
&& scm_smobs
[i
].print
364 && (scm_smobs
[i
].print
) (exp
, port
, writing
))
372 scm_ipruk ("type", svalue
, stream
);
379 scm_val_print (type
, valaddr
, embedded_offset
, address
,
380 stream
, format
, deref_ref
, recurse
, pretty
)
385 struct ui_file
*stream
;
389 enum val_prettyprint pretty
;
391 if (is_scmvalue_type (type
))
393 LONGEST svalue
= extract_signed_integer (valaddr
, TYPE_LENGTH (type
));
394 if (scm_inferior_print (svalue
, stream
, format
,
395 deref_ref
, recurse
, pretty
) >= 0)
400 scm_scmval_print (svalue
, stream
, format
,
401 deref_ref
, recurse
, pretty
);
409 return c_val_print (type
, valaddr
, 0, address
, stream
, format
,
410 deref_ref
, recurse
, pretty
);
415 scm_value_print (val
, stream
, format
, pretty
)
417 struct ui_file
*stream
;
419 enum val_prettyprint pretty
;
421 return (val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), 0,
422 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
));
This page took 0.038024 seconds and 4 git commands to generate.