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"
30 /* Prints the SCM value VALUE by invoking the inferior, if appropraite.
31 Returns >= 0 on succes; retunr -1 if the inferior cannot/should not
35 scm_inferior_print (value, stream, format, deref_ref, recurse, pretty)
41 enum val_prettyprint pretty;
46 /* {Names of immediate symbols}
47 * This table must agree with the declarations in scm.h: {Immediate Symbols}.*/
49 static char *scm_isymnames[] =
51 /* This table must agree with the declarations */
67 "literal-variable-ref",
68 "literal-variable-set!",
71 "call-with-current-continuation",
73 /* user visible ISYMS */
86 scm_scmlist_print (svalue, stream, format, deref_ref, recurse, pretty)
92 enum val_prettyprint pretty;
94 unsigned int more = print_max;
97 fputs_filtered ("...", stream);
100 scm_scmval_print (SCM_CAR (svalue), stream, format,
101 deref_ref, recurse + 1, pretty);
102 svalue = SCM_CDR (svalue);
103 for (; SCM_NIMP (svalue); svalue = SCM_CDR (svalue))
105 if (SCM_NECONSP (svalue))
107 fputs_filtered (" ", stream);
110 fputs_filtered ("...", stream);
113 scm_scmval_print (SCM_CAR (svalue), stream, format,
114 deref_ref, recurse + 1, pretty);
116 if (SCM_NNULLP (svalue))
118 fputs_filtered (" . ", stream);
119 scm_scmval_print (svalue, stream, format,
120 deref_ref, recurse + 1, pretty);
125 scm_ipruk (hdr, ptr, stream)
130 fprintf_filtered (stream, "#<unknown-%s", hdr);
131 #define SCM_SIZE TYPE_LENGTH (builtin_type_scm)
133 fprintf_filtered (stream, " (0x%lx . 0x%lx) @",
134 (long) SCM_CAR (ptr), (long) SCM_CDR (ptr));
135 fprintf_filtered (stream, " 0x%x>", ptr);
139 scm_scmval_print (svalue, stream, format, deref_ref, recurse, pretty)
145 enum val_prettyprint pretty;
152 print_longest (stream, format ? format : 'd', 1, svalue >> 2);
155 if (SCM_ICHRP (svalue))
157 svalue = SCM_ICHR (svalue);
158 scm_printchar (svalue, stream);
161 else if (SCM_IFLAGP (svalue)
162 && (SCM_ISYMNUM (svalue)
163 < (sizeof scm_isymnames / sizeof (char *))))
165 fputs_filtered (SCM_ISYMCHARS (svalue), stream);
168 else if (SCM_ILOCP (svalue))
170 fprintf_filtered (stream, "#@%ld%c%ld",
171 (long) SCM_IFRAME (svalue),
172 SCM_ICDRP (svalue) ? '-' : '+',
173 (long) SCM_IDIST (svalue));
181 svalue = SCM_CAR (svalue - 1);
185 scm_ipruk ("immediate", svalue, stream);
189 switch (SCM_TYP7 (svalue))
191 case scm_tcs_cons_gloc:
192 if (SCM_CDR (SCM_CAR (svalue) - 1L) == 0)
195 fputs_filtered ("#<latte ", stream);
197 fputs_filtered ("???", stream);
199 name = ((SCM n*)(STRUCT_TYPE( exp)))[struct_i_name];
200 scm_lfwrite (CHARS (name),
201 (sizet) sizeof (char),
202 (sizet) LENGTH (name),
205 fprintf_filtered (stream, " #X%lX>", svalue);
208 case scm_tcs_cons_imcar:
209 case scm_tcs_cons_nimcar:
210 fputs_filtered ("(", stream);
211 scm_scmlist_print (svalue, stream, format,
212 deref_ref, recurse + 1, pretty);
213 fputs_filtered (")", stream);
215 case scm_tcs_closures:
216 fputs_filtered ("#<CLOSURE ", stream);
217 scm_scmlist_print (SCM_CODE (svalue), stream, format,
218 deref_ref, recurse + 1, pretty);
219 fputs_filtered (">", stream);
223 int len = SCM_LENGTH (svalue);
224 CORE_ADDR addr = (CORE_ADDR) SCM_CDR (svalue);
229 int truncate = print_max && len > (int) print_max;
232 fputs_filtered ("\"", stream);
233 for (; done < len; done += buf_size)
235 buf_size = min (len - done, 64);
236 read_memory (addr + done, buffer, buf_size);
238 for (i = 0; i < buf_size; ++i)
243 fputs_filtered ("\\", stream);
245 fprintf_filtered (stream, "%c", buffer[i]);
248 fputs_filtered (truncate ? "...\"" : "\"", stream);
252 case scm_tcs_symbols:
254 int len = SCM_LENGTH (svalue);
256 char * str = (char*) alloca (len);
257 read_memory (SCM_CDR (svalue), str, len + 1);
258 /* Should handle weird characters FIXME */
260 fputs_filtered (str, stream);
265 int len = SCM_LENGTH (svalue);
267 LONGEST elements = SCM_CDR(svalue);
268 fputs_filtered ("#(", stream);
269 for (i = 0; i < len; ++i)
272 fputs_filtered (" ", stream);
273 scm_scmval_print (scm_get_field (elements, i), stream, format,
274 deref_ref, recurse + 1, pretty);
276 fputs_filtered (")", stream);
284 hook = scm_get_lvector_hook (exp, LV_PRINT_FN);
287 scm_puts ("#<locked-vector ", port);
288 scm_intprint(CDR(exp), 16, port);
289 scm_puts (">", port);
295 scm_listify (exp, port, (writing ? BOOL_T : BOOL_F),
298 if (result == BOOL_F)
310 scm_raprin1 (exp, port, writing);
315 int index = SCM_CAR (svalue) >> 8;
318 sprintf (str, "#%d", index);
320 char *str = index ? SCM_CHARS (scm_heap_org+index) : "";
321 #define SCM_CHARS(x) ((char *)(SCM_CDR(x)))
322 char *str = CHARS (SNAME (exp));
324 fprintf_filtered (stream, "#<primitive-procedure %s>",
331 scm_puts ("#<compiled-closure ", port);
332 scm_iprin1 (CCLO_SUBR (exp), port, writing);
333 scm_putc ('>', port);
337 fprintf_filtered (stream, "#<continuation %d @ #X%lx >",
339 (long) CHARS (svalue));
343 if (i < scm_numptob && scm_ptobs[i].print && (scm_ptobs[i].print) (exp, port, writing))
348 if (i < scm_numsmob && scm_smobs[i].print
349 && (scm_smobs[i].print) (exp, port, writing))
354 punk:scm_ipruk ("type", svalue, stream);
361 scm_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
370 enum val_prettyprint pretty;
372 if (is_scmvalue_type (type))
374 LONGEST svalue = extract_signed_integer (valaddr, TYPE_LENGTH (type));
375 if (scm_inferior_print (svalue, stream, format,
376 deref_ref, recurse, pretty) >= 0)
381 scm_scmval_print (svalue, stream, format,
382 deref_ref, recurse, pretty);
390 return c_val_print (type, valaddr, address, stream, format,
391 deref_ref, recurse, pretty);
396 scm_value_print (val, stream, format, pretty)
400 enum val_prettyprint pretty;
402 return (val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
403 VALUE_ADDRESS (val), stream, format, 1, 0, pretty));