1 /* Scheme/Guile language support routines for GDB, the GNU debugger.
3 Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2005 Free Software
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
26 #include "expression.h"
27 #include "parser-defs.h"
35 static void scm_ipruk (char *, LONGEST
, struct ui_file
*);
36 static void scm_scmlist_print (LONGEST
, struct ui_file
*, int, int,
37 int, enum val_prettyprint
);
38 static int scm_inferior_print (LONGEST
, struct ui_file
*, int, int,
39 int, enum val_prettyprint
);
41 /* Prints the SCM value VALUE by invoking the inferior, if appropraite.
42 Returns >= 0 on succes; retunr -1 if the inferior cannot/should not
46 scm_inferior_print (LONGEST value
, struct ui_file
*stream
, int format
,
47 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
52 /* {Names of immediate symbols}
53 * This table must agree with the declarations in scm.h: {Immediate Symbols}.*/
55 static char *scm_isymnames
[] =
57 /* This table must agree with the declarations */
73 "literal-variable-ref",
74 "literal-variable-set!",
77 "call-with-current-continuation",
79 /* user visible ISYMS */
92 scm_scmlist_print (LONGEST svalue
, struct ui_file
*stream
, int format
,
93 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
95 unsigned int more
= print_max
;
98 fputs_filtered ("...", stream
);
101 scm_scmval_print (SCM_CAR (svalue
), stream
, format
,
102 deref_ref
, recurse
+ 1, pretty
);
103 svalue
= SCM_CDR (svalue
);
104 for (; SCM_NIMP (svalue
); svalue
= SCM_CDR (svalue
))
106 if (SCM_NECONSP (svalue
))
108 fputs_filtered (" ", stream
);
111 fputs_filtered ("...", stream
);
114 scm_scmval_print (SCM_CAR (svalue
), stream
, format
,
115 deref_ref
, recurse
+ 1, pretty
);
117 if (SCM_NNULLP (svalue
))
119 fputs_filtered (" . ", stream
);
120 scm_scmval_print (svalue
, stream
, format
,
121 deref_ref
, recurse
+ 1, pretty
);
126 scm_ipruk (char *hdr
, LONGEST ptr
, struct ui_file
*stream
)
128 fprintf_filtered (stream
, "#<unknown-%s", hdr
);
129 #define SCM_SIZE TYPE_LENGTH (builtin_type_scm)
131 fprintf_filtered (stream
, " (0x%lx . 0x%lx) @",
132 (long) SCM_CAR (ptr
), (long) SCM_CDR (ptr
));
133 fprintf_filtered (stream
, " 0x%s>", paddr_nz (ptr
));
137 scm_scmval_print (LONGEST svalue
, struct ui_file
*stream
, int format
,
138 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
141 switch (7 & (int) svalue
)
145 print_longest (stream
, format
? format
: 'd', 1, svalue
>> 2);
148 if (SCM_ICHRP (svalue
))
150 svalue
= SCM_ICHR (svalue
);
151 scm_printchar (svalue
, stream
);
154 else if (SCM_IFLAGP (svalue
)
155 && (SCM_ISYMNUM (svalue
)
156 < (sizeof scm_isymnames
/ sizeof (char *))))
158 fputs_filtered (SCM_ISYMCHARS (svalue
), stream
);
161 else if (SCM_ILOCP (svalue
))
163 fprintf_filtered (stream
, "#@%ld%c%ld",
164 (long) SCM_IFRAME (svalue
),
165 SCM_ICDRP (svalue
) ? '-' : '+',
166 (long) SCM_IDIST (svalue
));
174 svalue
= SCM_CAR (svalue
- 1);
178 scm_ipruk ("immediate", svalue
, stream
);
182 switch (SCM_TYP7 (svalue
))
184 case scm_tcs_cons_gloc
:
185 if (SCM_CDR (SCM_CAR (svalue
) - 1L) == 0)
190 fputs_filtered ("#<latte ", stream
);
192 fputs_filtered ("???", stream
);
194 name
= ((SCM n
*) (STRUCT_TYPE (exp
)))[struct_i_name
];
195 scm_lfwrite (CHARS (name
),
196 (sizet
) sizeof (char),
197 (sizet
) LENGTH (name
),
200 fprintf_filtered (stream
, " #X%s>", paddr_nz (svalue
));
203 case scm_tcs_cons_imcar
:
204 case scm_tcs_cons_nimcar
:
205 fputs_filtered ("(", stream
);
206 scm_scmlist_print (svalue
, stream
, format
,
207 deref_ref
, recurse
+ 1, pretty
);
208 fputs_filtered (")", stream
);
210 case scm_tcs_closures
:
211 fputs_filtered ("#<CLOSURE ", stream
);
212 scm_scmlist_print (SCM_CODE (svalue
), stream
, format
,
213 deref_ref
, recurse
+ 1, pretty
);
214 fputs_filtered (">", stream
);
218 int len
= SCM_LENGTH (svalue
);
219 CORE_ADDR addr
= (CORE_ADDR
) SCM_CDR (svalue
);
224 int truncate
= print_max
&& len
> (int) print_max
;
227 fputs_filtered ("\"", stream
);
228 for (; done
< len
; done
+= buf_size
)
230 buf_size
= min (len
- done
, 64);
231 read_memory (addr
+ done
, buffer
, buf_size
);
233 for (i
= 0; i
< buf_size
; ++i
)
238 fputs_filtered ("\\", stream
);
240 fprintf_filtered (stream
, "%c", buffer
[i
]);
243 fputs_filtered (truncate
? "...\"" : "\"", stream
);
247 case scm_tcs_symbols
:
249 int len
= SCM_LENGTH (svalue
);
251 char *str
= alloca (len
);
252 read_memory (SCM_CDR (svalue
), (gdb_byte
*) str
, len
+ 1);
253 /* Should handle weird characters FIXME */
255 fputs_filtered (str
, stream
);
260 int len
= SCM_LENGTH (svalue
);
262 LONGEST elements
= SCM_CDR (svalue
);
263 fputs_filtered ("#(", stream
);
264 for (i
= 0; i
< len
; ++i
)
267 fputs_filtered (" ", stream
);
268 scm_scmval_print (scm_get_field (elements
, i
), stream
, format
,
269 deref_ref
, recurse
+ 1, pretty
);
271 fputs_filtered (")", stream
);
279 hook
= scm_get_lvector_hook (exp
, LV_PRINT_FN
);
282 scm_puts ("#<locked-vector ", port
);
283 scm_intprint (CDR (exp
), 16, port
);
284 scm_puts (">", port
);
290 scm_listify (exp
, port
,
291 (writing
? BOOL_T
: BOOL_F
),
294 if (result
== BOOL_F
)
306 scm_raprin1 (exp
, port
, writing
);
311 int index
= SCM_CAR (svalue
) >> 8;
314 sprintf (str
, "#%d", index
);
316 char *str
= index
? SCM_CHARS (scm_heap_org
+ index
) : "";
317 #define SCM_CHARS(x) ((char *)(SCM_CDR(x)))
318 char *str
= CHARS (SNAME (exp
));
320 fprintf_filtered (stream
, "#<primitive-procedure %s>",
327 scm_puts ("#<compiled-closure ", port
);
328 scm_iprin1 (CCLO_SUBR (exp
), port
, writing
);
329 scm_putc ('>', port
);
333 fprintf_filtered (stream
, "#<continuation %d @ #X%lx >",
335 (long) CHARS (svalue
));
340 && scm_ptobs
[i
].print
341 && (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
, const gdb_byte
*valaddr
,
363 int embedded_offset
, CORE_ADDR address
,
364 struct ui_file
*stream
, int format
, int deref_ref
,
365 int recurse
, enum val_prettyprint pretty
)
367 if (is_scmvalue_type (type
))
369 LONGEST svalue
= extract_signed_integer (valaddr
, TYPE_LENGTH (type
));
370 if (scm_inferior_print (svalue
, stream
, format
,
371 deref_ref
, recurse
, pretty
) >= 0)
376 scm_scmval_print (svalue
, stream
, format
,
377 deref_ref
, recurse
, pretty
);
385 return c_val_print (type
, valaddr
, 0, address
, stream
, format
,
386 deref_ref
, recurse
, pretty
);
391 scm_value_print (struct value
*val
, struct ui_file
*stream
, int format
,
392 enum val_prettyprint pretty
)
394 return (common_val_print (val
, stream
, format
, 1, 0, pretty
));
This page took 0.037894 seconds and 4 git commands to generate.