[1/2] Guile: add value-reference-value

Message ID hghgmkh_5gk&65mc5uti/tcgbi_wck98h78s.r_0k0xh._orcvyd@mail.bob131.so
State New
Headers show
Series
  • Guile: add value-{reference,const}-value
Related show

Commit Message

Mike Frysinger via Gdb-patches April 26, 2021, 12:49 a.m.
The Guile API doesn't currently have an equivalent to the Python API's
gdb.Value.reference_value(). This commit adds a procedure with
equivalent semantics to the Guile API.

gdb/ChangeLog:

2021-04-26  George Barrett  <bob@bob131.so>

	guile/scm-value.c (gdbscm_value_reference_value): Add
	implementation of value-reference-value procedure.
	(value_functions): Add value-reference-value procedure.

gdb/doc/ChangeLog:

2021-04-26  George Barrett  <bob@bob131.so>

	guile.texi (Values From Inferior In Guile): Add documentation
	for value-reference-value.

gdb/testsuite/ChangeLog:

2021-04-26  George Barrett  <bob@bob131.so>

	gdb.guile/scm-value.exp (test_value_in_inferior): Add test
	for value-reference-value.
---
 gdb/doc/guile.texi                    |  5 +++++
 gdb/guile/scm-value.c                 | 23 +++++++++++++++++++++++
 gdb/testsuite/gdb.guile/scm-value.exp |  3 +++
 3 files changed, 31 insertions(+)

-- 
2.30.2

Comments

Andrew Burgess April 26, 2021, 10:03 a.m. | #1
* George Barrett via Gdb-patches <gdb-patches@sourceware.org> [2021-04-26 10:49:32 +1000]:

> The Guile API doesn't currently have an equivalent to the Python API's

> gdb.Value.reference_value(). This commit adds a procedure with

> equivalent semantics to the Guile API.


I was comparing your gdbscm_value_reference_value with Python's
valpy_reference_value and noticed that you had TYPE_CODE_REF while the
Python code used a variable.

This is because Python has two methods reference_value and
rvalue_reference_value, sadly the second of these is not documented.

Given the similarity between reference_value and
rvalue_reference_value, do you think you could add the equivalent of
both of these to guile please?  Feel free to document both of these
for guile.

That would be great, thanks!
Andrew


> 

> gdb/ChangeLog:

> 

> 2021-04-26  George Barrett  <bob@bob131.so>

> 

> 	guile/scm-value.c (gdbscm_value_reference_value): Add

> 	implementation of value-reference-value procedure.

> 	(value_functions): Add value-reference-value procedure.

> 

> gdb/doc/ChangeLog:

> 

> 2021-04-26  George Barrett  <bob@bob131.so>

> 

> 	guile.texi (Values From Inferior In Guile): Add documentation

> 	for value-reference-value.

> 

> gdb/testsuite/ChangeLog:

> 

> 2021-04-26  George Barrett  <bob@bob131.so>

> 

> 	gdb.guile/scm-value.exp (test_value_in_inferior): Add test

> 	for value-reference-value.

> ---

>  gdb/doc/guile.texi                    |  5 +++++

>  gdb/guile/scm-value.c                 | 23 +++++++++++++++++++++++

>  gdb/testsuite/gdb.guile/scm-value.exp |  3 +++

>  3 files changed, 31 insertions(+)

> 

> diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi

> index 649dac559ad..eed94366027 100644

> --- a/gdb/doc/guile.texi

> +++ b/gdb/doc/guile.texi

> @@ -801,6 +801,11 @@ The @code{<gdb:value>} 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{<gdb:value>} object which is a reference to the value

> +encapsulated by @code{<gdb:value>} object @var{value}.

> +@end deffn

> +

>  @deffn {Scheme Procedure} value-field value field-name

>  Return field @var{field-name} from @code{<gdb:value>} object @var{value}.

>  @end deffn

> diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c

> index 59995169cd0..dc59633ec6f 100644

> --- a/gdb/guile/scm-value.c

> +++ b/gdb/guile/scm-value.c

> @@ -487,6 +487,24 @@ gdbscm_value_referenced_value (SCM self)

>      });

>  }

>  

> +/* (value-reference-value <gdb:value>) -> <gdb:value> */

> +

> +static SCM

> +gdbscm_value_reference_value (SCM self)

> +{

> +  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, TYPE_CODE_REF);

> +      return vlscm_scm_from_value (res_val);

> +    });

> +}

> +

>  /* (value-type <gdb:value>) -> <gdb:type> */

>  

>  static SCM

> @@ -1351,6 +1369,11 @@ 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 <gdb:value> object which is a 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/gdb.guile/scm-value.exp b/gdb/testsuite/gdb.guile/scm-value.exp

> index 191af1d71a6..83399f32103 100644

> --- a/gdb/testsuite/gdb.guile/scm-value.exp

> +++ b/gdb/testsuite/gdb.guile/scm-value.exp

> @@ -173,6 +173,9 @@ proc test_value_in_inferior {} {

>  	"get string beyond null"

>      gdb_test "gu (print nullst)" \

>  	"= divide\\\\000et"

> +

> +    gdb_test "gu (equal? argv (value-referenced-value (value-reference-value argv)))" \

> +	"#t"

>  }

>  

>  proc test_strings {} {

> -- 

> 2.30.2

Patch

diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi
index 649dac559ad..eed94366027 100644
--- a/gdb/doc/guile.texi
+++ b/gdb/doc/guile.texi
@@ -801,6 +801,11 @@  The @code{<gdb:value>} 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{<gdb:value>} object which is a reference to the value
+encapsulated by @code{<gdb:value>} object @var{value}.
+@end deffn
+
 @deffn {Scheme Procedure} value-field value field-name
 Return field @var{field-name} from @code{<gdb:value>} object @var{value}.
 @end deffn
diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c
index 59995169cd0..dc59633ec6f 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -487,6 +487,24 @@  gdbscm_value_referenced_value (SCM self)
     });
 }
 
+/* (value-reference-value <gdb:value>) -> <gdb:value> */
+
+static SCM
+gdbscm_value_reference_value (SCM self)
+{
+  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, TYPE_CODE_REF);
+      return vlscm_scm_from_value (res_val);
+    });
+}
+
 /* (value-type <gdb:value>) -> <gdb:type> */
 
 static SCM
@@ -1351,6 +1369,11 @@  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 <gdb:value> object which is a 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/gdb.guile/scm-value.exp b/gdb/testsuite/gdb.guile/scm-value.exp
index 191af1d71a6..83399f32103 100644
--- a/gdb/testsuite/gdb.guile/scm-value.exp
+++ b/gdb/testsuite/gdb.guile/scm-value.exp
@@ -173,6 +173,9 @@  proc test_value_in_inferior {} {
 	"get string beyond null"
     gdb_test "gu (print nullst)" \
 	"= divide\\\\000et"
+
+    gdb_test "gu (equal? argv (value-referenced-value (value-reference-value argv)))" \
+	"#t"
 }
 
 proc test_strings {} {