1 /* Scheme/Guile language support routines for GDB, the GNU debugger.
3 Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2005, 2007, 2008, 2009
4 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>. */
24 #include "expression.h"
25 #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,
37 const struct value_print_options
*);
38 static int scm_inferior_print (LONGEST
, struct ui_file
*, int,
39 const struct value_print_options
*);
41 /* Prints the SCM value VALUE by invoking the inferior, if appropraite.
42 Returns >= 0 on success; return -1 if the inferior cannot/should not
46 scm_inferior_print (LONGEST value
, struct ui_file
*stream
,
47 int recurse
, const struct value_print_options
*options
)
50 struct gdbarch
*gdbarch
;
51 struct value
*func
, *arg
, *result
;
52 struct symbol
*gdb_output_sym
, *gdb_output_len_sym
;
56 func
= find_function_in_inferior ("gdb_print", &objf
);
57 gdbarch
= get_objfile_arch (objf
);
58 arg
= value_from_longest (builtin_type (gdbarch
)->builtin_core_addr
, value
);
60 result
= call_function_by_hand (func
, 1, &arg
);
61 ret
= (int) value_as_long (result
);
64 /* XXX: Should we cache these symbols? */
66 lookup_symbol_global ("gdb_output", NULL
, NULL
, VAR_DOMAIN
);
68 lookup_symbol_global ("gdb_output_length", NULL
, NULL
, VAR_DOMAIN
);
70 if ((gdb_output_sym
== NULL
) || (gdb_output_len_sym
== NULL
))
74 struct value
*remote_buffer
;
76 read_memory (SYMBOL_VALUE_ADDRESS (gdb_output_len_sym
),
77 (char *) &output_len
, sizeof (output_len
));
79 output
= (char *) alloca (output_len
);
80 remote_buffer
= value_at (builtin_type (gdbarch
)->builtin_core_addr
,
81 SYMBOL_VALUE_ADDRESS (gdb_output_sym
));
82 read_memory (value_as_address (remote_buffer
),
85 ui_file_write (stream
, output
, output_len
);
92 /* {Names of immediate symbols}
93 * This table must agree with the declarations in scm.h: {Immediate Symbols}.*/
95 static char *scm_isymnames
[] =
97 /* This table must agree with the declarations */
113 "literal-variable-ref",
114 "literal-variable-set!",
117 "call-with-current-continuation",
119 /* user visible ISYMS */
132 scm_scmlist_print (LONGEST svalue
, struct ui_file
*stream
, int recurse
,
133 const struct value_print_options
*options
)
135 unsigned int more
= options
->print_max
;
138 fputs_filtered ("...", stream
);
141 scm_scmval_print (SCM_CAR (svalue
), stream
, recurse
+ 1, options
);
142 svalue
= SCM_CDR (svalue
);
143 for (; SCM_NIMP (svalue
); svalue
= SCM_CDR (svalue
))
145 if (SCM_NECONSP (svalue
))
147 fputs_filtered (" ", stream
);
150 fputs_filtered ("...", stream
);
153 scm_scmval_print (SCM_CAR (svalue
), stream
, recurse
+ 1, options
);
155 if (SCM_NNULLP (svalue
))
157 fputs_filtered (" . ", stream
);
158 scm_scmval_print (svalue
, stream
, recurse
+ 1, options
);
163 scm_ipruk (char *hdr
, LONGEST ptr
, struct ui_file
*stream
)
165 fprintf_filtered (stream
, "#<unknown-%s", hdr
);
166 #define SCM_SIZE TYPE_LENGTH (builtin_type_scm)
168 fprintf_filtered (stream
, " (0x%lx . 0x%lx) @",
169 (long) SCM_CAR (ptr
), (long) SCM_CDR (ptr
));
170 fprintf_filtered (stream
, " 0x%s>", paddr_nz (ptr
));
174 scm_scmval_print (LONGEST svalue
, struct ui_file
*stream
,
175 int recurse
, const struct value_print_options
*options
)
178 switch (7 & (int) svalue
)
182 print_longest (stream
,
183 options
->format
? options
->format
: 'd',
187 if (SCM_ICHRP (svalue
))
189 svalue
= SCM_ICHR (svalue
);
190 scm_printchar (svalue
, builtin_type (current_gdbarch
)->builtin_char
,
194 else if (SCM_IFLAGP (svalue
)
195 && (SCM_ISYMNUM (svalue
)
196 < (sizeof scm_isymnames
/ sizeof (char *))))
198 fputs_filtered (SCM_ISYMCHARS (svalue
), stream
);
201 else if (SCM_ILOCP (svalue
))
203 fprintf_filtered (stream
, "#@%ld%c%ld",
204 (long) SCM_IFRAME (svalue
),
205 SCM_ICDRP (svalue
) ? '-' : '+',
206 (long) SCM_IDIST (svalue
));
214 svalue
= SCM_CAR (svalue
- 1);
218 scm_ipruk ("immediate", svalue
, stream
);
222 switch (SCM_TYP7 (svalue
))
224 case scm_tcs_cons_gloc
:
225 if (SCM_CDR (SCM_CAR (svalue
) - 1L) == 0)
230 fputs_filtered ("#<latte ", stream
);
232 fputs_filtered ("???", stream
);
234 name
= ((SCM n
*) (STRUCT_TYPE (exp
)))[struct_i_name
];
235 scm_lfwrite (CHARS (name
),
236 (sizet
) sizeof (char),
237 (sizet
) LENGTH (name
),
240 fprintf_filtered (stream
, " #X%s>", paddr_nz (svalue
));
243 case scm_tcs_cons_imcar
:
244 case scm_tcs_cons_nimcar
:
245 fputs_filtered ("(", stream
);
246 scm_scmlist_print (svalue
, stream
, recurse
+ 1, options
);
247 fputs_filtered (")", stream
);
249 case scm_tcs_closures
:
250 fputs_filtered ("#<CLOSURE ", stream
);
251 scm_scmlist_print (SCM_CODE (svalue
), stream
, recurse
+ 1, options
);
252 fputs_filtered (">", stream
);
256 int len
= SCM_LENGTH (svalue
);
257 CORE_ADDR addr
= (CORE_ADDR
) SCM_CDR (svalue
);
262 int truncate
= options
->print_max
&& len
> (int) options
->print_max
;
264 len
= options
->print_max
;
265 fputs_filtered ("\"", stream
);
266 for (; done
< len
; done
+= buf_size
)
268 buf_size
= min (len
- done
, 64);
269 read_memory (addr
+ done
, buffer
, buf_size
);
271 for (i
= 0; i
< buf_size
; ++i
)
276 fputs_filtered ("\\", stream
);
278 fprintf_filtered (stream
, "%c", buffer
[i
]);
281 fputs_filtered (truncate
? "...\"" : "\"", stream
);
285 case scm_tcs_symbols
:
287 int len
= SCM_LENGTH (svalue
);
289 char *str
= alloca (len
);
290 read_memory (SCM_CDR (svalue
), (gdb_byte
*) str
, len
+ 1);
291 /* Should handle weird characters FIXME */
293 fputs_filtered (str
, stream
);
298 int len
= SCM_LENGTH (svalue
);
300 LONGEST elements
= SCM_CDR (svalue
);
301 fputs_filtered ("#(", stream
);
302 for (i
= 0; i
< len
; ++i
)
305 fputs_filtered (" ", stream
);
306 scm_scmval_print (scm_get_field (elements
, i
), stream
,
307 recurse
+ 1, options
);
309 fputs_filtered (")", stream
);
317 hook
= scm_get_lvector_hook (exp
, LV_PRINT_FN
);
320 scm_puts ("#<locked-vector ", port
);
321 scm_intprint (CDR (exp
), 16, port
);
322 scm_puts (">", port
);
328 scm_listify (exp
, port
,
329 (writing
? BOOL_T
: BOOL_F
),
332 if (result
== BOOL_F
)
344 scm_raprin1 (exp
, port
, writing
);
349 int index
= SCM_CAR (svalue
) >> 8;
352 sprintf (str
, "#%d", index
);
354 char *str
= index
? SCM_CHARS (scm_heap_org
+ index
) : "";
355 #define SCM_CHARS(x) ((char *)(SCM_CDR(x)))
356 char *str
= CHARS (SNAME (exp
));
358 fprintf_filtered (stream
, "#<primitive-procedure %s>",
365 scm_puts ("#<compiled-closure ", port
);
366 scm_iprin1 (CCLO_SUBR (exp
), port
, writing
);
367 scm_putc ('>', port
);
371 fprintf_filtered (stream
, "#<continuation %d @ #X%lx >",
373 (long) CHARS (svalue
));
378 && scm_ptobs
[i
].print
379 && (scm_ptobs
[i
].print
) (exp
, port
, writing
))
384 if (i
< scm_numsmob
&& scm_smobs
[i
].print
385 && (scm_smobs
[i
].print
) (exp
, port
, writing
))
393 scm_ipruk ("type", svalue
, stream
);
400 scm_val_print (struct type
*type
, const gdb_byte
*valaddr
,
401 int embedded_offset
, CORE_ADDR address
,
402 struct ui_file
*stream
, int recurse
,
403 const struct value_print_options
*options
)
405 if (is_scmvalue_type (type
))
407 LONGEST svalue
= extract_signed_integer (valaddr
, TYPE_LENGTH (type
));
409 if (scm_inferior_print (svalue
, stream
, recurse
, options
) >= 0)
414 scm_scmval_print (svalue
, stream
, recurse
, options
);
422 return c_val_print (type
, valaddr
, 0, address
, stream
, recurse
, options
);
427 scm_value_print (struct value
*val
, struct ui_file
*stream
,
428 const struct value_print_options
*options
)
430 struct value_print_options opts
= *options
;
432 return (common_val_print (val
, stream
, 0, &opts
, current_language
));
This page took 0.038357 seconds and 4 git commands to generate.