1 /* Scheme/Guile language support routines for GDB, the GNU debugger.
2 Copyright 1995, 1996, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "expression.h"
26 #include "parser-defs.h"
33 /* FIXME: Should be in a header file that we import. */
34 extern int c_val_print (struct type
*, char *, int, CORE_ADDR
,
35 struct ui_file
*, int, int, int,
36 enum val_prettyprint
);
38 static void scm_ipruk (char *, LONGEST
, struct ui_file
*);
39 static void scm_scmlist_print (LONGEST
, struct ui_file
*, int, int,
40 int, enum val_prettyprint
);
41 static int scm_inferior_print (LONGEST
, struct ui_file
*, int, int,
42 int, enum val_prettyprint
);
44 /* Prints the SCM value VALUE by invoking the inferior, if appropraite.
45 Returns >= 0 on succes; retunr -1 if the inferior cannot/should not
49 scm_inferior_print (LONGEST value
, struct ui_file
*stream
, int format
,
50 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
55 /* {Names of immediate symbols}
56 * This table must agree with the declarations in scm.h: {Immediate Symbols}.*/
58 static char *scm_isymnames
[] =
60 /* This table must agree with the declarations */
76 "literal-variable-ref",
77 "literal-variable-set!",
80 "call-with-current-continuation",
82 /* user visible ISYMS */
95 scm_scmlist_print (LONGEST svalue
, struct ui_file
*stream
, int format
,
96 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
98 unsigned int more
= print_max
;
101 fputs_filtered ("...", stream
);
104 scm_scmval_print (SCM_CAR (svalue
), stream
, format
,
105 deref_ref
, recurse
+ 1, pretty
);
106 svalue
= SCM_CDR (svalue
);
107 for (; SCM_NIMP (svalue
); svalue
= SCM_CDR (svalue
))
109 if (SCM_NECONSP (svalue
))
111 fputs_filtered (" ", stream
);
114 fputs_filtered ("...", stream
);
117 scm_scmval_print (SCM_CAR (svalue
), stream
, format
,
118 deref_ref
, recurse
+ 1, pretty
);
120 if (SCM_NNULLP (svalue
))
122 fputs_filtered (" . ", stream
);
123 scm_scmval_print (svalue
, stream
, format
,
124 deref_ref
, recurse
+ 1, pretty
);
129 scm_ipruk (char *hdr
, LONGEST ptr
, struct ui_file
*stream
)
131 fprintf_filtered (stream
, "#<unknown-%s", hdr
);
132 #define SCM_SIZE TYPE_LENGTH (builtin_type_scm)
134 fprintf_filtered (stream
, " (0x%lx . 0x%lx) @",
135 (long) SCM_CAR (ptr
), (long) SCM_CDR (ptr
));
136 fprintf_filtered (stream
, " 0x%s>", paddr_nz (ptr
));
140 scm_scmval_print (LONGEST svalue
, struct ui_file
*stream
, int format
,
141 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
144 switch (7 & (int) svalue
)
148 print_longest (stream
, format
? format
: 'd', 1, svalue
>> 2);
151 if (SCM_ICHRP (svalue
))
153 svalue
= SCM_ICHR (svalue
);
154 scm_printchar (svalue
, stream
);
157 else if (SCM_IFLAGP (svalue
)
158 && (SCM_ISYMNUM (svalue
)
159 < (sizeof scm_isymnames
/ sizeof (char *))))
161 fputs_filtered (SCM_ISYMCHARS (svalue
), stream
);
164 else if (SCM_ILOCP (svalue
))
166 fprintf_filtered (stream
, "#@%ld%c%ld",
167 (long) SCM_IFRAME (svalue
),
168 SCM_ICDRP (svalue
) ? '-' : '+',
169 (long) SCM_IDIST (svalue
));
177 svalue
= SCM_CAR (svalue
- 1);
181 scm_ipruk ("immediate", svalue
, stream
);
185 switch (SCM_TYP7 (svalue
))
187 case scm_tcs_cons_gloc
:
188 if (SCM_CDR (SCM_CAR (svalue
) - 1L) == 0)
193 fputs_filtered ("#<latte ", stream
);
195 fputs_filtered ("???", stream
);
197 name
= ((SCM n
*) (STRUCT_TYPE (exp
)))[struct_i_name
];
198 scm_lfwrite (CHARS (name
),
199 (sizet
) sizeof (char),
200 (sizet
) LENGTH (name
),
203 fprintf_filtered (stream
, " #X%s>", paddr_nz (svalue
));
206 case scm_tcs_cons_imcar
:
207 case scm_tcs_cons_nimcar
:
208 fputs_filtered ("(", stream
);
209 scm_scmlist_print (svalue
, stream
, format
,
210 deref_ref
, recurse
+ 1, pretty
);
211 fputs_filtered (")", stream
);
213 case scm_tcs_closures
:
214 fputs_filtered ("#<CLOSURE ", stream
);
215 scm_scmlist_print (SCM_CODE (svalue
), stream
, format
,
216 deref_ref
, recurse
+ 1, pretty
);
217 fputs_filtered (">", stream
);
221 int len
= SCM_LENGTH (svalue
);
222 CORE_ADDR addr
= (CORE_ADDR
) SCM_CDR (svalue
);
227 int truncate
= print_max
&& len
> (int) print_max
;
230 fputs_filtered ("\"", stream
);
231 for (; done
< len
; done
+= buf_size
)
233 buf_size
= min (len
- done
, 64);
234 read_memory (addr
+ done
, buffer
, buf_size
);
236 for (i
= 0; i
< buf_size
; ++i
)
241 fputs_filtered ("\\", stream
);
243 fprintf_filtered (stream
, "%c", buffer
[i
]);
246 fputs_filtered (truncate
? "...\"" : "\"", stream
);
250 case scm_tcs_symbols
:
252 int len
= SCM_LENGTH (svalue
);
254 char *str
= (char *) alloca (len
);
255 read_memory (SCM_CDR (svalue
), str
, len
+ 1);
256 /* Should handle weird characters FIXME */
258 fputs_filtered (str
, stream
);
263 int len
= SCM_LENGTH (svalue
);
265 LONGEST elements
= SCM_CDR (svalue
);
266 fputs_filtered ("#(", stream
);
267 for (i
= 0; i
< len
; ++i
)
270 fputs_filtered (" ", stream
);
271 scm_scmval_print (scm_get_field (elements
, i
), stream
, format
,
272 deref_ref
, recurse
+ 1, pretty
);
274 fputs_filtered (")", stream
);
282 hook
= scm_get_lvector_hook (exp
, LV_PRINT_FN
);
285 scm_puts ("#<locked-vector ", port
);
286 scm_intprint (CDR (exp
), 16, port
);
287 scm_puts (">", port
);
293 scm_listify (exp
, port
, (writing
? BOOL_T
: BOOL_F
),
296 if (result
== BOOL_F
)
308 scm_raprin1 (exp
, port
, writing
);
313 int index
= SCM_CAR (svalue
) >> 8;
316 sprintf (str
, "#%d", index
);
318 char *str
= index
? SCM_CHARS (scm_heap_org
+ index
) : "";
319 #define SCM_CHARS(x) ((char *)(SCM_CDR(x)))
320 char *str
= CHARS (SNAME (exp
));
322 fprintf_filtered (stream
, "#<primitive-procedure %s>",
329 scm_puts ("#<compiled-closure ", port
);
330 scm_iprin1 (CCLO_SUBR (exp
), port
, writing
);
331 scm_putc ('>', port
);
335 fprintf_filtered (stream
, "#<continuation %d @ #X%lx >",
337 (long) CHARS (svalue
));
341 if (i
< scm_numptob
&& scm_ptobs
[i
].print
&& (scm_ptobs
[i
].print
) (exp
, port
, writing
))
346 if (i
< scm_numsmob
&& scm_smobs
[i
].print
347 && (scm_smobs
[i
].print
) (exp
, port
, writing
))
355 scm_ipruk ("type", svalue
, stream
);
362 scm_val_print (struct type
*type
, char *valaddr
, int embedded_offset
,
363 CORE_ADDR address
, struct ui_file
*stream
, int format
,
364 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
366 if (is_scmvalue_type (type
))
368 LONGEST svalue
= extract_signed_integer (valaddr
, TYPE_LENGTH (type
));
369 if (scm_inferior_print (svalue
, stream
, format
,
370 deref_ref
, recurse
, pretty
) >= 0)
375 scm_scmval_print (svalue
, stream
, format
,
376 deref_ref
, recurse
, pretty
);
384 return c_val_print (type
, valaddr
, 0, address
, stream
, format
,
385 deref_ref
, recurse
, pretty
);
390 scm_value_print (struct value
*val
, struct ui_file
*stream
, int format
,
391 enum val_prettyprint pretty
)
393 return (val_print (value_type (val
), VALUE_CONTENTS (val
), 0,
394 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
));
This page took 0.038521 seconds and 4 git commands to generate.