aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-03-13 17:39:52 -0600
committerTom Tromey <tom@tromey.com>2020-03-13 18:03:42 -0600
commit42331a1ea2a13ce15ec202c5f0fbef3e5171253c (patch)
tree69cd05a4b2d8de096c8ee3f0b5a87c219f855ee1 /gdb/python
parent3a916a975745f386cabbaba64531ed9b5f8be509 (diff)
downloadgdb-42331a1ea2a13ce15ec202c5f0fbef3e5171253c.zip
gdb-42331a1ea2a13ce15ec202c5f0fbef3e5171253c.tar.gz
gdb-42331a1ea2a13ce15ec202c5f0fbef3e5171253c.tar.bz2
Change extension language pretty-printers to use value API
This changes the extension language pretty-printers to use the value API. Note that new functions were needed, for both Guile and Python. Currently both languages always wrap values by removing the values from the value chain. This makes sense to avoid strange behavior with watchpoints, and to avoid excessive memory use. However, when printing, it's important to leave the passed-in value untouched, in case pretty-printing does nothing -- that way the caller can still access it. gdb/ChangeLog 2020-03-13 Tom Tromey <tom@tromey.com> * valprint.c (do_val_print): Update. * python/python-internal.h (gdbpy_apply_val_pretty_printer): Take a struct value. (value_to_value_object_no_release): Declare. * python/py-value.c (value_to_value_object_no_release): New function. * python/py-prettyprint.c (gdbpy_apply_val_pretty_printer): Take a struct value. * guile/scm-value.c (vlscm_scm_from_value_no_release): New function. * guile/scm-pretty-print.c (gdbscm_apply_val_pretty_printer): Take a struct value. * guile/guile-internal.h (vlscm_scm_from_value_no_release): Declare. (gdbscm_apply_val_pretty_printer): Take a struct value. * extension.h (apply_ext_lang_val_pretty_printer): Take a struct value. * extension.c (apply_ext_lang_val_pretty_printer): Take a struct value. * extension-priv.h (struct extension_language_ops) <apply_val_pretty_printer>: Take a struct value. * cp-valprint.c (cp_print_value): Create a struct value. (cp_print_value): Update.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-prettyprint.c17
-rw-r--r--gdb/python/py-value.c21
-rw-r--r--gdb/python/python-internal.h5
3 files changed, 29 insertions, 14 deletions
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index deecb12..7cb20df 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -558,22 +558,20 @@ print_children (PyObject *printer, const char *hint,
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 value *value,
struct ui_file *stream, int recurse,
- struct value *val,
const struct value_print_options *options,
const struct language_defn *language)
{
+ struct type *type = value_type (value);
struct gdbarch *gdbarch = get_type_arch (type);
- struct value *value;
enum string_repr_result print_result;
- if (value_lazy (val))
- value_fetch_lazy (val);
+ if (value_lazy (value))
+ value_fetch_lazy (value);
/* No pretty-printer support for unavailable values. */
- if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
+ if (!value_bytes_available (value, 0, TYPE_LENGTH (type)))
return EXT_LANG_RC_NOP;
if (!gdb_python_initialized)
@@ -581,10 +579,7 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
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));
+ gdbpy_ref<> val_obj (value_to_value_object_no_release (value));
if (val_obj == NULL)
{
print_stack_unless_memory_error (stream);
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 497696a..bc75a68 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1788,6 +1788,27 @@ value_to_value_object (struct value *val)
return (PyObject *) val_obj;
}
+/* Returns an object for a value, but without releasing it from the
+ all_values chain. */
+PyObject *
+value_to_value_object_no_release (struct value *val)
+{
+ value_object *val_obj;
+
+ val_obj = PyObject_New (value_object, &value_object_type);
+ if (val_obj != NULL)
+ {
+ value_incref (val);
+ val_obj->value = val;
+ val_obj->address = NULL;
+ val_obj->type = NULL;
+ val_obj->dynamic_type = NULL;
+ note_value (val_obj);
+ }
+
+ return (PyObject *) val_obj;
+}
+
/* Returns a borrowed reference to the struct value corresponding to
the given value object. */
struct value *
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index bbb66bd..e352b30 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -391,10 +391,8 @@ extern int gdbpy_auto_load_enabled (const struct extension_language_defn *);
extern enum ext_lang_rc gdbpy_apply_val_pretty_printer
(const struct extension_language_defn *,
- struct type *type,
- LONGEST embedded_offset, CORE_ADDR address,
+ struct value *value,
struct ui_file *stream, int recurse,
- struct value *val,
const struct value_print_options *options,
const struct language_defn *language);
extern enum ext_lang_bt_status gdbpy_apply_frame_filter
@@ -456,6 +454,7 @@ PyObject *symbol_to_symbol_object (struct symbol *sym);
PyObject *block_to_block_object (const struct block *block,
struct objfile *objfile);
PyObject *value_to_value_object (struct value *v);
+PyObject *value_to_value_object_no_release (struct value *v);
PyObject *type_to_type_object (struct type *);
PyObject *frame_info_to_frame_object (struct frame_info *frame);
PyObject *symtab_to_linetable_object (PyObject *symtab);