1 /* Scheme/Guile language support routines for GDB, the GNU debugger.
2 Copyright 1995 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, Boston, MA 02111-1307, USA. */
23 #include "expression.h"
24 #include "parser-defs.h"
31 /* FIXME: Should be in a header file that we import. */
33 c_val_print PARAMS ((struct type *, char *, int, CORE_ADDR, GDB_FILE *, int, int,
34 int, enum val_prettyprint));
36 static void scm_ipruk PARAMS ((char *, LONGEST, GDB_FILE *));
37 static void scm_scmlist_print PARAMS ((LONGEST, GDB_FILE *, int, int,
38 int, enum val_prettyprint));
39 static int scm_inferior_print PARAMS ((LONGEST, GDB_FILE *, int, int,
40 int, enum val_prettyprint));
42 /* Prints the SCM value VALUE by invoking the inferior, if appropraite.
43 Returns >= 0 on succes; retunr -1 if the inferior cannot/should not
47 scm_inferior_print (value, stream, format, deref_ref, recurse, pretty)
53 enum val_prettyprint pretty;
58 /* {Names of immediate symbols}
59 * This table must agree with the declarations in scm.h: {Immediate Symbols}.*/
61 static char *scm_isymnames[] =
63 /* This table must agree with the declarations */
79 "literal-variable-ref",
80 "literal-variable-set!",
83 "call-with-current-continuation",
85 /* user visible ISYMS */
98 scm_scmlist_print (svalue, stream, format, deref_ref, recurse, pretty)
104 enum val_prettyprint pretty;
106 unsigned int more = print_max;
109 fputs_filtered ("...", stream);
112 scm_scmval_print (SCM_CAR (svalue), stream, format,
113 deref_ref, recurse + 1, pretty);
114 svalue = SCM_CDR (svalue);
115 for (; SCM_NIMP (svalue); svalue = SCM_CDR (svalue))
117 if (SCM_NECONSP (svalue))
119 fputs_filtered (" ", stream);
122 fputs_filtered ("...", stream);
125 scm_scmval_print (SCM_CAR (svalue), stream, format,
126 deref_ref, recurse + 1, pretty);
128 if (SCM_NNULLP (svalue))
130 fputs_filtered (" . ", stream);
131 scm_scmval_print (svalue, stream, format,
132 deref_ref, recurse + 1, pretty);
137 scm_ipruk (hdr, ptr, stream)
142 fprintf_filtered (stream, "#<unknown-%s", hdr);
143 #define SCM_SIZE TYPE_LENGTH (builtin_type_scm)
145 fprintf_filtered (stream, " (0x%lx . 0x%lx) @",
146 (long) SCM_CAR (ptr), (long) SCM_CDR (ptr));
147 fprintf_filtered (stream, " 0x%x>", ptr);
151 scm_scmval_print (svalue, stream, format, deref_ref, recurse, pretty)
157 enum val_prettyprint pretty;
160 switch (7 & (int) svalue)
164 print_longest (stream, format ? format : 'd', 1, svalue >> 2);
167 if (SCM_ICHRP (svalue))
169 svalue = SCM_ICHR (svalue);
170 scm_printchar (svalue, stream);
173 else if (SCM_IFLAGP (svalue)
174 && (SCM_ISYMNUM (svalue)
175 < (sizeof scm_isymnames / sizeof (char *))))
177 fputs_filtered (SCM_ISYMCHARS (svalue), stream);
180 else if (SCM_ILOCP (svalue))
182 fprintf_filtered (stream, "#@%ld%c%ld",
183 (long) SCM_IFRAME (svalue),
184 SCM_ICDRP (svalue) ? '-' : '+',
185 (long) SCM_IDIST (svalue));
193 svalue = SCM_CAR (svalue - 1);
197 scm_ipruk ("immediate", svalue, stream);
201 switch (SCM_TYP7 (svalue))
203 case scm_tcs_cons_gloc:
204 if (SCM_CDR (SCM_CAR (svalue) - 1L) == 0)
209 fputs_filtered ("#<latte ", stream);
211 fputs_filtered ("???", stream);
213 name = ((SCM n*)(STRUCT_TYPE( exp)))[struct_i_name];
214 scm_lfwrite (CHARS (name),
215 (sizet) sizeof (char),
216 (sizet) LENGTH (name),
219 fprintf_filtered (stream, " #X%lX>", svalue);
222 case scm_tcs_cons_imcar:
223 case scm_tcs_cons_nimcar:
224 fputs_filtered ("(", stream);
225 scm_scmlist_print (svalue, stream, format,
226 deref_ref, recurse + 1, pretty);
227 fputs_filtered (")", stream);
229 case scm_tcs_closures:
230 fputs_filtered ("#<CLOSURE ", stream);
231 scm_scmlist_print (SCM_CODE (svalue), stream, format,
232 deref_ref, recurse + 1, pretty);
233 fputs_filtered (">", stream);
237 int len = SCM_LENGTH (svalue);
238 CORE_ADDR addr = (CORE_ADDR) SCM_CDR (svalue);
243 int truncate = print_max && len > (int) print_max;
246 fputs_filtered ("\"", stream);
247 for (; done < len; done += buf_size)
249 buf_size = min (len - done, 64);
250 read_memory (addr + done, buffer, buf_size);
252 for (i = 0; i < buf_size; ++i)
257 fputs_filtered ("\\", stream);
259 fprintf_filtered (stream, "%c", buffer[i]);
262 fputs_filtered (truncate ? "...\"" : "\"", stream);
266 case scm_tcs_symbols:
268 int len = SCM_LENGTH (svalue);
270 char * str = (char*) alloca (len);
271 read_memory (SCM_CDR (svalue), str, len + 1);
272 /* Should handle weird characters FIXME */
274 fputs_filtered (str, stream);
279 int len = SCM_LENGTH (svalue);
281 LONGEST elements = SCM_CDR(svalue);
282 fputs_filtered ("#(", stream);
283 for (i = 0; i < len; ++i)
286 fputs_filtered (" ", stream);
287 scm_scmval_print (scm_get_field (elements, i), stream, format,
288 deref_ref, recurse + 1, pretty);
290 fputs_filtered (")", stream);
298 hook = scm_get_lvector_hook (exp, LV_PRINT_FN);
301 scm_puts ("#<locked-vector ", port);
302 scm_intprint(CDR(exp), 16, port);
303 scm_puts (">", port);
309 scm_listify (exp, port, (writing ? BOOL_T : BOOL_F),
312 if (result == BOOL_F)
324 scm_raprin1 (exp, port, writing);
329 int index = SCM_CAR (svalue) >> 8;
332 sprintf (str, "#%d", index);
334 char *str = index ? SCM_CHARS (scm_heap_org+index) : "";
335 #define SCM_CHARS(x) ((char *)(SCM_CDR(x)))
336 char *str = CHARS (SNAME (exp));
338 fprintf_filtered (stream, "#<primitive-procedure %s>",
345 scm_puts ("#<compiled-closure ", port);
346 scm_iprin1 (CCLO_SUBR (exp), port, writing);
347 scm_putc ('>', port);
351 fprintf_filtered (stream, "#<continuation %d @ #X%lx >",
353 (long) CHARS (svalue));
357 if (i < scm_numptob && scm_ptobs[i].print && (scm_ptobs[i].print) (exp, port, writing))
362 if (i < scm_numsmob && scm_smobs[i].print
363 && (scm_smobs[i].print) (exp, port, writing))
371 scm_ipruk ("type", svalue, stream);
378 scm_val_print (type, valaddr, embedded_offset, address,
379 stream, format, deref_ref, recurse, pretty)
388 enum val_prettyprint pretty;
390 if (is_scmvalue_type (type))
392 LONGEST svalue = extract_signed_integer (valaddr, TYPE_LENGTH (type));
393 if (scm_inferior_print (svalue, stream, format,
394 deref_ref, recurse, pretty) >= 0)
399 scm_scmval_print (svalue, stream, format,
400 deref_ref, recurse, pretty);
408 return c_val_print (type, valaddr, 0, address, stream, format,
409 deref_ref, recurse, pretty);
414 scm_value_print (val, stream, format, pretty)
418 enum val_prettyprint pretty;
420 return (val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
421 VALUE_ADDRESS (val), stream, format, 1, 0, pretty));