GDB (xrefs)
Loading...
Searching...
No Matches
py-prettyprint.c
Go to the documentation of this file.
1/* Python pretty-printing
2
3 Copyright (C) 2008-2023 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#include "defs.h"
21#include "objfiles.h"
22#include "symtab.h"
23#include "language.h"
24#include "valprint.h"
25#include "extension-priv.h"
26#include "python.h"
27#include "python-internal.h"
28#include "cli/cli-style.h"
29
30extern PyTypeObject printer_object_type;
31
32/* Return type of print_string_repr. */
33
35 {
36 /* The string method returned None. */
38 /* The string method had an error. */
40 /* Everything ok. */
42 };
43
44/* If non-null, points to options that are in effect while
45 printing. */
47
48/* Helper function for find_pretty_printer which iterates over a list,
49 calls each function and inspects output. This will return a
50 printer object if one recognizes VALUE. If no printer is found, it
51 will return None. On error, it will set the Python error and
52 return NULL. */
53
54static gdbpy_ref<>
56{
57 Py_ssize_t pp_list_size, list_index;
58
59 pp_list_size = PyList_Size (list);
60 for (list_index = 0; list_index < pp_list_size; list_index++)
61 {
62 PyObject *function = PyList_GetItem (list, list_index);
63 if (! function)
64 return NULL;
65
66 /* Skip if disabled. */
67 if (PyObject_HasAttr (function, gdbpy_enabled_cst))
68 {
69 gdbpy_ref<> attr (PyObject_GetAttr (function, gdbpy_enabled_cst));
70 int cmp;
71
72 if (attr == NULL)
73 return NULL;
74 cmp = PyObject_IsTrue (attr.get ());
75 if (cmp == -1)
76 return NULL;
77
78 if (!cmp)
79 continue;
80 }
81
82 gdbpy_ref<> printer (PyObject_CallFunctionObjArgs (function, value,
83 NULL));
84 if (printer == NULL)
85 return NULL;
86 else if (printer != Py_None)
87 return printer;
88 }
89
90 return gdbpy_ref<>::new_reference (Py_None);
91}
92
93/* Subroutine of find_pretty_printer to simplify it.
94 Look for a pretty-printer to print VALUE in all objfiles.
95 The result is NULL if there's an error and the search should be terminated.
96 The result is Py_None, suitably inc-ref'd, if no pretty-printer was found.
97 Otherwise the result is the pretty-printer function, suitably inc-ref'd. */
98
99static PyObject *
101{
102 for (objfile *obj : current_program_space->objfiles ())
103 {
105 if (objf == NULL)
106 {
107 /* Ignore the error and continue. */
108 PyErr_Clear ();
109 continue;
110 }
111
112 gdbpy_ref<> pp_list (objfpy_get_printers (objf.get (), NULL));
113 gdbpy_ref<> function (search_pp_list (pp_list.get (), value));
114
115 /* If there is an error in any objfile list, abort the search and exit. */
116 if (function == NULL)
117 return NULL;
118
119 if (function != Py_None)
120 return function.release ();
121 }
122
123 Py_RETURN_NONE;
124}
125
126/* Subroutine of find_pretty_printer to simplify it.
127 Look for a pretty-printer to print VALUE in the current program space.
128 The result is NULL if there's an error and the search should be terminated.
129 The result is Py_None, suitably inc-ref'd, if no pretty-printer was found.
130 Otherwise the result is the pretty-printer function, suitably inc-ref'd. */
131
132static gdbpy_ref<>
134{
136
137 if (obj == NULL)
138 return NULL;
139 gdbpy_ref<> pp_list (pspy_get_printers (obj.get (), NULL));
140 return search_pp_list (pp_list.get (), value);
141}
142
143/* Subroutine of find_pretty_printer to simplify it.
144 Look for a pretty-printer to print VALUE in the gdb module.
145 The result is NULL if there's an error and the search should be terminated.
146 The result is Py_None, suitably inc-ref'd, if no pretty-printer was found.
147 Otherwise the result is the pretty-printer function, suitably inc-ref'd. */
148
149static gdbpy_ref<>
151{
152 /* Fetch the global pretty printer list. */
153 if (gdb_python_module == NULL
154 || ! PyObject_HasAttrString (gdb_python_module, "pretty_printers"))
155 return gdbpy_ref<>::new_reference (Py_None);
156 gdbpy_ref<> pp_list (PyObject_GetAttrString (gdb_python_module,
157 "pretty_printers"));
158 if (pp_list == NULL || ! PyList_Check (pp_list.get ()))
159 return gdbpy_ref<>::new_reference (Py_None);
160
161 return search_pp_list (pp_list.get (), value);
162}
163
164/* Find the pretty-printing constructor function for VALUE. If no
165 pretty-printer exists, return None. If one exists, return a new
166 reference. On error, set the Python error and return NULL. */
167
168static gdbpy_ref<>
170{
171 /* Look at the pretty-printer list for each objfile
172 in the current program-space. */
174 if (function == NULL || function != Py_None)
175 return function;
176
177 /* Look at the pretty-printer list for the current program-space. */
179 if (function == NULL || function != Py_None)
180 return function;
181
182 /* Look at the pretty-printer list in the gdb module. */
184}
185
186/* Pretty-print a single value, via the printer object PRINTER.
187 If the function returns a string, a PyObject containing the string
188 is returned. If the function returns Py_NONE that means the pretty
189 printer returned the Python None as a value. Otherwise, if the
190 function returns a value, *OUT_VALUE is set to the value, and NULL
191 is returned. On error, *OUT_VALUE is set to NULL, NULL is
192 returned, with a python exception set. */
193
194static gdbpy_ref<>
195pretty_print_one_value (PyObject *printer, struct value **out_value)
196{
197 gdbpy_ref<> result;
198
199 *out_value = NULL;
200 try
201 {
202 if (!PyObject_HasAttr (printer, gdbpy_to_string_cst))
203 result = gdbpy_ref<>::new_reference (Py_None);
204 else
205 {
206 result.reset (PyObject_CallMethodObjArgs (printer, gdbpy_to_string_cst,
207 NULL));
208 if (result != NULL)
209 {
210 if (! gdbpy_is_string (result.get ())
211 && ! gdbpy_is_lazy_string (result.get ())
212 && result != Py_None)
213 {
214 *out_value = convert_value_from_python (result.get ());
215 if (PyErr_Occurred ())
216 *out_value = NULL;
217 result = NULL;
218 }
219 }
220 }
221 }
222 catch (const gdb_exception &except)
223 {
224 }
225
226 return result;
227}
228
229/* Return the display hint for the object printer, PRINTER. Return
230 NULL if there is no display_hint method, or if the method did not
231 return a string. On error, print stack trace and return NULL. On
232 success, return an xmalloc()d string. */
233gdb::unique_xmalloc_ptr<char>
235{
236 gdb::unique_xmalloc_ptr<char> result;
237
238 if (! PyObject_HasAttr (printer, gdbpy_display_hint_cst))
239 return NULL;
240
241 gdbpy_ref<> hint (PyObject_CallMethodObjArgs (printer, gdbpy_display_hint_cst,
242 NULL));
243 if (hint != NULL)
244 {
245 if (gdbpy_is_string (hint.get ()))
246 {
247 result = python_string_to_host_string (hint.get ());
248 if (result == NULL)
250 }
251 }
252 else
254
255 return result;
256}
257
258/* A wrapper for gdbpy_print_stack that ignores MemoryError. */
259
260static void
262{
263 if (PyErr_ExceptionMatches (gdbpy_gdb_memory_error))
264 {
265 gdbpy_err_fetch fetched_error;
266 gdb::unique_xmalloc_ptr<char> msg = fetched_error.to_string ();
267
268 if (msg == NULL || *msg == '\0')
270 _("<error reading variable>"));
271 else
273 _("<error reading variable: %s>"), msg.get ());
274 }
275 else
277}
278
279/* Helper for gdbpy_apply_val_pretty_printer which calls to_string and
280 formats the result. */
281
282static enum gdbpy_string_repr_result
283print_string_repr (PyObject *printer, const char *hint,
284 struct ui_file *stream, int recurse,
285 const struct value_print_options *options,
286 const struct language_defn *language,
287 struct gdbarch *gdbarch)
288{
289 struct value *replacement = NULL;
291
292 gdbpy_ref<> py_str = pretty_print_one_value (printer, &replacement);
293 if (py_str != NULL)
294 {
295 if (py_str == Py_None)
296 result = string_repr_none;
297 else if (gdbpy_is_lazy_string (py_str.get ()))
298 {
299 CORE_ADDR addr;
300 long length;
301 struct type *type;
302 gdb::unique_xmalloc_ptr<char> encoding;
303 struct value_print_options local_opts = *options;
304
305 gdbpy_extract_lazy_string (py_str.get (), &addr, &type,
306 &length, &encoding);
307
308 local_opts.addressprint = false;
309 val_print_string (type, encoding.get (), addr, (int) length,
310 stream, &local_opts);
311 }
312 else
313 {
314 gdbpy_ref<> string
316 if (string != NULL)
317 {
318 char *output;
319 long length;
320 struct type *type;
321
322 output = PyBytes_AS_STRING (string.get ());
323 length = PyBytes_GET_SIZE (string.get ());
325
326 if (hint && !strcmp (hint, "string"))
327 language->printstr (stream, type, (gdb_byte *) output,
328 length, NULL, 0, options);
329 else
330 gdb_puts (output, stream);
331 }
332 else
333 {
334 result = string_repr_error;
336 }
337 }
338 }
339 else if (replacement)
340 {
341 struct value_print_options opts = *options;
342
343 opts.addressprint = false;
344 common_val_print (replacement, stream, recurse, &opts, language);
345 }
346 else
347 {
348 result = string_repr_error;
350 }
351
352 return result;
353}
354
355/* Helper for gdbpy_apply_val_pretty_printer that formats children of the
356 printer, if any exist. If is_py_none is true, then nothing has
357 been printed by to_string, and format output accordingly. */
358static void
359print_children (PyObject *printer, const char *hint,
360 struct ui_file *stream, int recurse,
361 const struct value_print_options *options,
362 const struct language_defn *language,
363 int is_py_none)
364{
365 int is_map, is_array, done_flag, pretty;
366 unsigned int i;
367
368 if (! PyObject_HasAttr (printer, gdbpy_children_cst))
369 return;
370
371 /* If we are printing a map or an array, we want some special
372 formatting. */
373 is_map = hint && ! strcmp (hint, "map");
374 is_array = hint && ! strcmp (hint, "array");
375
376 gdbpy_ref<> children (PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
377 NULL));
378 if (children == NULL)
379 {
381 return;
382 }
383
384 gdbpy_ref<> iter (PyObject_GetIter (children.get ()));
385 if (iter == NULL)
386 {
388 return;
389 }
390
391 /* Use the prettyformat_arrays option if we are printing an array,
392 and the pretty option otherwise. */
393 if (is_array)
394 pretty = options->prettyformat_arrays;
395 else
396 {
397 if (options->prettyformat == Val_prettyformat)
398 pretty = 1;
399 else
400 pretty = options->prettyformat_structs;
401 }
402
403 done_flag = 0;
404 for (i = 0; i < options->print_max; ++i)
405 {
406 PyObject *py_v;
407 const char *name;
408
409 gdbpy_ref<> item (PyIter_Next (iter.get ()));
410 if (item == NULL)
411 {
412 if (PyErr_Occurred ())
414 /* Set a flag so we can know whether we printed all the
415 available elements. */
416 else
417 done_flag = 1;
418 break;
419 }
420
421 if (! PyTuple_Check (item.get ()) || PyTuple_Size (item.get ()) != 2)
422 {
423 PyErr_SetString (PyExc_TypeError,
424 _("Result of children iterator not a tuple"
425 " of two elements."));
427 continue;
428 }
429 if (! PyArg_ParseTuple (item.get (), "sO", &name, &py_v))
430 {
431 /* The user won't necessarily get a stack trace here, so provide
432 more context. */
435 _("Bad result from children iterator.\n"));
437 continue;
438 }
439
440 /* Print initial "=" to separate print_string_repr output and
441 children. For other elements, there are three cases:
442 1. Maps. Print a "," after each value element.
443 2. Arrays. Always print a ",".
444 3. Other. Always print a ",". */
445 if (i == 0)
446 {
447 if (!is_py_none)
448 gdb_puts (" = ", stream);
449 }
450 else if (! is_map || i % 2 == 0)
451 gdb_puts (pretty ? "," : ", ", stream);
452
453 /* Skip printing children if max_depth has been reached. This check
454 is performed after print_string_repr and the "=" separator so that
455 these steps are not skipped if the variable is located within the
456 permitted depth. */
457 if (val_print_check_max_depth (stream, recurse, options, language))
458 return;
459 else if (i == 0)
460 /* Print initial "{" to bookend children. */
461 gdb_puts ("{", stream);
462
463 /* In summary mode, we just want to print "= {...}" if there is
464 a value. */
465 if (options->summary)
466 {
467 /* This increment tricks the post-loop logic to print what
468 we want. */
469 ++i;
470 /* Likewise. */
471 pretty = 0;
472 break;
473 }
474
475 if (! is_map || i % 2 == 0)
476 {
477 if (pretty)
478 {
479 gdb_puts ("\n", stream);
480 print_spaces (2 + 2 * recurse, stream);
481 }
482 else
483 stream->wrap_here (2 + 2 *recurse);
484 }
485
486 if (is_map && i % 2 == 0)
487 gdb_puts ("[", stream);
488 else if (is_array)
489 {
490 /* We print the index, not whatever the child method
491 returned as the name. */
492 if (options->print_array_indexes)
493 gdb_printf (stream, "[%d] = ", i);
494 }
495 else if (! is_map)
496 {
497 gdb_puts (name, stream);
498 gdb_puts (" = ", stream);
499 }
500
501 if (gdbpy_is_lazy_string (py_v))
502 {
503 CORE_ADDR addr;
504 struct type *type;
505 long length;
506 gdb::unique_xmalloc_ptr<char> encoding;
507 struct value_print_options local_opts = *options;
508
509 gdbpy_extract_lazy_string (py_v, &addr, &type, &length, &encoding);
510
511 local_opts.addressprint = false;
512 val_print_string (type, encoding.get (), addr, (int) length, stream,
513 &local_opts);
514 }
515 else if (gdbpy_is_string (py_v))
516 {
517 gdb::unique_xmalloc_ptr<char> output;
518
519 output = python_string_to_host_string (py_v);
520 if (!output)
522 else
523 gdb_puts (output.get (), stream);
524 }
525 else
526 {
527 struct value *value = convert_value_from_python (py_v);
528
529 if (value == NULL)
530 {
532 error (_("Error while executing Python code."));
533 }
534 else
535 {
536 /* When printing the key of a map we allow one additional
537 level of depth. This means the key will print before the
538 value does. */
539 struct value_print_options opt = *options;
540 if (is_map && i % 2 == 0
541 && opt.max_depth != -1
542 && opt.max_depth < INT_MAX)
543 ++opt.max_depth;
544 common_val_print (value, stream, recurse + 1, &opt, language);
545 }
546 }
547
548 if (is_map && i % 2 == 0)
549 gdb_puts ("] = ", stream);
550 }
551
552 if (i)
553 {
554 if (!done_flag)
555 {
556 if (pretty)
557 {
558 gdb_puts ("\n", stream);
559 print_spaces (2 + 2 * recurse, stream);
560 }
561 gdb_puts ("...", stream);
562 }
563 if (pretty)
564 {
565 gdb_puts ("\n", stream);
566 print_spaces (2 * recurse, stream);
567 }
568 gdb_puts ("}", stream);
569 }
570}
571
572enum ext_lang_rc
574 struct value *value,
575 struct ui_file *stream, int recurse,
576 const struct value_print_options *options,
577 const struct language_defn *language)
578{
579 struct type *type = value->type ();
580 struct gdbarch *gdbarch = type->arch ();
581 enum gdbpy_string_repr_result print_result;
582
583 if (value->lazy ())
584 value->fetch_lazy ();
585
586 /* No pretty-printer support for unavailable values. */
587 if (!value->bytes_available (0, type->length ()))
588 return EXT_LANG_RC_NOP;
589
591 return EXT_LANG_RC_NOP;
592
593 gdbpy_enter enter_py (gdbarch, language);
594
596 if (val_obj == NULL)
597 {
599 return EXT_LANG_RC_ERROR;
600 }
601
602 /* Find the constructor. */
603 gdbpy_ref<> printer (find_pretty_printer (val_obj.get ()));
604 if (printer == NULL)
605 {
607 return EXT_LANG_RC_ERROR;
608 }
609
610 if (printer == Py_None)
611 return EXT_LANG_RC_NOP;
612
613 scoped_restore set_options = make_scoped_restore (&gdbpy_current_print_options,
614 options);
615
616 /* If we are printing a map, we want some special formatting. */
617 gdb::unique_xmalloc_ptr<char> hint (gdbpy_get_display_hint (printer.get ()));
618
619 /* Print the section */
620 print_result = print_string_repr (printer.get (), hint.get (), stream,
621 recurse, options, language, gdbarch);
622 if (print_result != string_repr_error)
623 print_children (printer.get (), hint.get (), stream, recurse, options,
624 language, print_result == string_repr_none);
625
626 if (PyErr_Occurred ())
628 return EXT_LANG_RC_OK;
629}
630
631
632/* Apply a pretty-printer for the varobj code. PRINTER_OBJ is the
633 print object. It must have a 'to_string' method (but this is
634 checked by varobj, not here) which takes no arguments and
635 returns a string. The printer will return a value and in the case
636 of a Python string being returned, this function will return a
637 PyObject containing the string. For any other type, *REPLACEMENT is
638 set to the replacement value and this function returns NULL. On
639 error, *REPLACEMENT is set to NULL and this function also returns
640 NULL. */
643 struct value **replacement,
644 struct ui_file *stream,
645 const value_print_options *opts)
646{
647 scoped_restore set_options = make_scoped_restore (&gdbpy_current_print_options,
648 opts);
649
650 *replacement = NULL;
651 gdbpy_ref<> py_str = pretty_print_one_value (printer_obj, replacement);
652
653 if (*replacement == NULL && py_str == NULL)
655
656 return py_str;
657}
658
659/* Find a pretty-printer object for the varobj module. Returns a new
660 reference to the object if successful; returns NULL if not. VALUE
661 is the value for which a printer tests to determine if it
662 can pretty-print the value. */
665{
667 if (val_obj == NULL)
668 return NULL;
669
670 return find_pretty_printer (val_obj.get ());
671}
672
673/* A Python function which wraps find_pretty_printer and instantiates
674 the resulting class. This accepts a Value argument and returns a
675 pretty printer instance, or None. This function is useful as an
676 argument to the MI command -var-set-visualizer. */
677PyObject *
679{
680 PyObject *val_obj;
681 struct value *value;
682
683 if (! PyArg_ParseTuple (args, "O", &val_obj))
684 return NULL;
685 value = value_object_to_value (val_obj);
686 if (! value)
687 {
688 PyErr_SetString (PyExc_TypeError,
689 _("Argument must be a gdb.Value."));
690 return NULL;
691 }
692
693 return find_pretty_printer (val_obj).release ();
694}
695
696/* Helper function to set a boolean in a dictionary. */
697static int
698set_boolean (PyObject *dict, const char *name, bool val)
699{
700 gdbpy_ref<> val_obj (PyBool_FromLong (val));
701 if (val_obj == nullptr)
702 return -1;
703 return PyDict_SetItemString (dict, name, val_obj.get ());
704}
705
706/* Helper function to set an integer in a dictionary. */
707static int
708set_unsigned (PyObject *dict, const char *name, unsigned int val)
709{
711 if (val_obj == nullptr)
712 return -1;
713 return PyDict_SetItemString (dict, name, val_obj.get ());
714}
715
716/* Implement gdb.print_options. */
717PyObject *
719{
720 gdbpy_ref<> result (PyDict_New ());
721 if (result == nullptr)
722 return nullptr;
723
726
727 if (set_boolean (result.get (), "raw",
728 opts.raw) < 0
729 || set_boolean (result.get (), "pretty_arrays",
730 opts.prettyformat_arrays) < 0
731 || set_boolean (result.get (), "pretty_structs",
732 opts.prettyformat_structs) < 0
733 || set_boolean (result.get (), "array_indexes",
734 opts.print_array_indexes) < 0
735 || set_boolean (result.get (), "symbols",
736 opts.symbol_print) < 0
737 || set_boolean (result.get (), "unions",
738 opts.unionprint) < 0
739 || set_boolean (result.get (), "address",
740 opts.addressprint) < 0
741 || set_boolean (result.get (), "deref_refs",
742 opts.deref_ref) < 0
743 || set_boolean (result.get (), "actual_objects",
744 opts.objectprint) < 0
745 || set_boolean (result.get (), "static_members",
746 opts.static_field_print) < 0
747 || set_boolean (result.get (), "deref_refs",
748 opts.deref_ref) < 0
749 || set_boolean (result.get (), "nibbles",
750 opts.nibblesprint) < 0
751 || set_boolean (result.get (), "summary",
752 opts.summary) < 0
753 || set_unsigned (result.get (), "max_elements",
754 opts.print_max) < 0
755 || set_unsigned (result.get (), "max_depth",
756 opts.max_depth) < 0
757 || set_unsigned (result.get (), "repeat_threshold",
758 opts.repeat_count_threshold) < 0)
759 return nullptr;
760
761 if (opts.format != 0)
762 {
763 char str[2] = { (char) opts.format, 0 };
765 if (fmtstr == nullptr)
766 return nullptr;
767 if (PyDict_SetItemString (result.get (), "format", fmtstr.get ()) < 0)
768 return nullptr;
769 }
770
771 return result.release ();
772}
773
774/* Helper function that either finds the prevailing print options, or
775 calls get_user_print_options. */
776void
784
785/* A ValuePrinter is just a "tag", so it has no state other than that
786 required by Python. */
788{
789 PyObject_HEAD
790};
791
792/* The ValuePrinter type object. */
794{
795 PyVarObject_HEAD_INIT (NULL, 0)
796 "gdb.ValuePrinter", /*tp_name*/
797 sizeof (printer_object), /*tp_basicsize*/
798 0, /*tp_itemsize*/
799 0, /*tp_dealloc*/
800 0, /*tp_print*/
801 0, /*tp_getattr*/
802 0, /*tp_setattr*/
803 0, /*tp_compare*/
804 0, /*tp_repr*/
805 0, /*tp_as_number*/
806 0, /*tp_as_sequence*/
807 0, /*tp_as_mapping*/
808 0, /*tp_hash*/
809 0, /*tp_call*/
810 0, /*tp_str*/
811 0, /*tp_getattro*/
812 0, /*tp_setattro*/
813 0, /*tp_as_buffer*/
814 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
815 "GDB value printer object", /* tp_doc */
816 0, /* tp_traverse */
817 0, /* tp_clear */
818 0, /* tp_richcompare */
819 0, /* tp_weaklistoffset */
820 0, /* tp_iter */
821 0, /* tp_iternext */
822 0, /* tp_methods */
823 0, /* tp_members */
824 0, /* tp_getset */
825 0, /* tp_base */
826 0, /* tp_dict */
827 0, /* tp_descr_get */
828 0, /* tp_descr_set */
829 0, /* tp_dictoffset */
830 0, /* tp_init */
831 0, /* tp_alloc */
832 PyType_GenericNew, /* tp_new */
833};
834
835/* Set up the ValuePrinter type. */
836
837static int
839{
840 if (PyType_Ready (&printer_object_type) < 0)
841 return -1;
842 return gdb_pymodule_addobject (gdb_module, "ValuePrinter",
844}
845
constexpr string_view get()
Definition 70483.cc:49
const char *const name
ui_file_style style() const
Definition cli-style.c:169
gdb::unique_xmalloc_ptr< char > to_string() const
Definition py-utils.c:186
virtual void wrap_here(int indent)
Definition ui-file.h:119
cli_style_option metadata_style
language
Definition defs.h:211
ext_lang_rc
Definition extension.h:165
@ EXT_LANG_RC_NOP
Definition extension.h:170
@ EXT_LANG_RC_OK
Definition extension.h:167
@ EXT_LANG_RC_ERROR
Definition extension.h:179
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition gdbtypes.c:6168
struct program_space * current_program_space
Definition progspace.c:40
void gdbpy_extract_lazy_string(PyObject *string, CORE_ADDR *addr, struct type **str_elt_type, long *length, gdb::unique_xmalloc_ptr< char > *encoding)
int gdbpy_is_lazy_string(PyObject *result)
gdbpy_ref objfile_to_objfile_object(struct objfile *objfile)
Definition py-objfile.c:686
PyObject * objfpy_get_printers(PyObject *o, void *ignore)
Definition py-objfile.c:255
int value
Definition py-param.c:79
static int set_boolean(PyObject *dict, const char *name, bool val)
static enum gdbpy_string_repr_result print_string_repr(PyObject *printer, const char *hint, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language, struct gdbarch *gdbarch)
gdbpy_ref apply_varobj_pretty_printer(PyObject *printer_obj, struct value **replacement, struct ui_file *stream, const value_print_options *opts)
static int set_unsigned(PyObject *dict, const char *name, unsigned int val)
static gdbpy_ref find_pretty_printer_from_gdb(PyObject *value)
gdb::unique_xmalloc_ptr< char > gdbpy_get_display_hint(PyObject *printer)
PyObject * gdbpy_default_visualizer(PyObject *self, PyObject *args)
static gdbpy_ref search_pp_list(PyObject *list, PyObject *value)
PyTypeObject printer_object_type
PyObject * gdbpy_print_options(PyObject *unused1, PyObject *unused2)
static void print_stack_unless_memory_error(struct ui_file *stream)
static gdbpy_ref find_pretty_printer(PyObject *value)
static gdbpy_ref find_pretty_printer_from_progspace(PyObject *value)
static int gdbpy_initialize_prettyprint()
static void print_children(PyObject *printer, const char *hint, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language, int is_py_none)
static PyObject * find_pretty_printer_from_objfiles(PyObject *value)
gdbpy_ref gdbpy_get_varobj_pretty_printer(struct value *value)
const struct value_print_options * gdbpy_current_print_options
static gdbpy_ref pretty_print_one_value(PyObject *printer, struct value **out_value)
enum ext_lang_rc gdbpy_apply_val_pretty_printer(const struct extension_language_defn *extlang, struct value *value, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
gdbpy_string_repr_result
@ string_repr_error
@ string_repr_none
@ string_repr_ok
void gdbpy_get_print_options(value_print_options *opts)
gdbpy_ref pspace_to_pspace_object(struct program_space *pspace)
PyObject * pspy_get_printers(PyObject *o, void *ignore)
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
Definition py-ref.h:42
gdbpy_ref host_string_to_python_string(const char *str)
Definition py-utils.c:154
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
Definition py-utils.c:334
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
Definition py-utils.c:142
gdbpy_ref python_string_to_target_python_string(PyObject *obj)
Definition py-utils.c:129
int gdbpy_is_string(PyObject *obj)
Definition py-utils.c:164
gdbpy_ref gdb_py_object_from_ulongest(ULONGEST l)
Definition py-utils.c:293
struct value * convert_value_from_python(PyObject *obj)
Definition py-value.c:1892
PyObject * value_to_value_object(struct value *val)
Definition py-value.c:1854
struct value * value_object_to_value(PyObject *self)
Definition py-value.c:1877
void gdbpy_print_stack(void)
int gdbpy_print_python_errors_p(void)
PyObject * gdb_module
int gdb_python_initialized
PyObject * gdbpy_children_cst
#define GDBPY_INITIALIZE_FILE(INIT,...)
PyObject * gdbpy_gdb_memory_error
PyObject * gdbpy_display_hint_cst
PyObject * gdbpy_enabled_cst
PyObject * gdbpy_to_string_cst
PyObject * gdb_python_module
enum var_types type
Definition scm-param.c:142
struct type * builtin_char
Definition gdbtypes.h:2078
objfiles_range objfiles()
Definition progspace.h:209
ULONGEST length() const
Definition gdbtypes.h:983
gdbarch * arch() const
Definition gdbtypes.c:273
unsigned int print_max
Definition valprint.h:68
enum val_prettyformat prettyformat
Definition valprint.h:41
bool prettyformat_structs
Definition valprint.h:47
Definition value.h:130
bool lazy() const
Definition value.h:265
bool bytes_available(LONGEST offset, ULONGEST length) const
Definition value.c:187
struct type * type() const
Definition value.h:180
void fetch_lazy()
Definition value.c:4001
void print_spaces(int n, struct ui_file *stream)
Definition utils.c:1968
void fprintf_styled(struct ui_file *stream, const ui_file_style &style, const char *format,...)
Definition utils.c:1898
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
void gdb_puts(const char *linebuffer, struct ui_file *stream)
Definition utils.c:1809
#define gdb_stderr
Definition utils.h:187
bool val_print_check_max_depth(struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
Definition valprint.c:1104
int val_print_string(struct type *elttype, const char *encoding, CORE_ADDR addr, int len, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:2643
void get_user_print_options(struct value_print_options *opts)
Definition valprint.c:135
void common_val_print(struct value *value, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
Definition valprint.c:1033
@ Val_prettyformat
Definition valprint.h:31
int PyObject
Definition varobj.c:41