enum ext_lang_rc gdbpy_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) { struct gdbarch *gdbarch = get_type_arch (type); struct value *value; enum string_repr_result print_result; if (value_lazy (val)) value_fetch_lazy (val); /* No pretty-printer support for unavailable values. */ if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type))) return EXT_LANG_RC_NOP; if (!gdb_python_initialized) return EXT_LANG_RC_NOP; gdbpy_enter enter_py (gdbarch, language); /* Instantiate the printer. */ value = value_from_component (val, type, embedded_offset); gdbpy_ref<> val_obj (value_to_value_object (value)); if (val_obj == NULL) { print_stack_unless_memory_error (stream); return EXT_LANG_RC_ERROR; } /* Find the constructor. */ gdbpy_ref<> printer (find_pretty_printer (val_obj.get ())); if (printer == NULL) { print_stack_unless_memory_error (stream); return EXT_LANG_RC_ERROR; } if (printer == Py_None) return EXT_LANG_RC_NOP; /* If we are printing a map, we want some special formatting. */ gdb::unique_xmalloc_ptr<char> hint (gdbpy_get_display_hint (printer.get ())); /* Print the section */ print_result = print_string_repr (printer.get (), hint.get (), stream, recurse, options, language, gdbarch); if (print_result != string_repr_error) print_children (printer.get (), hint.get (), stream, recurse, options, language, print_result == string_repr_none); if (PyErr_Occurred ()) print_stack_unless_memory_error (stream); return EXT_LANG_RC_OK; }
enum ext_lang_rc gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang, struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, const struct value_print_options *options, const struct language_defn *language) { struct gdbarch *gdbarch = get_type_arch (type); PyObject *printer = NULL; PyObject *val_obj = NULL; struct value *value; char *hint = NULL; struct cleanup *cleanups; enum ext_lang_rc result = EXT_LANG_RC_NOP; enum string_repr_result print_result; /* No pretty-printer support for unavailable values. */ if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type))) return EXT_LANG_RC_NOP; if (!gdb_python_initialized) return EXT_LANG_RC_NOP; cleanups = ensure_python_env (gdbarch, language); /* Instantiate the printer. */ if (valaddr) valaddr += embedded_offset; value = value_from_contents_and_address (type, valaddr, address + embedded_offset); set_value_component_location (value, val); /* set_value_component_location resets the address, so we may need to set it again. */ if (VALUE_LVAL (value) != lval_internalvar && VALUE_LVAL (value) != lval_internalvar_component && VALUE_LVAL (value) != lval_computed) set_value_address (value, address + embedded_offset); val_obj = value_to_value_object (value); if (! val_obj) { result = EXT_LANG_RC_ERROR; goto done; } /* Find the constructor. */ printer = find_pretty_printer (val_obj); Py_DECREF (val_obj); if (printer == NULL) { result = EXT_LANG_RC_ERROR; goto done; } make_cleanup_py_decref (printer); if (printer == Py_None) { result = EXT_LANG_RC_NOP; goto done; } /* If we are printing a map, we want some special formatting. */ hint = gdbpy_get_display_hint (printer); make_cleanup (free_current_contents, &hint); /* Print the section */ print_result = print_string_repr (printer, hint, stream, recurse, options, language, gdbarch); if (print_result != string_repr_error) print_children (printer, hint, stream, recurse, options, language, print_result == string_repr_none); result = EXT_LANG_RC_OK; done: if (PyErr_Occurred ()) print_stack_unless_memory_error (stream); do_cleanups (cleanups); return result; }