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 (LONGEST value
, struct ui_file
*stream
, int format
,
49 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
54 /* {Names of immediate symbols}
55 * This table must agree with the declarations in scm.h: {Immediate Symbols}.*/
57 static char *scm_isymnames
[] =
59 /* This table must agree with the declarations */
75 "literal-variable-ref",
76 "literal-variable-set!",
79 "call-with-current-continuation",
81 /* user visible ISYMS */
94 scm_scmlist_print (LONGEST svalue
, struct ui_file
*stream
, int format
,
95 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
97 unsigned int more
= print_max
;
100 fputs_filtered ("...", stream
);
103 scm_scmval_print (SCM_CAR (svalue
), stream
, format
,
104 deref_ref
, recurse
+ 1, pretty
);
105 svalue
= SCM_CDR (svalue
);
106 for (; SCM_NIMP (svalue
); svalue
= SCM_CDR (svalue
))
108 if (SCM_NECONSP (svalue
))
110 fputs_filtered (" ", stream
);
113 fputs_filtered ("...", stream
);
116 scm_scmval_print (SCM_CAR (svalue
), stream
, format
,
117 deref_ref
, recurse
+ 1, pretty
);
119 if (SCM_NNULLP (svalue
))
121 fputs_filtered (" . ", stream
);
122 scm_scmval_print (svalue
, stream
, format
,
123 deref_ref
, recurse
+ 1, pretty
);
128 scm_ipruk (char *hdr
, LONGEST ptr
, struct ui_file
*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%s>", paddr_nz (ptr
));
139 scm_scmval_print (LONGEST svalue
, struct ui_file
*stream
, int format
,
140 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
143 switch (7 & (int) svalue
)
147 print_longest (stream
, format
? format
: 'd', 1, svalue
>> 2);
150 if (SCM_ICHRP (svalue
))
152 svalue
= SCM_ICHR (svalue
);
153 scm_printchar (svalue
, stream
);
156 else if (SCM_IFLAGP (svalue
)
157 && (SCM_ISYMNUM (svalue
)
158 < (sizeof scm_isymnames
/ sizeof (char *))))
160 fputs_filtered (SCM_ISYMCHARS (svalue
), stream
);
163 else if (SCM_ILOCP (svalue
))
165 fprintf_filtered (stream
, "#@%ld%c%ld",
166 (long) SCM_IFRAME (svalue
),
167 SCM_ICDRP (svalue
) ? '-' : '+',
168 (long) SCM_IDIST (svalue
));
176 svalue
= SCM_CAR (svalue
- 1);
180 scm_ipruk ("immediate", svalue
, stream
);
184 switch (SCM_TYP7 (svalue
))
186 case scm_tcs_cons_gloc
:
187 if (SCM_CDR (SCM_CAR (svalue
) - 1L) == 0)
192 fputs_filtered ("#<latte ", stream
);
194 fputs_filtered ("???", stream
);
196 name
= ((SCM n
*) (STRUCT_TYPE (exp
)))[struct_i_name
];
197 scm_lfwrite (CHARS (name
),
198 (sizet
) sizeof (char),
199 (sizet
) LENGTH (name
),
202 fprintf_filtered (stream
, " #X%s>", paddr_nz (svalue
));
205 case scm_tcs_cons_imcar
:
206 case scm_tcs_cons_nimcar
:
207 fputs_filtered ("(", stream
);
208 scm_scmlist_print (svalue
, stream
, format
,
209 deref_ref
, recurse
+ 1, pretty
);
210 fputs_filtered (")", stream
);
212 case scm_tcs_closures
:
213 fputs_filtered ("#<CLOSURE ", stream
);
214 scm_scmlist_print (SCM_CODE (svalue
), stream
, format
,
215 deref_ref
, recurse
+ 1, pretty
);
216 fputs_filtered (">", stream
);
220 int len
= SCM_LENGTH (svalue
);
221 CORE_ADDR addr
= (CORE_ADDR
) SCM_CDR (svalue
);
226 int truncate
= print_max
&& len
> (int) print_max
;
229 fputs_filtered ("\"", stream
);
230 for (; done
< len
; done
+= buf_size
)
232 buf_size
= min (len
- done
, 64);
233 read_memory (addr
+ done
, buffer
, buf_size
);
235 for (i
= 0; i
< buf_size
; ++i
)
240 fputs_filtered ("\\", stream
);
242 fprintf_filtered (stream
, "%c", buffer
[i
]);
245 fputs_filtered (truncate
? "...\"" : "\"", stream
);
249 case scm_tcs_symbols
:
251 int len
= SCM_LENGTH (svalue
);
253 char *str
= (char *) alloca (len
);
254 read_memory (SCM_CDR (svalue
), str
, len
+ 1);
255 /* Should handle weird characters FIXME */
257 fputs_filtered (str
, stream
);
262 int len
= SCM_LENGTH (svalue
);
264 LONGEST elements
= SCM_CDR (svalue
);
265 fputs_filtered ("#(", stream
);
266 for (i
= 0; i
< len
; ++i
)
269 fputs_filtered (" ", stream
);
270 scm_scmval_print (scm_get_field (elements
, i
), stream
, format
,
271 deref_ref
, recurse
+ 1, pretty
);
273 fputs_filtered (")", stream
);
281 hook
= scm_get_lvector_hook (exp
, LV_PRINT_FN
);
284 scm_puts ("#<locked-vector ", port
);
285 scm_intprint (CDR (exp
), 16, port
);
286 scm_puts (">", port
);
292 scm_listify (exp
, port
, (writing
? BOOL_T
: BOOL_F
),
295 if (result
== BOOL_F
)
307 scm_raprin1 (exp
, port
, writing
);
312 int index
= SCM_CAR (svalue
) >> 8;
315 sprintf (str
, "#%d", index
);
317 char *str
= index
? SCM_CHARS (scm_heap_org
+ index
) : "";
318 #define SCM_CHARS(x) ((char *)(SCM_CDR(x)))
319 char *str
= CHARS (SNAME (exp
));
321 fprintf_filtered (stream
, "#<primitive-procedure %s>",
328 scm_puts ("#<compiled-closure ", port
);
329 scm_iprin1 (CCLO_SUBR (exp
), port
, writing
);
330 scm_putc ('>', port
);
334 fprintf_filtered (stream
, "#<continuation %d @ #X%lx >",
336 (long) CHARS (svalue
));
340 if (i
< scm_numptob
&& scm_ptobs
[i
].print
&& (scm_ptobs
[i
].print
) (exp
, port
, writing
))
345 if (i
< scm_numsmob
&& scm_smobs
[i
].print
346 && (scm_smobs
[i
].print
) (exp
, port
, writing
))
354 scm_ipruk ("type", svalue
, stream
);
361 scm_val_print (struct type
*type
, char *valaddr
, int embedded_offset
,
362 CORE_ADDR address
, struct ui_file
*stream
, int format
,
363 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
365 if (is_scmvalue_type (type
))
367 LONGEST svalue
= extract_signed_integer (valaddr
, TYPE_LENGTH (type
));
368 if (scm_inferior_print (svalue
, stream
, format
,
369 deref_ref
, recurse
, pretty
) >= 0)
374 scm_scmval_print (svalue
, stream
, format
,
375 deref_ref
, recurse
, pretty
);
383 return c_val_print (type
, valaddr
, 0, address
, stream
, format
,
384 deref_ref
, recurse
, pretty
);
389 scm_value_print (value_ptr val
, struct ui_file
*stream
, int format
,
390 enum val_prettyprint pretty
)
392 return (val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), 0,
393 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
));
This page took 0.041826 seconds and 4 git commands to generate.