* monitor.c (monitor_load_srec monitor_make_srec): Move all
[deliverable/binutils-gdb.git] / gdb / scm-valprint.c
CommitLineData
5b4d668a
PB
1/* Scheme/Guile language support routines for GDB, the GNU debugger.
2 Copyright 1995 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "defs.h"
21#include "symtab.h"
22#include "gdbtypes.h"
23#include "expression.h"
24#include "parser-defs.h"
25#include "language.h"
26#include "value.h"
27#include "scm-lang.h"
28#include "valprint.h"
29
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
32 print VALUE. */
33
34int
35scm_inferior_print (value, stream, format, deref_ref, recurse, pretty)
36 LONGEST value;
37 GDB_FILE *stream;
38 int format;
39 int deref_ref;
40 int recurse;
41 enum val_prettyprint pretty;
42{
43 return -1;
44}
45
46/* {Names of immediate symbols}
47 * This table must agree with the declarations in scm.h: {Immediate Symbols}.*/
48
49static char *scm_isymnames[] =
50{
51 /* This table must agree with the declarations */
52 "#@and",
53 "#@begin",
54 "#@case",
55 "#@cond",
56 "#@do",
57 "#@if",
58 "#@lambda",
59 "#@let",
60 "#@let*",
61 "#@letrec",
62 "#@or",
63 "#@quote",
64 "#@set!",
65 "#@define",
66#if 0
67 "#@literal-variable-ref",
68 "#@literal-variable-set!",
69#endif
70 "#@apply",
71 "#@call-with-current-continuation",
72
73 /* user visible ISYMS */
74 /* other keywords */
75 /* Flags */
76
77 "#f",
78 "#t",
79 "#<undefined>",
80 "#<eof>",
81 "()",
82 "#<unspecified>"
83};
84
85static int
86scm_scmlist_print (svalue, stream, format, deref_ref, recurse, pretty)
87 LONGEST svalue;
88 GDB_FILE *stream;
89 int format;
90 int deref_ref;
91 int recurse;
92 enum val_prettyprint pretty;
93{
94 unsigned int more = print_max;
95 if (recurse > 6)
96 {
97 fputs_filtered ("...", stream);
98 return 0;
99 }
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))
104 {
105 if (SCM_NECONSP (svalue))
106 break;
107 fputs_filtered (" ", stream);
108 if (--more == 0)
109 {
110 fputs_filtered ("...", stream);
111 return;
112 }
113 scm_scmval_print (SCM_CAR (svalue), stream, format,
114 deref_ref, recurse + 1, pretty);
115 }
116 if (SCM_NNULLP (svalue))
117 {
118 fputs_filtered (" . ", stream);
119 scm_scmval_print (svalue, stream, format,
120 deref_ref, recurse + 1, pretty);
121 }
122}
123
124static void
125scm_ipruk (hdr, ptr, stream)
126 char *hdr;
127 LONGEST ptr;
128 GDB_FILE *stream;
129{
130 fprintf_filtered (stream, "#<unknown-%s", hdr);
3c02944a 131#define SCM_SIZE TYPE_LENGTH (builtin_type_scm)
5b4d668a
PB
132 if (SCM_CELLP (ptr))
133 fprintf_filtered (stream, " (0x%lx . 0x%lx) @",
134 (long) SCM_CAR (ptr), (long) SCM_CDR (ptr));
135 fprintf_filtered (stream, " 0x%x>", ptr);
136}
137
138int
139scm_scmval_print (svalue, stream, format, deref_ref, recurse, pretty)
140 LONGEST svalue;
141 GDB_FILE *stream;
142 int format;
143 int deref_ref;
144 int recurse;
145 enum val_prettyprint pretty;
146{
147 taloop:
148 switch (7 & svalue)
149 {
150 case 2:
151 case 6:
152 print_longest (stream, format ? format : 'd', 1, svalue >> 2);
153 break;
154 case 4:
155 if (SCM_ICHRP (svalue))
156 {
157 svalue = SCM_ICHR (svalue);
158 scm_printchar (svalue, stream);
159 break;
160 }
161 else if (SCM_IFLAGP (svalue)
162 && (SCM_ISYMNUM (svalue)
163 < (sizeof scm_isymnames / sizeof (char *))))
164 {
165 fputs_filtered (SCM_ISYMCHARS (svalue), stream);
166 break;
167 }
168 else if (SCM_ILOCP (svalue))
169 {
170 fprintf_filtered (stream, "#@%ld%c%ld",
171 (long) SCM_IFRAME (svalue),
172 SCM_ICDRP (svalue) ? '-' : '+',
173 (long) SCM_IDIST (svalue));
174 break;
175 }
176 else
177 goto idef;
178 break;
179 case 1:
180 /* gloc */
181 fputs_filtered ("#@", stream);
182 svalue = SCM_CAR (svalue - 1);
183 goto taloop;
184 default:
185 idef:
186 scm_ipruk ("immediate", svalue, stream);
187 break;
188 case 0:
189
190 switch (SCM_TYP7 (svalue))
191 {
192 case scm_tcs_cons_gloc:
193 if (SCM_CDR (SCM_CAR (svalue) - 1L) == 0)
194 {
195 SCM name;
196 fputs_filtered ("#<latte ", stream);
197#if 1
198 fputs_filtered ("???", stream);
199#else
200 name = ((SCM n*)(STRUCT_TYPE( exp)))[struct_i_name];
201 scm_lfwrite (CHARS (name),
202 (sizet) sizeof (char),
203 (sizet) LENGTH (name),
204 port);
205#endif
206 fprintf_filtered (stream, " #X%lX>", svalue);
207 break;
208 }
209 case scm_tcs_cons_imcar:
210 case scm_tcs_cons_nimcar:
211 fputs_filtered ("(", stream);
212 scm_scmlist_print (svalue, stream, format,
213 deref_ref, recurse + 1, pretty);
214 fputs_filtered (")", stream);
215 break;
216 case scm_tcs_closures:
217 fputs_filtered ("#<CLOSURE ", stream);
218 scm_scmlist_print (SCM_CODE (svalue), stream, format,
219 deref_ref, recurse + 1, pretty);
220 fputs_filtered (">", stream);
221 break;
222 case scm_tc7_string:
223 {
224 int len = SCM_LENGTH (svalue);
225 CORE_ADDR addr = (CORE_ADDR) SCM_CDR (svalue);
226 int i;
227 int done = 0;
228 int buf_size;
229 char buffer[64];
230 int truncate = print_max && len > (int) print_max;
231 if (truncate)
232 len = print_max;
233 fputs_filtered ("\"", stream);
234 for (; done < len; done += buf_size)
235 {
236 buf_size = min (len - done, 64);
237 read_memory (addr + done, buffer, buf_size);
238
239 for (i = 0; i < buf_size; ++i)
240 switch (buffer[i])
241 {
242 case '\"':
243 case '\\':
244 fputs_filtered ("\\", stream);
245 default:
246 fprintf_filtered (stream, "%c", buffer[i]);
247 }
248 }
249 fputs_filtered (truncate ? "...\"" : "\"", stream);
250 break;
251 }
252 break;
253 case scm_tcs_symbols:
254 {
255 int len = SCM_LENGTH (svalue);
256
257 char * str = (char*) alloca (len);
258 read_memory (SCM_CDR (svalue), str, len + 1);
259 /* Should handle weird characters FIXME */
260 str[len] = '\0';
261 fputs_filtered (str, stream);
262 break;
263 }
264 case scm_tc7_vector:
265 {
266 int len = SCM_LENGTH (svalue);
267 int i;
268 LONGEST elements = SCM_CDR(svalue);
269 fputs_filtered ("#(", stream);
270 for (i = 0; i < len; ++i)
271 {
272 if (i > 0)
273 fputs_filtered (" ", stream);
274 scm_scmval_print (scm_get_field (elements, i), stream, format,
275 deref_ref, recurse + 1, pretty);
276 }
277 fputs_filtered (")", stream);
278 }
279 break;
280#if 0
281 case tc7_lvector:
282 {
283 SCM result;
284 SCM hook;
285 hook = scm_get_lvector_hook (exp, LV_PRINT_FN);
286 if (hook == BOOL_F)
287 {
288 scm_puts ("#<locked-vector ", port);
289 scm_intprint(CDR(exp), 16, port);
290 scm_puts (">", port);
291 }
292 else
293 {
294 result
295 = scm_apply (hook,
296 scm_listify (exp, port, (writing ? BOOL_T : BOOL_F),
297 SCM_UNDEFINED),
298 EOL);
299 if (result == BOOL_F)
300 goto punk;
301 }
302 break;
303 }
304 break;
305 case tc7_bvect:
306 case tc7_ivect:
307 case tc7_uvect:
308 case tc7_fvect:
309 case tc7_dvect:
310 case tc7_cvect:
311 scm_raprin1 (exp, port, writing);
312 break;
313#endif
314 case scm_tcs_subrs:
315 {
316 int index = SCM_CAR (svalue) >> 8;
317#if 1
318 char str[20];
319 sprintf (str, "#%d", index);
320#else
321 char *str = index ? SCM_CHARS (scm_heap_org+index) : "";
322#define SCM_CHARS(x) ((char *)(SCM_CDR(x)))
323 char *str = CHARS (SNAME (exp));
324#endif
325 fprintf_filtered (stream, "#<primitive-procedure %s>",
326 str);
327 }
328 break;
329#if 0
330#ifdef CCLO
331 case tc7_cclo:
332 scm_puts ("#<compiled-closure ", port);
333 scm_iprin1 (CCLO_SUBR (exp), port, writing);
334 scm_putc ('>', port);
335 break;
336#endif
337 case tc7_contin:
338 fprintf_filtered (stream, "#<continuation %d @ #X%lx >",
339 LENGTH (svalue),
340 (long) CHARS (svalue));
341 break;
342 case tc7_port:
343 i = PTOBNUM (exp);
344 if (i < scm_numptob && scm_ptobs[i].print && (scm_ptobs[i].print) (exp, port, writing))
345 break;
346 goto punk;
347 case tc7_smob:
348 i = SMOBNUM (exp);
349 if (i < scm_numsmob && scm_smobs[i].print
350 && (scm_smobs[i].print) (exp, port, writing))
351 break;
352 goto punk;
353#endif
354 default:
355 punk:scm_ipruk ("type", svalue, stream);
356 }
357 break;
358 }
359}
360
361int
362scm_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
363 pretty)
364 struct type *type;
365 char *valaddr;
366 CORE_ADDR address;
367 GDB_FILE *stream;
368 int format;
369 int deref_ref;
370 int recurse;
371 enum val_prettyprint pretty;
372{
373 if (is_scmvalue_type (type))
374 {
3c02944a 375 LONGEST svalue = extract_signed_integer (valaddr, TYPE_LENGTH (type));
5b4d668a
PB
376 if (scm_inferior_print (svalue, stream, format,
377 deref_ref, recurse, pretty) >= 0)
378 {
379 }
380 else
381 {
382 scm_scmval_print (svalue, stream, format,
383 deref_ref, recurse, pretty);
384 }
385
386 gdb_flush (stream);
387 return (0);
388 }
389 else
390 {
391 return c_val_print (type, valaddr, address, stream, format,
392 deref_ref, recurse, pretty);
393 }
394}
395
396int
397scm_value_print (val, stream, format, pretty)
398 value_ptr val;
399 GDB_FILE *stream;
400 int format;
401 enum val_prettyprint pretty;
402{
403 return (val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
404 VALUE_ADDRESS (val), stream, format, 1, 0, pretty));
405}
This page took 0.088736 seconds and 4 git commands to generate.