57 Py_ssize_t pp_list_size, list_index;
59 pp_list_size = PyList_Size (list);
60 for (list_index = 0; list_index < pp_list_size; list_index++)
62 PyObject *function = PyList_GetItem (list, list_index);
74 cmp = PyObject_IsTrue (attr.get ());
86 else if (printer != Py_None)
116 if (function == NULL)
119 if (function != Py_None)
120 return function.release ();
158 if (pp_list == NULL || ! PyList_Check (pp_list.get ()))
174 if (function == NULL || function != Py_None)
179 if (function == NULL || function != Py_None)
212 && result != Py_None)
215 if (PyErr_Occurred ())
222 catch (
const gdb_exception &except)
233gdb::unique_xmalloc_ptr<char>
236 gdb::unique_xmalloc_ptr<char> result;
266 gdb::unique_xmalloc_ptr<char> msg = fetched_error.
to_string ();
268 if (msg == NULL || *msg ==
'\0')
270 _(
"<error reading variable>"));
273 _(
"<error reading variable: %s>"), msg.get ());
284 struct ui_file *stream,
int recurse,
289 struct value *replacement = NULL;
295 if (py_str == Py_None)
302 gdb::unique_xmalloc_ptr<char> encoding;
310 stream, &local_opts);
322 output = PyBytes_AS_STRING (
string.
get ());
323 length = PyBytes_GET_SIZE (
string.
get ());
326 if (hint && !strcmp (hint,
"string"))
328 length, NULL, 0, options);
339 else if (replacement)
343 opts.addressprint =
false;
360 struct ui_file *stream,
int recurse,
365 int is_map, is_array, done_flag, pretty;
373 is_map = hint && ! strcmp (hint,
"map");
374 is_array = hint && ! strcmp (hint,
"array");
378 if (children == NULL)
384 gdbpy_ref<> iter (PyObject_GetIter (children.get ()));
412 if (PyErr_Occurred ())
421 if (! PyTuple_Check (item.get ()) || PyTuple_Size (item.get ()) != 2)
423 PyErr_SetString (PyExc_TypeError,
424 _(
"Result of children iterator not a tuple"
425 " of two elements."));
429 if (! PyArg_ParseTuple (item.get (),
"sO", &
name, &py_v))
435 _(
"Bad result from children iterator.\n"));
450 else if (! is_map || i % 2 == 0)
451 gdb_puts (pretty ?
"," :
", ", stream);
475 if (! is_map || i % 2 == 0)
486 if (is_map && i % 2 == 0)
506 gdb::unique_xmalloc_ptr<char> encoding;
517 gdb::unique_xmalloc_ptr<char> output;
532 error (_(
"Error while executing Python code."));
540 if (is_map && i % 2 == 0
548 if (is_map && i % 2 == 0)
575 struct ui_file *stream,
int recurse,
610 if (printer == Py_None)
623 print_children (printer.get (), hint.get (), stream, recurse, options,
626 if (PyErr_Occurred ())
643 struct value **replacement,
653 if (*replacement == NULL && py_str == NULL)
683 if (! PyArg_ParseTuple (args,
"O", &val_obj))
688 PyErr_SetString (PyExc_TypeError,
689 _(
"Argument must be a gdb.Value."));
701 if (val_obj ==
nullptr)
703 return PyDict_SetItemString (dict,
name, val_obj.get ());
711 if (val_obj ==
nullptr)
713 return PyDict_SetItemString (dict,
name, val_obj.get ());
721 if (result ==
nullptr)
730 opts.prettyformat_arrays) < 0
732 opts.prettyformat_structs) < 0
734 opts.print_array_indexes) < 0
736 opts.symbol_print) < 0
740 opts.addressprint) < 0
744 opts.objectprint) < 0
746 opts.static_field_print) < 0
750 opts.nibblesprint) < 0
758 opts.repeat_count_threshold) < 0)
761 if (opts.format != 0)
763 char str[2] = { (char) opts.format, 0 };
765 if (fmtstr ==
nullptr)
767 if (PyDict_SetItemString (result.get (),
"format", fmtstr.get ()) < 0)
771 return result.release ();
795 PyVarObject_HEAD_INIT (NULL, 0)
814 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
815 "GDB value printer object",
constexpr string_view get()
ui_file_style style() const
gdb::unique_xmalloc_ptr< char > to_string() const
virtual void wrap_here(int indent)
cli_style_option metadata_style
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
struct program_space * current_program_space
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)
PyObject * objfpy_get_printers(PyObject *o, void *ignore)
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)
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
gdbpy_ref host_string_to_python_string(const char *str)
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
gdbpy_ref python_string_to_target_python_string(PyObject *obj)
int gdbpy_is_string(PyObject *obj)
gdbpy_ref gdb_py_object_from_ulongest(ULONGEST l)
struct value * convert_value_from_python(PyObject *obj)
PyObject * value_to_value_object(struct value *val)
struct value * value_object_to_value(PyObject *self)
void gdbpy_print_stack(void)
int gdbpy_print_python_errors_p(void)
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
struct type * builtin_char
objfiles_range objfiles()
enum val_prettyformat prettyformat
bool prettyformat_structs
bool bytes_available(LONGEST offset, ULONGEST length) const
struct type * type() const
void print_spaces(int n, struct ui_file *stream)
void fprintf_styled(struct ui_file *stream, const ui_file_style &style, const char *format,...)
void gdb_printf(struct ui_file *stream, const char *format,...)
void gdb_puts(const char *linebuffer, struct ui_file *stream)
bool val_print_check_max_depth(struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
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)
void get_user_print_options(struct value_print_options *opts)
void common_val_print(struct value *value, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)