From: George Barrett Date: Wed, 28 Apr 2021 17:32:47 +0000 (+1000) Subject: Guile: add value-{rvalue-,}reference-value X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9d4fc61d41a0aef2d199e2b18d238603a8e4be98;p=binutils-gdb.git Guile: add value-{rvalue-,}reference-value The Guile API doesn't currently have an equivalent to the Python API's Value.reference_value() or Value.rvalue_reference_value(). This commit adds a procedure with equivalent semantics to the Guile API. gdb/ChangeLog: * NEWS (Guile API): Note the addition of new procedures. * guile/scm-value.c (gdbscm_reference_value): Add helper function for reference value creation. (gdbscm_value_reference_value): Add implementation of value-reference-value procedure. (gdbscm_value_rvalue_reference_value): Add implementation of value-rvalue-reference-value procedure. (value_functions): Add value-reference-value procedure. Add value-rvalue-reference-value procedure. gdb/doc/ChangeLog: * guile.texi (Values From Inferior In Guile): Add documentation for value-reference-value. Add documentation for value-rvalue-reference-value. gdb/testsuite/ChangeLog: * gdb.guile/scm-value.exp (test_value_in_inferior): Add test for value-reference-value. Add test for value-rvalue-reference-value. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 26751d318b2..f29f60a7d62 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +2021-05-12 George Barrett + + * NEWS (Guile API): Note the addition of new procedures. + * guile/scm-value.c (gdbscm_reference_value): Add helper function + for reference value creation. + (gdbscm_value_reference_value): Add implementation of + value-reference-value procedure. + (gdbscm_value_rvalue_reference_value): Add implementation of + value-rvalue-reference-value procedure. + (value_functions): Add value-reference-value procedure. Add + value-rvalue-reference-value procedure. + 2021-05-12 George Barrett * guile/scm-type.c (type_integer_constants): Add binding for diff --git a/gdb/NEWS b/gdb/NEWS index 250f79153ca..f7844e5d9e3 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -207,6 +207,9 @@ QMemTags value-referenced-value procedure now handles rvalue reference values. + ** New procedures for obtaining reference values: + value-reference-value and value-rvalue-reference-value. + *** Changes in GDB 10 * There are new feature names for ARC targets: "org.gnu.gdb.arc.core" diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 0546f650b32..029e2404470 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,9 @@ +2021-05-12 George Barrett + + * guile.texi (Values From Inferior In Guile): Add documentation + for value-reference-value. Add documentation for + value-rvalue-reference-value. + 2021-05-12 George Barrett * guile.texi (Types In Guile): Add documentation for diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi index c3e134b5ffe..cca3a943c61 100644 --- a/gdb/doc/guile.texi +++ b/gdb/doc/guile.texi @@ -801,6 +801,16 @@ The @code{} object @code{scm-val} is identical to that corresponding to @code{val}. @end deffn +@deffn {Scheme Procedure} value-reference-value value +Return a new @code{} object which is a reference to the value +encapsulated by @code{} object @var{value}. +@end deffn + +@deffn {Scheme Procedure} value-rvalue-reference-value value +Return a new @code{} object which is an rvalue reference to +the value encapsulated by @code{} object @var{value}. +@end deffn + @deffn {Scheme Procedure} value-field value field-name Return field @var{field-name} from @code{} object @var{value}. @end deffn diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c index f50e8b5b46c..a07bc7d2e61 100644 --- a/gdb/guile/scm-value.c +++ b/gdb/guile/scm-value.c @@ -488,6 +488,38 @@ gdbscm_value_referenced_value (SCM self) }); } +static SCM +gdbscm_reference_value (SCM self, enum type_code refcode) +{ + value_smob *v_smob + = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); + struct value *value = v_smob->value; + + return gdbscm_wrap ([=] + { + scoped_value_mark free_values; + + struct value *res_val = value_ref (value, refcode); + return vlscm_scm_from_value (res_val); + }); +} + +/* (value-reference-value ) -> */ + +static SCM +gdbscm_value_reference_value (SCM self) +{ + return gdbscm_reference_value (self, TYPE_CODE_REF); +} + +/* (value-rvalue-reference-value ) -> */ + +static SCM +gdbscm_value_rvalue_reference_value (SCM self) +{ + return gdbscm_reference_value (self, TYPE_CODE_RVALUE_REF); +} + /* (value-type ) -> */ static SCM @@ -1352,6 +1384,16 @@ For example, for a value which is a reference to an 'int' pointer ('int *'),\n\ value-dereference will result in a value of type 'int' while\n\ value-referenced-value will result in a value of type 'int *'." }, + { "value-reference-value", 1, 0, 0, + as_a_scm_t_subr (gdbscm_value_reference_value), + "\ +Return a object which is a reference to the given value." }, + + { "value-rvalue-reference-value", 1, 0, 0, + as_a_scm_t_subr (gdbscm_value_rvalue_reference_value), + "\ +Return a object which is an rvalue reference to the given value." }, + { "value-field", 2, 0, 0, as_a_scm_t_subr (gdbscm_value_field), "\ Return the specified field of the value.\n\ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index a1cd48578df..691e83cdc94 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2021-05-12 George Barrett + + * gdb.guile/scm-value.exp (test_value_in_inferior): Add test for + value-reference-value. Add test for value-rvalue-reference-value. + 2021-05-11 Tom de Vries * gdb.base/watch_thread_num.exp: Fix "set debug infrun 1" FAILs. diff --git a/gdb/testsuite/gdb.guile/scm-value.exp b/gdb/testsuite/gdb.guile/scm-value.exp index 191af1d71a6..b3f785c9ecf 100644 --- a/gdb/testsuite/gdb.guile/scm-value.exp +++ b/gdb/testsuite/gdb.guile/scm-value.exp @@ -173,6 +173,16 @@ proc test_value_in_inferior {} { "get string beyond null" gdb_test "gu (print nullst)" \ "= divide\\\\000et" + + gdb_scm_test_silent_cmd "gu (define argv-ref (value-reference-value argv))" \ + "test value-reference-value" + gdb_test "gu (equal? argv (value-referenced-value argv-ref))" "#t" + gdb_test "gu (eqv? (type-code (value-type argv-ref)) TYPE_CODE_REF)" "#t" + + gdb_scm_test_silent_cmd "gu (define argv-rref (value-rvalue-reference-value argv))" \ + "test value-rvalue-reference-value" + gdb_test "gu (equal? argv (value-referenced-value argv-rref))" "#t" + gdb_test "gu (eqv? (type-code (value-type argv-rref)) TYPE_CODE_RVALUE_REF)" "#t" } proc test_strings {} {