aboutsummaryrefslogtreecommitdiff
path: root/gdb/guile
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/guile
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/guile')
-rw-r--r--gdb/guile/guile-internal.h5
-rw-r--r--gdb/guile/scm-pretty-print.c16
-rw-r--r--gdb/guile/scm-value.c18
3 files changed, 26 insertions, 13 deletions
diff --git a/gdb/guile/guile-internal.h b/gdb/guile/guile-internal.h
index 08fcb33..c501e2b 100644
--- a/gdb/guile/guile-internal.h
+++ b/gdb/guile/guile-internal.h
@@ -579,6 +579,7 @@ extern struct value *vlscm_scm_to_value (SCM scm);
extern int vlscm_is_value (SCM scm);
extern SCM vlscm_scm_from_value (struct value *value);
+extern SCM vlscm_scm_from_value_no_release (struct value *value);
extern struct value *vlscm_convert_typed_value_from_scheme
(const char *func_name, int obj_arg_pos, SCM obj,
@@ -602,10 +603,8 @@ extern void gdbscm_preserve_values
extern enum ext_lang_rc gdbscm_apply_val_pretty_printer
(const struct extension_language_defn *,
- struct type *type,
- LONGEST embedded_offset, CORE_ADDR address,
- struct ui_file *stream, int recurse,
struct value *val,
+ struct ui_file *stream, int recurse,
const struct value_print_options *options,
const struct language_defn *language);
diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c
index 3ab1bd1..ccc6164 100644
--- a/gdb/guile/scm-pretty-print.c
+++ b/gdb/guile/scm-pretty-print.c
@@ -943,36 +943,32 @@ ppscm_print_children (SCM printer, enum display_hint hint,
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 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);
SCM exception = SCM_BOOL_F;
SCM printer = SCM_BOOL_F;
SCM val_obj = SCM_BOOL_F;
- struct value *value;
enum display_hint hint;
enum ext_lang_rc result = EXT_LANG_RC_NOP;
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_scheme_initialized)
return EXT_LANG_RC_NOP;
/* Instantiate the printer. */
- value = value_from_component (val, type, embedded_offset);
-
- val_obj = vlscm_scm_from_value (value);
+ val_obj = vlscm_scm_from_value_no_release (value);
if (gdbscm_is_exception (val_obj))
{
exception = val_obj;
diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c
index 020b5e1..53b373e 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -261,6 +261,24 @@ vlscm_scm_from_value (struct value *value)
return v_scm;
}
+/* Create a new <gdb:value> object that encapsulates VALUE.
+ The value is not released from the all_values chain. */
+
+SCM
+vlscm_scm_from_value_no_release (struct value *value)
+{
+ /* N.B. It's important to not cause any side-effects until we know the
+ conversion worked. */
+ SCM v_scm = vlscm_make_value_smob ();
+ value_smob *v_smob = (value_smob *) SCM_SMOB_DATA (v_scm);
+
+ value_incref (value);
+ v_smob->value = value;
+ vlscm_remember_scheme_value (v_smob);
+
+ return v_scm;
+}
+
/* Returns the <gdb:value> object in SELF.
Throws an exception if SELF is not a <gdb:value> object. */