GDB (xrefs)

scm-pretty-print.c
Go to the documentation of this file.
1 /* GDB/Scheme pretty-printing.
2
3 Copyright (C) 2008-2018 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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 3 of the License, or
10 (at your option) any later version.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 /* See README file in this directory for implementation notes, coding
21 conventions, et.al. */
22
23 #include "defs.h"
24 #include "charset.h"
25 #include "symtab.h" /* Needed by language.h. */
26 #include "language.h"
27 #include "objfiles.h"
28 #include "value.h"
29 #include "valprint.h"
30 #include "guile-internal.h"
31
32 /* Return type of print_string_repr. */
33
34 enum string_repr_result
35 {
36 /* The string method returned None. */
37 STRING_REPR_NONE,
38 /* The string method had an error. */
39 STRING_REPR_ERROR,
40 /* Everything ok. */
41 STRING_REPR_OK
42 };
43
44 /* Display hints. */
45
46 enum display_hint
47 {
48 /* No display hint. */
49 HINT_NONE,
50 /* The display hint has a bad value. */
51 HINT_ERROR,
52 /* Print as an array. */
53 HINT_ARRAY,
54 /* Print as a map. */
55 HINT_MAP,
56 /* Print as a string. */
57 HINT_STRING
58 };
59
60 /* The <gdb:pretty-printer> smob. */
61
62 typedef struct
63 {
64 /* This must appear first. */
65 gdb_smob base;
66
67 /* A string representing the name of the printer. */
68 SCM name;
69
70 /* A boolean indicating whether the printer is enabled. */
71 SCM enabled;
72
73 /* A procedure called to look up the printer for the given value.
74 The procedure is called as (lookup gdb:pretty-printer value).
75 The result should either be a gdb:pretty-printer object that will print
76 the value, or #f if the value is not recognized. */
77 SCM lookup;
78
79 /* Note: Attaching subprinters to this smob is left to Scheme. */
80 } pretty_printer_smob;
81
82 /* The <gdb:pretty-printer-worker> smob. */
83
84 typedef struct
85 {
86 /* This must appear first. */
87 gdb_smob base;
88
89 /* Either #f or one of the supported display hints: map, array, string.
90 If neither of those then the display hint is ignored (treated as #f). */
91 SCM display_hint;
92
93 /* A procedure called to pretty-print the value.
94 (lambda (printer) ...) -> string | <gdb:lazy-string> | <gdb:value> */
95 SCM to_string;
96
97 /* A procedure called to print children of the value.
98 (lambda (printer) ...) -> <gdb:iterator>
99 The iterator returns a pair for each iteration: (name . value),
100 where "value" can have the same types as to_string. */
101 SCM children;
102 } pretty_printer_worker_smob;
103
104 static const char pretty_printer_smob_name[] =
105 "gdb:pretty-printer";
106 static const char pretty_printer_worker_smob_name[] =
107 "gdb:pretty-printer-worker";
108
109 /* The tag Guile knows the pretty-printer smobs by. */
110 static scm_t_bits pretty_printer_smob_tag;
111 static scm_t_bits pretty_printer_worker_smob_tag;
112
113 /* The global pretty-printer list. */
114 static SCM pretty_printer_list;
115
116 /* gdb:pp-type-error. */
117 static SCM pp_type_error_symbol;
118
119 /* Pretty-printer display hints are specified by strings. */
120 static SCM ppscm_map_string;
121 static SCM ppscm_array_string;
122 static SCM ppscm_string_string;
123
124 /* Administrivia for pretty-printer matcher smobs. */
125
126 /* The smob "print" function for <gdb:pretty-printer>. */
127
128 static int
129 ppscm_print_pretty_printer_smob (SCM self, SCM port, scm_print_state *pstate)
130 {
131 pretty_printer_smob *pp_smob = (pretty_printer_smob *) SCM_SMOB_DATA (self);
132
133 gdbscm_printf (port, "#<%s ", pretty_printer_smob_name);
134 scm_write (pp_smob->name, port);
135 scm_puts (gdbscm_is_true (pp_smob->enabled) ? " enabled" : " disabled",
136 port);
137 scm_puts (">", port);
138
139 scm_remember_upto_here_1 (self);
140
141 /* Non-zero means success. */
142 return 1;
143 }
144
145 /* (make-pretty-printer string procedure) -> <gdb:pretty-printer> */
146
147 static SCM
148 gdbscm_make_pretty_printer (SCM name, SCM lookup)
149 {
150 pretty_printer_smob *pp_smob = (pretty_printer_smob *)
151 scm_gc_malloc (sizeof (pretty_printer_smob),
152 pretty_printer_smob_name);
153 SCM smob;
154
155 SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, FUNC_NAME,
156 _("string"));
157 SCM_ASSERT_TYPE (gdbscm_is_procedure (lookup), lookup, SCM_ARG2, FUNC_NAME,
158 _("procedure"));
159
160 pp_smob->name = name;
161 pp_smob->lookup = lookup;
162 pp_smob->enabled = SCM_BOOL_T;
163 smob = scm_new_smob (pretty_printer_smob_tag, (scm_t_bits) pp_smob);
164 gdbscm_init_gsmob (&pp_smob->base);
165
166 return smob;
167 }
168
169 /* Return non-zero if SCM is a <gdb:pretty-printer> object. */
170
171 static int
172 ppscm_is_pretty_printer (SCM scm)
173 {
174 return SCM_SMOB_PREDICATE (pretty_printer_smob_tag, scm);
175 }
176
177 /* (pretty-printer? object) -> boolean */
178
179 static SCM
180 gdbscm_pretty_printer_p (SCM scm)
181 {
182 return scm_from_bool (ppscm_is_pretty_printer (scm));
183 }
184
185 /* Returns the <gdb:pretty-printer> object in SELF.
186 Throws an exception if SELF is not a <gdb:pretty-printer> object. */
187
188 static SCM
189 ppscm_get_pretty_printer_arg_unsafe (SCM self, int arg_pos,
190 const char *func_name)
191 {
192 SCM_ASSERT_TYPE (ppscm_is_pretty_printer (self), self, arg_pos, func_name,
193 pretty_printer_smob_name);
194
195 return self;
196 }
197
198 /* Returns a pointer to the pretty-printer smob of SELF.
199 Throws an exception if SELF is not a <gdb:pretty-printer> object. */
200
201 static pretty_printer_smob *
202 ppscm_get_pretty_printer_smob_arg_unsafe (SCM self, int arg_pos,
203 const char *func_name)
204 {
205 SCM pp_scm = ppscm_get_pretty_printer_arg_unsafe (self, arg_pos, func_name);
206 pretty_printer_smob *pp_smob
207 = (pretty_printer_smob *) SCM_SMOB_DATA (pp_scm);
208
209 return pp_smob;
210 }
211
212 /* Pretty-printer methods. */
213
214 /* (pretty-printer-enabled? <gdb:pretty-printer>) -> boolean */
215
216 static SCM
217 gdbscm_pretty_printer_enabled_p (SCM self)
218 {
219 pretty_printer_smob *pp_smob
220 = ppscm_get_pretty_printer_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
221
222 return pp_smob->enabled;
223 }
224
225 /* (set-pretty-printer-enabled! <gdb:pretty-printer> boolean)
226 -> unspecified */
227
228 static SCM
229 gdbscm_set_pretty_printer_enabled_x (SCM self, SCM enabled)
230 {
231 pretty_printer_smob *pp_smob
232 = ppscm_get_pretty_printer_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
233
234 pp_smob->enabled = scm_from_bool (gdbscm_is_true (enabled));
235
236 return SCM_UNSPECIFIED;
237 }
238
239 /* (pretty-printers) -> list
240 Returns the list of global pretty-printers. */
241
242 static SCM
243 gdbscm_pretty_printers (void)
244 {
245 return pretty_printer_list;
246 }
247
248 /* (set-pretty-printers! list) -> unspecified
249 Set the global pretty-printers list. */
250
251 static SCM
252 gdbscm_set_pretty_printers_x (SCM printers)
253 {
254 SCM_ASSERT_TYPE (gdbscm_is_true (scm_list_p (printers)), printers,
255 SCM_ARG1, FUNC_NAME, _("list"));
256
257 pretty_printer_list = printers;
258
259 return SCM_UNSPECIFIED;
260 }
261
262 /* Administrivia for pretty-printer-worker smobs.
263 These are created when a matcher recognizes a value. */
264
265 /* The smob "print" function for <gdb:pretty-printer-worker>. */
266
267 static int
268 ppscm_print_pretty_printer_worker_smob (SCM self, SCM port,
269 scm_print_state *pstate)
270 {
271 pretty_printer_worker_smob *w_smob
272 = (pretty_printer_worker_smob *) SCM_SMOB_DATA (self);
273
274 gdbscm_printf (port, "#<%s ", pretty_printer_worker_smob_name);
275 scm_write (w_smob->display_hint, port);
276 scm_puts (" ", port);
277 scm_write (w_smob->to_string, port);
278 scm_puts (" ", port);
279 scm_write (w_smob->children, port);
280 scm_puts (">", port);
281
282 scm_remember_upto_here_1 (self);
283
284 /* Non-zero means success. */
285 return 1;
286 }
287
288 /* (make-pretty-printer-worker string procedure procedure)
289 -> <gdb:pretty-printer-worker> */
290
291 static SCM
292 gdbscm_make_pretty_printer_worker (SCM display_hint, SCM to_string,
293 SCM children)
294 {
295 pretty_printer_worker_smob *w_smob = (pretty_printer_worker_smob *)
296 scm_gc_malloc (sizeof (pretty_printer_worker_smob),
297 pretty_printer_worker_smob_name);
298 SCM w_scm;
299
300 w_smob->display_hint = display_hint;
301 w_smob->to_string = to_string;
302 w_smob->children = children;
303 w_scm = scm_new_smob (pretty_printer_worker_smob_tag, (scm_t_bits) w_smob);
304 gdbscm_init_gsmob (&w_smob->base);
305 return w_scm;
306 }
307
308 /* Return non-zero if SCM is a <gdb:pretty-printer-worker> object. */
309
310 static int
311 ppscm_is_pretty_printer_worker (SCM scm)
312 {
313 return SCM_SMOB_PREDICATE (pretty_printer_worker_smob_tag, scm);
314 }
315
316 /* (pretty-printer-worker? object) -> boolean */
317
318 static SCM
319 gdbscm_pretty_printer_worker_p (SCM scm)
320 {
321 return scm_from_bool (ppscm_is_pretty_printer_worker (scm));
322 }
323
324 /* Helper function to create a <gdb:exception> object indicating that the
325 type of some value returned from a pretty-printer is invalid. */
326
327 static SCM
328 ppscm_make_pp_type_error_exception (const char *message, SCM object)
329 {
330 char *msg = xstrprintf ("%s: ~S", message);
331 struct cleanup *cleanup = make_cleanup (xfree, msg);
332 SCM exception
333 = gdbscm_make_error (pp_type_error_symbol,
334 NULL /* func */, msg,
335 scm_list_1 (object), scm_list_1 (object));
336
337 do_cleanups (cleanup);
338
339 return exception;
340 }
341
342 /* Print MESSAGE as an exception (meaning it is controlled by
343 "guile print-stack").
344 Called from the printer code when the Scheme code returns an invalid type
345 for something. */
346
347 static void
348 ppscm_print_pp_type_error (const char *message, SCM object)
349 {
350 SCM exception = ppscm_make_pp_type_error_exception (message, object);
351
352 gdbscm_print_gdb_exception (SCM_BOOL_F, exception);
353 }
354
355 /* Helper function for find_pretty_printer which iterates over a list,
356 calls each function and inspects output. This will return a
357 <gdb:pretty-printer> object if one recognizes VALUE. If no printer is
358 found, it will return #f. On error, it will return a <gdb:exception>
359 object.
360
361 Note: This has to be efficient and careful.
362 We don't want to excessively slow down printing of values, but any kind of
363 random crud can appear in the pretty-printer list, and we can't crash
364 because of it. */
365
366 static SCM
367 ppscm_search_pp_list (SCM list, SCM value)
368 {
369 SCM orig_list = list;
370
371 if (scm_is_null (list))
372 return SCM_BOOL_F;
373 if (gdbscm_is_false (scm_list_p (list))) /* scm_is_pair? */
374 {
375 return ppscm_make_pp_type_error_exception
376 (_("pretty-printer list is not a list"), list);
377 }
378
379 for ( ; scm_is_pair (list); list = scm_cdr (list))
380 {
381 SCM matcher = scm_car (list);
382 SCM worker;
383 pretty_printer_smob *pp_smob;
384
385 if (!ppscm_is_pretty_printer (matcher))
386 {
387 return ppscm_make_pp_type_error_exception
388 (_("pretty-printer list contains non-pretty-printer object"),
389 matcher);
390 }
391
392 pp_smob = (pretty_printer_smob *) SCM_SMOB_DATA (matcher);
393
394 /* Skip if disabled. */
395 if (gdbscm_is_false (pp_smob->enabled))
396 continue;
397
398 if (!gdbscm_is_procedure (pp_smob->lookup))
399 {
400 return ppscm_make_pp_type_error_exception
401 (_("invalid lookup object in pretty-printer matcher"),
402 pp_smob->lookup);
403 }
404
405 worker = gdbscm_safe_call_2 (pp_smob->lookup, matcher,
406 value, gdbscm_memory_error_p);
407 if (!gdbscm_is_false (worker))
408 {
409 if (gdbscm_is_exception (worker))
410 return worker;
411 if (ppscm_is_pretty_printer_worker (worker))
412 return worker;
413 return ppscm_make_pp_type_error_exception
414 (_("invalid result from pretty-printer lookup"), worker);
415 }
416 }
417
418 if (!scm_is_null (list))
419 {
420 return ppscm_make_pp_type_error_exception
421 (_("pretty-printer list is not a list"), orig_list);
422 }
423
424 return SCM_BOOL_F;
425 }
426
427 /* Subroutine of find_pretty_printer to simplify it.
428 Look for a pretty-printer to print VALUE in all objfiles.
429 If there's an error an exception smob is returned.
430 The result is #f, if no pretty-printer was found.
431 Otherwise the result is the pretty-printer smob. */
432
433 static SCM
434 ppscm_find_pretty_printer_from_objfiles (SCM value)
435 {
436 struct objfile *objfile;
437
438 ALL_OBJFILES (objfile)
439 {
440 objfile_smob *o_smob = ofscm_objfile_smob_from_objfile (objfile);
441 SCM pp = ppscm_search_pp_list (ofscm_objfile_smob_pretty_printers (o_smob),
442 value);
443
444 /* Note: This will return if pp is a <gdb:exception> object,
445 which is what we want. */
446 if (gdbscm_is_true (pp))
447 return pp;
448 }
449
450 return SCM_BOOL_F;
451 }
452
453 /* Subroutine of find_pretty_printer to simplify it.
454 Look for a pretty-printer to print VALUE in the current program space.
455 If there's an error an exception smob is returned.
456 The result is #f, if no pretty-printer was found.
457 Otherwise the result is the pretty-printer smob. */
458
459 static SCM
460 ppscm_find_pretty_printer_from_progspace (SCM value)
461 {
462 pspace_smob *p_smob = psscm_pspace_smob_from_pspace (current_program_space);
463 SCM pp
464 = ppscm_search_pp_list (psscm_pspace_smob_pretty_printers (p_smob), value);
465
466 return pp;
467 }
468
469 /* Subroutine of find_pretty_printer to simplify it.
470 Look for a pretty-printer to print VALUE in the gdb module.
471 If there's an error a Scheme exception is returned.
472 The result is #f, if no pretty-printer was found.
473 Otherwise the result is the pretty-printer smob. */
474
475 static SCM
476 ppscm_find_pretty_printer_from_gdb (SCM value)
477 {
478 SCM pp = ppscm_search_pp_list (pretty_printer_list, value);
479
480 return pp;
481 }
482
483 /* Find the pretty-printing constructor function for VALUE. If no
484 pretty-printer exists, return #f. If one exists, return the
485 gdb:pretty-printer smob that implements it. On error, an exception smob
486 is returned.
487
488 Note: In the end it may be better to call out to Scheme once, and then
489 do all of the lookup from Scheme. TBD. */
490
491 static SCM
492 ppscm_find_pretty_printer (SCM value)
493 {
494 SCM pp;
495
496 /* Look at the pretty-printer list for each objfile
497 in the current program-space. */
498 pp = ppscm_find_pretty_printer_from_objfiles (value);
499 /* Note: This will return if function is a <gdb:exception> object,
500 which is what we want. */
501 if (gdbscm_is_true (pp))
502 return pp;
503
504 /* Look at the pretty-printer list for the current program-space. */
505 pp = ppscm_find_pretty_printer_from_progspace (value);
506 /* Note: This will return if function is a <gdb:exception> object,
507 which is what we want. */
508 if (gdbscm_is_true (pp))
509 return pp;
510
511 /* Look at the pretty-printer list in the gdb module. */
512 pp = ppscm_find_pretty_printer_from_gdb (value);
513 return pp;
514 }
515
516 /* Pretty-print a single value, via the PRINTER, which must be a
517 <gdb:pretty-printer-worker> object.
518 The caller is responsible for ensuring PRINTER is valid.
519 If the function returns a string, an SCM containing the string
520 is returned. If the function returns #f that means the pretty
521 printer returned #f as a value. Otherwise, if the function returns a
522 <gdb:value> object, *OUT_VALUE is set to the value and #t is returned.
523 It is an error if the printer returns #t.
524 On error, an exception smob is returned. */
525
526 static SCM
527 ppscm_pretty_print_one_value (SCM printer, struct value **out_value,
528 struct gdbarch *gdbarch,
529 const struct language_defn *language)
530 {
531 SCM result = SCM_BOOL_F;
532
533 *out_value = NULL;
534 TRY
535 {
536 pretty_printer_worker_smob *w_smob
537 = (pretty_printer_worker_smob *) SCM_SMOB_DATA (printer);
538
539 result = gdbscm_safe_call_1 (w_smob->to_string, printer,
540 gdbscm_memory_error_p);
541 if (gdbscm_is_false (result))
542 ; /* Done. */
543 else if (scm_is_string (result)
544 || lsscm_is_lazy_string (result))
545 ; /* Done. */
546 else if (vlscm_is_value (result))
547 {
548 SCM except_scm;
549
550 *out_value
551 = vlscm_convert_value_from_scheme (FUNC_NAME, GDBSCM_ARG_NONE,
552 result, &except_scm,
553 gdbarch, language);
554 if (*out_value != NULL)
555 result = SCM_BOOL_T;
556 else
557 result = except_scm;
558 }
559 else if (gdbscm_is_exception (result))
560 ; /* Done. */
561 else
562 {
563 /* Invalid result from to-string. */
564 result = ppscm_make_pp_type_error_exception
565 (_("invalid result from pretty-printer to-string"), result);
566 }
567 }
568 CATCH (except, RETURN_MASK_ALL)
569 {
570 }
571 END_CATCH
572
573 return result;
574 }
575
576 /* Return the display hint for PRINTER as a Scheme object.
577 The caller is responsible for ensuring PRINTER is a
578 <gdb:pretty-printer-worker> object. */
579
580 static SCM
581 ppscm_get_display_hint_scm (SCM printer)
582 {
583 pretty_printer_worker_smob *w_smob
584 = (pretty_printer_worker_smob *) SCM_SMOB_DATA (printer);
585
586 return w_smob->display_hint;
587 }
588
589 /* Return the display hint for the pretty-printer PRINTER.
590 The caller is responsible for ensuring PRINTER is a
591 <gdb:pretty-printer-worker> object.
592 Returns the display hint or #f if the hint is not a string. */
593
594 static enum display_hint
595 ppscm_get_display_hint_enum (SCM printer)
596 {
597 SCM hint = ppscm_get_display_hint_scm (printer);
598
599 if (gdbscm_is_false (hint))
600 return HINT_NONE;
601 if (scm_is_string (hint))
602 {
603 if (gdbscm_is_true (scm_string_equal_p (hint, ppscm_array_string)))
604 return HINT_STRING;
605 if (gdbscm_is_true (scm_string_equal_p (hint, ppscm_map_string)))
606 return HINT_STRING;
607 if (gdbscm_is_true (scm_string_equal_p (hint, ppscm_string_string)))
608 return HINT_STRING;
609 return HINT_ERROR;
610 }
611 return HINT_ERROR;
612 }
613
614 /* A wrapper for gdbscm_print_gdb_exception that ignores memory errors.
615 EXCEPTION is a <gdb:exception> object. */
616
617 static void
618 ppscm_print_exception_unless_memory_error (SCM exception,
619 struct ui_file *stream)
620 {
621 if (gdbscm_memory_error_p (gdbscm_exception_key (exception)))
622 {
623 char *msg = gdbscm_exception_message_to_string (exception);
624 struct cleanup *cleanup = make_cleanup (xfree, msg);
625
626 /* This "shouldn't happen", but play it safe. */
627 if (msg == NULL || *msg == '\0')
628 fprintf_filtered (stream, _("<error reading variable>"));
629 else
630 {
631 /* Remove the trailing newline. We could instead call a special
632 routine for printing memory error messages, but this is easy
633 enough for now. */
634 size_t len = strlen (msg);
635
636 if (msg[len - 1] == '\n')
637 msg[len - 1] = '\0';
638 fprintf_filtered (stream, _("<error reading variable: %s>"), msg);
639 }
640
641 do_cleanups (cleanup);
642 }
643 else
644 gdbscm_print_gdb_exception (SCM_BOOL_F, exception);
645 }
646
647 /* Helper for gdbscm_apply_val_pretty_printer which calls to_string and
648 formats the result. */
649
650 static enum string_repr_result
651 ppscm_print_string_repr (SCM printer, enum display_hint hint,
652 struct ui_file *stream, int recurse,
653 const struct value_print_options *options,
654 struct gdbarch *gdbarch,
655 const struct language_defn *language)
656 {
657 struct value *replacement = NULL;
658 SCM str_scm;
659 enum string_repr_result result = STRING_REPR_ERROR;
660
661 str_scm = ppscm_pretty_print_one_value (printer, &replacement,
662 gdbarch, language);
663 if (gdbscm_is_false (str_scm))
664 {
665 result = STRING_REPR_NONE;
666 }
667 else if (scm_is_eq (str_scm, SCM_BOOL_T))
668 {
669 struct value_print_options opts = *options;
670
671 gdb_assert (replacement != NULL);
672 opts.addressprint = 0;
673 common_val_print (replacement, stream, recurse, &opts, language);
674 result = STRING_REPR_OK;
675 }
676 else if (scm_is_string (str_scm))
677 {
678 struct cleanup *cleanup;
679 size_t length;
680 char *string
681 = gdbscm_scm_to_string (str_scm, &length,
682 target_charset (gdbarch), 0 , NULL);
683
684 cleanup = make_cleanup (xfree, string);
685 if (hint == HINT_STRING)
686 {
687 struct type *type = builtin_type (gdbarch)->builtin_char;
688
689 LA_PRINT_STRING (stream, type, (gdb_byte *) string,
690 length, NULL, 0, options);
691 }
692 else
693 {
694 /* Alas scm_to_stringn doesn't nul-terminate the string if we
695 ask for the length. */
696 size_t i;
697
698 for (i = 0; i < length; ++i)
699 {
700 if (string[i] == '\0')
701 fputs_filtered ("\\000", stream);
702 else
703 fputc_filtered (string[i], stream);
704 }
705 }
706 result = STRING_REPR_OK;
707 do_cleanups (cleanup);
708 }
709 else if (lsscm_is_lazy_string (str_scm))
710 {
711 struct value_print_options local_opts = *options;
712
713 local_opts.addressprint = 0;
714 lsscm_val_print_lazy_string (str_scm, stream, &local_opts);
715 result = STRING_REPR_OK;
716 }
717 else
718 {
719 gdb_assert (gdbscm_is_exception (str_scm));
720 ppscm_print_exception_unless_memory_error (str_scm, stream);
721 result = STRING_REPR_ERROR;
722 }
723
724 return result;
725 }
726
727 /* Helper for gdbscm_apply_val_pretty_printer that formats children of the
728 printer, if any exist.
729 The caller is responsible for ensuring PRINTER is a printer smob.
730 If PRINTED_NOTHING is true, then nothing has been printed by to_string,
731 and format output accordingly. */
732
733 static void
734 ppscm_print_children (SCM printer, enum display_hint hint,
735 struct ui_file *stream, int recurse,
736 const struct value_print_options *options,
737 struct gdbarch *gdbarch,
738 const struct language_defn *language,
739 int printed_nothing)
740 {
741 pretty_printer_worker_smob *w_smob
742 = (pretty_printer_worker_smob *) SCM_SMOB_DATA (printer);
743 int is_map, is_array, done_flag, pretty;
744 unsigned int i;
745 SCM children;
746 SCM iter = SCM_BOOL_F; /* -Wall */
747 struct cleanup *cleanups;
748
749 if (gdbscm_is_false (w_smob->children))
750 return;
751 if (!gdbscm_is_procedure (w_smob->children))
752 {
753 ppscm_print_pp_type_error
754 (_("pretty-printer \"children\" object is not a procedure or #f"),
755 w_smob->children);
756 return;
757 }
758
759 cleanups = make_cleanup (null_cleanup, NULL);
760
761 /* If we are printing a map or an array, we want special formatting. */
762 is_map = hint == HINT_MAP;
763 is_array = hint == HINT_ARRAY;
764
765 children = gdbscm_safe_call_1 (w_smob->children, printer,
766 gdbscm_memory_error_p);
767 if (gdbscm_is_exception (children))
768 {
769 ppscm_print_exception_unless_memory_error (children, stream);
770 goto done;
771 }
772 /* We combine two steps here: get children, make an iterator out of them.
773 This simplifies things because there's no language means of creating
774 iterators, and it's the printer object that knows how it will want its
775 children iterated over. */
776 if (!itscm_is_iterator (children))
777 {
778 ppscm_print_pp_type_error
779 (_("result of pretty-printer \"children\" procedure is not"
780 " a <gdb:iterator> object"), children);
781 goto done;
782 }
783 iter = children;
784
785 /* Use the prettyformat_arrays option if we are printing an array,
786 and the pretty option otherwise. */
787 if (is_array)
788 pretty = options->prettyformat_arrays;
789 else
790 {
791 if (options->prettyformat == Val_prettyformat)
792 pretty = 1;
793 else
794 pretty = options->prettyformat_structs;
795 }
796
797 done_flag = 0;
798 for (i = 0; i < options->print_max; ++i)
799 {
800 SCM scm_name, v_scm;
801 char *name;
802 SCM item = itscm_safe_call_next_x (iter, gdbscm_memory_error_p);
803 struct cleanup *inner_cleanup = make_cleanup (null_cleanup, NULL);
804
805 if (gdbscm_is_exception (item))
806 {
807 ppscm_print_exception_unless_memory_error (item, stream);
808 break;
809 }
810 if (itscm_is_end_of_iteration (item))
811 {
812 /* Set a flag so we can know whether we printed all the
813 available elements. */
814 done_flag = 1;
815 break;
816 }
817
818 if (! scm_is_pair (item))
819 {
820 ppscm_print_pp_type_error
821 (_("result of pretty-printer children iterator is not a pair"
822 " or (end-of-iteration)"),
823 item);
824 continue;
825 }
826 scm_name = scm_car (item);
827 v_scm = scm_cdr (item);
828 if (!scm_is_string (scm_name))
829 {
830 ppscm_print_pp_type_error
831 (_("first element of pretty-printer children iterator is not"
832 " a string"), item);
833 continue;
834 }
835 name = gdbscm_scm_to_c_string (scm_name);
836 make_cleanup (xfree, name);
837
838 /* Print initial "{". For other elements, there are three cases:
839 1. Maps. Print a "," after each value element.
840 2. Arrays. Always print a ",".
841 3. Other. Always print a ",". */
842 if (i == 0)
843 {
844 if (printed_nothing)
845 fputs_filtered ("{", stream);
846 else
847 fputs_filtered (" = {", stream);
848 }
849
850 else if (! is_map || i % 2 == 0)
851 fputs_filtered (pretty ? "," : ", ", stream);
852
853 /* In summary mode, we just want to print "= {...}" if there is
854 a value. */
855 if (options->summary)
856 {
857 /* This increment tricks the post-loop logic to print what
858 we want. */
859 ++i;
860 /* Likewise. */
861 pretty = 0;
862 break;
863 }
864
865 if (! is_map || i % 2 == 0)
866 {
867 if (pretty)
868 {
869 fputs_filtered ("\n", stream);
870 print_spaces_filtered (2 + 2 * recurse, stream);
871 }
872 else
873 wrap_here (n_spaces (2 + 2 *recurse));
874 }
875
876 if (is_map && i % 2 == 0)
877 fputs_filtered ("[", stream);
878 else if (is_array)
879 {
880 /* We print the index, not whatever the child method
881 returned as the name. */
882 if (options->print_array_indexes)
883 fprintf_filtered (stream, "[%d] = ", i);
884 }
885 else if (! is_map)
886 {
887 fputs_filtered (name, stream);
888 fputs_filtered (" = ", stream);
889 }
890
891 if (lsscm_is_lazy_string (v_scm))
892 {
893 struct value_print_options local_opts = *options;
894
895 local_opts.addressprint = 0;
896 lsscm_val_print_lazy_string (v_scm, stream, &local_opts);
897 }
898 else if (scm_is_string (v_scm))
899 {
900 char *output = gdbscm_scm_to_c_string (v_scm);
901
902 fputs_filtered (output, stream);
903 xfree (output);
904 }
905 else
906 {
907 SCM except_scm;
908 struct value *value
909 = vlscm_convert_value_from_scheme (FUNC_NAME, GDBSCM_ARG_NONE,
910 v_scm, &except_scm,
911 gdbarch, language);
912
913 if (value == NULL)
914 {
915 ppscm_print_exception_unless_memory_error (except_scm, stream);
916 break;
917 }
918 common_val_print (value, stream, recurse + 1, options, language);
919 }
920
921 if (is_map && i % 2 == 0)
922 fputs_filtered ("] = ", stream);
923
924 do_cleanups (inner_cleanup);
925 }
926
927 if (i)
928 {
929 if (!done_flag)
930 {
931 if (pretty)
932 {
933 fputs_filtered ("\n", stream);
934 print_spaces_filtered (2 + 2 * recurse, stream);
935 }
936 fputs_filtered ("...", stream);
937 }
938 if (pretty)
939 {
940 fputs_filtered ("\n", stream);
941 print_spaces_filtered (2 * recurse, stream);
942 }
943 fputs_filtered ("}", stream);
944 }
945
946 done:
947 do_cleanups (cleanups);
948
949 /* Play it safe, make sure ITER doesn't get GC'd. */
950 scm_remember_upto_here_1 (iter);
951 }
952
953 /* This is the extension_language_ops.apply_val_pretty_printer "method". */
954
955 enum ext_lang_rc
956 gdbscm_apply_val_pretty_printer (const struct extension_language_defn *extlang,
957 struct type *type,
958 LONGEST embedded_offset, CORE_ADDR address,
959 struct ui_file *stream, int recurse,
960 struct value *val,
961 const struct value_print_options *options,
962 const struct language_defn *language)
963 {
964 struct gdbarch *gdbarch = get_type_arch (type);
965 SCM exception = SCM_BOOL_F;
966 SCM printer = SCM_BOOL_F;
967 SCM val_obj = SCM_BOOL_F;
968 struct value *value;
969 enum display_hint hint;
970 struct cleanup *cleanups;
971 enum ext_lang_rc result = EXT_LANG_RC_NOP;
972 enum string_repr_result print_result;
973 const gdb_byte *valaddr = value_contents_for_printing (val);
974
975 /* No pretty-printer support for unavailable values. */
976 if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
977 return EXT_LANG_RC_NOP;
978
979 if (!gdb_scheme_initialized)
980 return EXT_LANG_RC_NOP;
981
982 cleanups = make_cleanup (null_cleanup, NULL);
983
984 /* Instantiate the printer. */
985 value = value_from_component (val, type, embedded_offset);
986
987 val_obj = vlscm_scm_from_value (value);
988 if (gdbscm_is_exception (val_obj))
989 {
990 exception = val_obj;
991 result = EXT_LANG_RC_ERROR;
992 goto done;
993 }
994
995 printer = ppscm_find_pretty_printer (val_obj);
996
997 if (gdbscm_is_exception (printer))
998 {
999 exception = printer;
1000 result = EXT_LANG_RC_ERROR;
1001 goto done;
1002 }
1003 if (gdbscm_is_false (printer))
1004 {
1005 result = EXT_LANG_RC_NOP;
1006 goto done;
1007 }
1008 gdb_assert (ppscm_is_pretty_printer_worker (printer));
1009
1010 /* If we are printing a map, we want some special formatting. */
1011 hint = ppscm_get_display_hint_enum (printer);
1012 if (hint == HINT_ERROR)
1013 {
1014 /* Print the error as an exception for consistency. */
1015 SCM hint_scm = ppscm_get_display_hint_scm (printer);
1016
1017 ppscm_print_pp_type_error ("Invalid display hint", hint_scm);
1018 /* Fall through. A bad hint doesn't stop pretty-printing. */
1019 hint = HINT_NONE;
1020 }
1021
1022 /* Print the section. */
1023 print_result = ppscm_print_string_repr (printer, hint, stream, recurse,
1024 options, gdbarch, language);
1025 if (print_result != STRING_REPR_ERROR)
1026 {
1027 ppscm_print_children (printer, hint, stream, recurse, options,
1028 gdbarch, language,
1029 print_result == STRING_REPR_NONE);
1030 }
1031
1032 result = EXT_LANG_RC_OK;
1033
1034 done:
1035 if (gdbscm_is_exception (exception))
1036 ppscm_print_exception_unless_memory_error (exception, stream);
1037 do_cleanups (cleanups);
1038 return result;
1039 }
1040
1041 /* Initialize the Scheme pretty-printer code. */
1042
1043 static const scheme_function pretty_printer_functions[] =
1044 {
1045 { "make-pretty-printer", 2, 0, 0,
1046 as_a_scm_t_subr (gdbscm_make_pretty_printer),
1047 "\
1048 Create a <gdb:pretty-printer> object.\n\
1049 \n\
1050 Arguments: name lookup\n\
1051 name: a string naming the matcher\n\
1052 lookup: a procedure:\n\
1053 (pretty-printer <gdb:value>) -> <gdb:pretty-printer-worker> | #f." },
1054
1055 { "pretty-printer?", 1, 0, 0, as_a_scm_t_subr (gdbscm_pretty_printer_p),
1056 "\
1057 Return #t if the object is a <gdb:pretty-printer> object." },
1058
1059 { "pretty-printer-enabled?", 1, 0, 0,
1060 as_a_scm_t_subr (gdbscm_pretty_printer_enabled_p),
1061 "\
1062 Return #t if the pretty-printer is enabled." },
1063
1064 { "set-pretty-printer-enabled!", 2, 0, 0,
1065 as_a_scm_t_subr (gdbscm_set_pretty_printer_enabled_x),
1066 "\
1067 Set the enabled flag of the pretty-printer.\n\
1068 Returns \"unspecified\"." },
1069
1070 { "make-pretty-printer-worker", 3, 0, 0,
1071 as_a_scm_t_subr (gdbscm_make_pretty_printer_worker),
1072 "\
1073 Create a <gdb:pretty-printer-worker> object.\n\
1074 \n\
1075 Arguments: display-hint to-string children\n\
1076 display-hint: either #f or one of \"array\", \"map\", or \"string\"\n\
1077 to-string: a procedure:\n\
1078 (pretty-printer) -> string | #f | <gdb:value>\n\
1079 children: either #f or a procedure:\n\
1080 (pretty-printer) -> <gdb:iterator>" },
1081
1082 { "pretty-printer-worker?", 1, 0, 0,
1083 as_a_scm_t_subr (gdbscm_pretty_printer_worker_p),
1084 "\
1085 Return #t if the object is a <gdb:pretty-printer-worker> object." },
1086
1087 { "pretty-printers", 0, 0, 0, as_a_scm_t_subr (gdbscm_pretty_printers),
1088 "\
1089 Return the list of global pretty-printers." },
1090
1091 { "set-pretty-printers!", 1, 0, 0,
1092 as_a_scm_t_subr (gdbscm_set_pretty_printers_x),
1093 "\
1094 Set the list of global pretty-printers." },
1095
1096 END_FUNCTIONS
1097 };
1098
1099 void
1100 gdbscm_initialize_pretty_printers (void)
1101 {
1102 pretty_printer_smob_tag
1103 = gdbscm_make_smob_type (pretty_printer_smob_name,
1104 sizeof (pretty_printer_smob));
1105 scm_set_smob_print (pretty_printer_smob_tag,
1106 ppscm_print_pretty_printer_smob);
1107
1108 pretty_printer_worker_smob_tag
1109 = gdbscm_make_smob_type (pretty_printer_worker_smob_name,
1110 sizeof (pretty_printer_worker_smob));
1111 scm_set_smob_print (pretty_printer_worker_smob_tag,
1112 ppscm_print_pretty_printer_worker_smob);
1113
1114 gdbscm_define_functions (pretty_printer_functions, 1);
1115
1116 pretty_printer_list = SCM_EOL;
1117
1118 pp_type_error_symbol = scm_from_latin1_symbol ("gdb:pp-type-error");
1119
1120 ppscm_map_string = scm_from_latin1_string ("map");
1121 ppscm_array_string = scm_from_latin1_string ("array");
1122 ppscm_string_string = scm_from_latin1_string ("string");
1123 }
pretty_printer_smob::enabled
SCM enabled
Definition: scm-pretty-print.c:71
gdbarch
Definition: gdbarch.c:127
type::length
unsigned int length
Definition: gdbtypes.h:803
ppscm_get_display_hint_enum
static enum display_hint ppscm_get_display_hint_enum(SCM printer)
Definition: scm-pretty-print.c:595
ppscm_array_string
static SCM ppscm_array_string
Definition: scm-pretty-print.c:121
as_a_scm_t_subr
static scm_t_subr as_a_scm_t_subr(SCM(*func)(void))
Definition: guile-internal.h:66
target_charset
const char * target_charset(struct gdbarch *gdbarch)
Definition: charset.c:425
scm_new_smob
static SCM scm_new_smob(scm_t_bits tc, scm_t_bits data)
Definition: guile-internal.h:141
Val_prettyformat
Definition: defs.h:443
gdbscm_set_pretty_printer_enabled_x
static SCM gdbscm_set_pretty_printer_enabled_x(SCM self, SCM enabled)
Definition: scm-pretty-print.c:229
ppscm_find_pretty_printer_from_objfiles
static SCM ppscm_find_pretty_printer_from_objfiles(SCM value)
Definition: scm-pretty-print.c:434
gdbscm_make_pretty_printer
static SCM gdbscm_make_pretty_printer(SCM name, SCM lookup)
Definition: scm-pretty-print.c:148
gdbscm_define_functions
void gdbscm_define_functions(const scheme_function *, int is_public)
Definition: scm-utils.c:44
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
RETURN_MASK_ALL
Definition: common-exceptions.h:44
ppscm_get_pretty_printer_smob_arg_unsafe
static pretty_printer_smob * ppscm_get_pretty_printer_smob_arg_unsafe(SCM self, int arg_pos, const char *func_name)
Definition: scm-pretty-print.c:202
xfree
void xfree(void *)
ext_lang_rc
ext_lang_rc
Definition: extension-priv.h:30
ppscm_search_pp_list
static SCM ppscm_search_pp_list(SCM list, SCM value)
Definition: scm-pretty-print.c:367
value::embedded_offset
LONGEST embedded_offset
Definition: value.c:309
fputc_filtered
int fputc_filtered(int c, struct ui_file *stream)
Definition: utils.c:1844
vlscm_convert_value_from_scheme
struct value * vlscm_convert_value_from_scheme(const char *func_name, int obj_arg_pos, SCM obj, SCM *except_scmp, struct gdbarch *gdbarch, const struct language_defn *language)
Definition: scm-math.c:903
ppscm_get_pretty_printer_arg_unsafe
static SCM ppscm_get_pretty_printer_arg_unsafe(SCM self, int arg_pos, const char *func_name)
Definition: scm-pretty-print.c:189
ppscm_map_string
static SCM ppscm_map_string
Definition: scm-pretty-print.c:120
gdbscm_scm_to_c_string
char * gdbscm_scm_to_c_string(SCM string)
Definition: scm-string.c:55
pretty_printer_worker_smob::base
gdb_smob base
Definition: scm-pretty-print.c:87
HINT_STRING
Definition: scm-pretty-print.c:57
pretty_printer_worker_smob
Definition: scm-pretty-print.c:84
ppscm_find_pretty_printer
static SCM ppscm_find_pretty_printer(SCM value)
Definition: scm-pretty-print.c:492
pretty_printer_smob::lookup
SCM lookup
Definition: scm-pretty-print.c:77
builtin_type
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition: gdbtypes.c:5217
common_val_print
void common_val_print(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
Definition: valprint.c:1136
charset.h
gdbscm_apply_val_pretty_printer
enum ext_lang_rc gdbscm_apply_val_pretty_printer(const struct extension_language_defn *extlang, struct type *type, LONGEST embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, struct value *val, const struct value_print_options *options, const struct language_defn *language)
Definition: scm-pretty-print.c:956
FUNC_NAME
#define FUNC_NAME
Definition: guile-internal.h:153
guile-internal.h
value_print_options::print_array_indexes
int print_array_indexes
Definition: valprint.h:71
vlscm_is_value
int vlscm_is_value(SCM scm)
Definition: scm-value.c:231
ppscm_print_pretty_printer_worker_smob
static int ppscm_print_pretty_printer_worker_smob(SCM self, SCM port, scm_print_state *pstate)
Definition: scm-pretty-print.c:268
gdbscm_make_smob_type
scm_t_bits gdbscm_make_smob_type(const char *name, size_t size)
Definition: scm-gsmob.c:102
cleanup
Definition: cleanups.c:38
_
#define _(String)
Definition: gdb_locale.h:35
value_contents_for_printing
const gdb_byte * value_contents_for_printing(struct value *value)
Definition: value.c:1250
ui_file
Definition: ui-file.h:26
value_bytes_available
int value_bytes_available(const struct value *value, LONGEST offset, LONGEST length)
Definition: value.c:357
defs.h
gdbscm_pretty_printer_p
static SCM gdbscm_pretty_printer_p(SCM scm)
Definition: scm-pretty-print.c:180
gdbscm_pretty_printer_enabled_p
static SCM gdbscm_pretty_printer_enabled_p(SCM self)
Definition: scm-pretty-print.c:217
END_CATCH
#define END_CATCH
Definition: common-exceptions.h:259
value_print_options::prettyformat
enum val_prettyformat prettyformat
Definition: valprint.h:28
vlscm_scm_from_value
SCM vlscm_scm_from_value(struct value *value)
Definition: scm-value.c:249
gdbscm_is_exception
int gdbscm_is_exception(SCM scm)
Definition: scm-exception.c:147
gdbscm_is_true
#define gdbscm_is_true(scm)
Definition: guile-internal.h:134
objfiles.h
GDBSCM_ARG_NONE
#define GDBSCM_ARG_NONE
Definition: guile-internal.h:117
language_defn
Definition: language.h:132
pretty_printer_smob::name
SCM name
Definition: scm-pretty-print.c:68
null_cleanup
void null_cleanup(void *arg)
Definition: cleanups.c:294
STRING_REPR_NONE
Definition: scm-pretty-print.c:37
TRY
#define TRY
Definition: common-exceptions.h:246
symtab.h
name
const char *const name
Definition: aarch64-tdep.c:76
STRING_REPR_ERROR
Definition: scm-pretty-print.c:39
gdbscm_init_gsmob
void gdbscm_init_gsmob(gdb_smob *base)
Definition: scm-gsmob.c:113
gdbscm_initialize_pretty_printers
void gdbscm_initialize_pretty_printers(void)
Definition: scm-pretty-print.c:1100
CATCH
#define CATCH(EXCEPTION, MASK)
Definition: common-exceptions.h:254
gdbscm_exception_message_to_string
char * gdbscm_exception_message_to_string(SCM exception)
Definition: scm-exception.c:583
ofscm_objfile_smob_from_objfile
objfile_smob * ofscm_objfile_smob_from_objfile(struct objfile *objfile)
Definition: scm-objfile.c:147
value_print_options
Definition: valprint.h:25
pretty_printer_smob_tag
static scm_t_bits pretty_printer_smob_tag
Definition: scm-pretty-print.c:110
HINT_NONE
Definition: scm-pretty-print.c:49
pstate
static struct parser_state * pstate
Definition: ada-exp.c:98
pretty_printer_worker_smob_tag
static scm_t_bits pretty_printer_worker_smob_tag
Definition: scm-pretty-print.c:111
gdbscm_pretty_printer_worker_p
static SCM gdbscm_pretty_printer_worker_p(SCM scm)
Definition: scm-pretty-print.c:319
objfile::objfile
objfile(bfd *, const char *, objfile_flags)
Definition: objfiles.c:373
fprintf_filtered
void fprintf_filtered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2008
gdbscm_exception_key
SCM gdbscm_exception_key(SCM excp)
Definition: scm-exception.c:163
gdbscm_memory_error_p
excp_matcher_func gdbscm_memory_error_p
gdbscm_is_false
#define gdbscm_is_false(scm)
Definition: guile-internal.h:133
ppscm_is_pretty_printer
static int ppscm_is_pretty_printer(SCM scm)
Definition: scm-pretty-print.c:172
ppscm_find_pretty_printer_from_gdb
static SCM ppscm_find_pretty_printer_from_gdb(SCM value)
Definition: scm-pretty-print.c:476
fputs_filtered
void fputs_filtered(const char *linebuffer, struct ui_file *stream)
Definition: utils.c:1811
value_print_options::prettyformat_structs
int prettyformat_structs
Definition: valprint.h:34
make_cleanup
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
Definition: cleanups.c:116
type
Definition: gdbtypes.h:749
gdbscm_safe_call_2
SCM gdbscm_safe_call_2(SCM proc, SCM arg0, SCM arg1, excp_matcher_func *ok_excps)
Definition: scm-safe-call.c:275
language.h
gdb_smob
Definition: guile-internal.h:241
_pspace_smob
Definition: scm-progspace.c:34
scheme_function
Definition: guile-internal.h:91
get_type_arch
struct gdbarch * get_type_arch(const struct type *type)
Definition: gdbtypes.c:234
value_print_options::summary
int summary
Definition: valprint.h:90
ofscm_objfile_smob_pretty_printers
SCM ofscm_objfile_smob_pretty_printers(objfile_smob *o_smob)
Definition: scm-objfile.c:58
n_spaces
char * n_spaces(int n)
Definition: utils.c:2099
ppscm_print_pp_type_error
static void ppscm_print_pp_type_error(const char *message, SCM object)
Definition: scm-pretty-print.c:348
gdbscm_make_pretty_printer_worker
static SCM gdbscm_make_pretty_printer_worker(SCM display_hint, SCM to_string, SCM children)
Definition: scm-pretty-print.c:292
ppscm_print_pretty_printer_smob
static int ppscm_print_pretty_printer_smob(SCM self, SCM port, scm_print_state *pstate)
Definition: scm-pretty-print.c:129
gdbscm_set_pretty_printers_x
static SCM gdbscm_set_pretty_printers_x(SCM printers)
Definition: scm-pretty-print.c:252
lsscm_val_print_lazy_string
void lsscm_val_print_lazy_string(SCM string, struct ui_file *stream, const struct value_print_options *options)
Definition: scm-lazy-string.c:353
lsscm_is_lazy_string
int lsscm_is_lazy_string(SCM scm)
Definition: scm-lazy-string.c:138
xstrprintf
char * xstrprintf(const char *format,...)
Definition: common-utils.c:107
extension_language_defn
Definition: extension-priv.h:53
value_print_options::addressprint
int addressprint
Definition: valprint.h:43
pretty_printer_smob::base
gdb_smob base
Definition: scm-pretty-print.c:65
display_hint
display_hint
Definition: scm-pretty-print.c:46
gdbscm_printf
void gdbscm_printf(SCM port, const char *format,...) ATTRIBUTE_PRINTF(2
ppscm_get_display_hint_scm
static SCM ppscm_get_display_hint_scm(SCM printer)
Definition: scm-pretty-print.c:581
gdb_assert
#define gdb_assert(expr)
Definition: gdb_assert.h:32
value
Definition: value.c:169
wrap_here
void wrap_here(const char *indent)
Definition: utils.c:1596
HINT_ARRAY
Definition: scm-pretty-print.c:53
ppscm_pretty_print_one_value
static SCM ppscm_pretty_print_one_value(SCM printer, struct value **out_value, struct gdbarch *gdbarch, const struct language_defn *language)
Definition: scm-pretty-print.c:527
_objfile_smob
Definition: scm-objfile.c:31
objfile
Definition: objfiles.h:286
itscm_is_end_of_iteration
int itscm_is_end_of_iteration(SCM obj)
Definition: scm-iterator.c:197
HINT_MAP
Definition: scm-pretty-print.c:55
gdbscm_safe_call_1
SCM gdbscm_safe_call_1(SCM proc, SCM arg0, excp_matcher_func *ok_excps)
Definition: scm-safe-call.c:257
ppscm_is_pretty_printer_worker
static int ppscm_is_pretty_printer_worker(SCM scm)
Definition: scm-pretty-print.c:311
print_spaces_filtered
void print_spaces_filtered(int n, struct ui_file *stream)
Definition: utils.c:2121
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
END_FUNCTIONS
#define END_FUNCTIONS
Definition: guile-internal.h:103
pretty_printer_worker_smob::children
SCM children
Definition: scm-pretty-print.c:101
builtin_type::builtin_char
struct type * builtin_char
Definition: gdbtypes.h:1501
value_print_options::prettyformat_arrays
int prettyformat_arrays
Definition: valprint.h:31
gdbscm_print_gdb_exception
void gdbscm_print_gdb_exception(SCM port, SCM exception)
Definition: scm-exception.c:567
ppscm_string_string
static SCM ppscm_string_string
Definition: scm-pretty-print.c:122
ppscm_print_children
static void ppscm_print_children(SCM printer, enum display_hint hint, struct ui_file *stream, int recurse, const struct value_print_options *options, struct gdbarch *gdbarch, const struct language_defn *language, int printed_nothing)
Definition: scm-pretty-print.c:734
psscm_pspace_smob_pretty_printers
SCM psscm_pspace_smob_pretty_printers(const pspace_smob *)
Definition: scm-progspace.c:61
pretty_printer_smob_name
static const char pretty_printer_smob_name[]
Definition: scm-pretty-print.c:104
value.h
pretty_printer_list
static SCM pretty_printer_list
Definition: scm-pretty-print.c:114
pretty_printer_worker_smob::display_hint
SCM display_hint
Definition: scm-pretty-print.c:91
ppscm_make_pp_type_error_exception
static SCM ppscm_make_pp_type_error_exception(const char *message, SCM object)
Definition: scm-pretty-print.c:328
current_program_space
struct program_space * current_program_space
Definition: progspace.c:35
gdbscm_make_error
SCM gdbscm_make_error(SCM key, const char *subr, const char *message, SCM args, SCM data)
Definition: scm-exception.c:220
language
language
Definition: defs.h:203
itscm_safe_call_next_x
SCM itscm_safe_call_next_x(SCM iter, excp_matcher_func *ok_excps)
Definition: scm-iterator.c:215
STRING_REPR_OK
Definition: scm-pretty-print.c:41
gdbscm_pretty_printers
static SCM gdbscm_pretty_printers(void)
Definition: scm-pretty-print.c:243
value_print_options::print_max
unsigned int print_max
Definition: valprint.h:53
EXT_LANG_RC_NOP
Definition: extension-priv.h:36
ppscm_print_string_repr
static enum string_repr_result ppscm_print_string_repr(SCM printer, enum display_hint hint, struct ui_file *stream, int recurse, const struct value_print_options *options, struct gdbarch *gdbarch, const struct language_defn *language)
Definition: scm-pretty-print.c:651
gdb_scheme_initialized
int gdb_scheme_initialized
ppscm_print_exception_unless_memory_error
static void ppscm_print_exception_unless_memory_error(SCM exception, struct ui_file *stream)
Definition: scm-pretty-print.c:618
LA_PRINT_STRING
#define LA_PRINT_STRING(stream, elttype, string, length, encoding, force_ellipses, options)
Definition: language.h:529
pp_type_error_symbol
static SCM pp_type_error_symbol
Definition: scm-pretty-print.c:117
itscm_is_iterator
int itscm_is_iterator(SCM scm)
Definition: scm-iterator.c:172
EXT_LANG_RC_OK
Definition: extension-priv.h:33
pretty_printer_functions
static const scheme_function pretty_printer_functions[]
Definition: scm-pretty-print.c:1043
pretty_printer_smob
Definition: scm-pretty-print.c:62
string_repr_result
string_repr_result
Definition: scm-pretty-print.c:34
TYPE_LENGTH
#define TYPE_LENGTH(thistype)
Definition: gdbtypes.h:1235
value::address
CORE_ADDR address
Definition: value.c:208
ppscm_find_pretty_printer_from_progspace
static SCM ppscm_find_pretty_printer_from_progspace(SCM value)
Definition: scm-pretty-print.c:460
ALL_OBJFILES
#define ALL_OBJFILES(obj)
Definition: objfiles.h:582
psscm_pspace_smob_from_pspace
pspace_smob * psscm_pspace_smob_from_pspace(struct program_space *)
Definition: scm-progspace.c:157
valprint.h
HINT_ERROR
Definition: scm-pretty-print.c:51
value_from_component
struct value * value_from_component(struct value *whole, struct type *type, LONGEST offset)
Definition: value.c:3699
gdbscm_is_procedure
int gdbscm_is_procedure(SCM proc)
Definition: scm-utils.c:579
pretty_printer_worker_smob_name
static const char pretty_printer_worker_smob_name[]
Definition: scm-pretty-print.c:106
gdbscm_scm_to_string
SCM char * gdbscm_scm_to_string(SCM string, size_t *lenp, const char *charset, int strict, SCM *except_scmp)
Definition: scm-string.c:120
EXT_LANG_RC_ERROR
Definition: extension-priv.h:45
LONGEST
long long LONGEST
Definition: common-types.h:52
do_cleanups
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:174
pretty_printer_worker_smob::to_string
SCM to_string
Definition: scm-pretty-print.c:95