[v2,3/3] Guile: add value-const-value

Message ID _&asv9zsvgp0_qu_j4mkgcwrzuu08a1c2&w8n5/tkh5rflya&1&u@mail.bob131.so
State New
Headers show
Series
  • Guile: add value-{reference,const}-value
Related show

Commit Message

Aaron Merey via Gdb-patches April 26, 2021, 7:36 p.m.
The Guile API doesn't currently have an equivalent to the Python API's
gdb.Value.const_value(). This commit adds a procedure with equivalent
semantics to the Guile API.

gdb/ChangeLog:

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

	* guile/scm-value.c (gdbscm_value_const_value): Add
	implementation of value-const-value procedure.
	(value_functions): Add value-const-value procedure.

gdb/doc/ChangeLog:

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

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

gdb/testsuite/ChangeLog:

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

	* gdb.guile/scm-value.exp (test_value_in_inferior): Add test
	for value-const-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

Aaron Merey via Gdb-patches April 27, 2021, 1:57 p.m. | #1
> Date: Tue, 27 Apr 2021 05:36:27 +1000

> From: George Barrett via Gdb-patches <gdb-patches@sourceware.org>

> Cc: George Barrett <bob@bob131.so>

> 

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

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

> semantics to the Guile API.

> 

> gdb/ChangeLog:

> 

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

> 

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

> 	implementation of value-const-value procedure.

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

> 

> gdb/doc/ChangeLog:

> 

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

> 

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

> 	documentation for value-const-value.

> 

> gdb/testsuite/ChangeLog:

> 

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

> 

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

> 	for value-const-value.


Thanks.

> +@deffn {Scheme Procedure} value-const-value value

> +Return a new @code{<gdb:value>} object which is a 'const' version of

                                                     ^^^^^^^
Please use @samp{const} instead.  In general, ASCII quotes are almost
never correct in Texinfo.

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


Can you tell me what is the significance of the brackets <..> here?  I
see it is used elsewhere in the manual, but I'm not sure it isn't a
mistake.

Other than that, the patch for the manual is okay.
Aaron Merey via Gdb-patches April 27, 2021, 3 p.m. | #2
On Tue, Apr 27, 2021 at 04:57:31PM +0300, Eli Zaretskii wrote:
> Please use @samp{const} instead.  In general, ASCII quotes are almost

> never correct in Texinfo.


Sure, thanks for the tip! I'll do a v3 shortly.

> Can you tell me what is the significance of the brackets <..> here?  I

> see it is used elsewhere in the manual, but I'm not sure it isn't a

> mistake.


The convention in Guile is that names of types are enclosed in angle brackets.
The addition of angle brackets to type names is implicit in calls to the smob
registration machinery, so the name of the GDB value type in Guile is
"<gdb:value>" even though GDB asks for the registration for "gdb:value".

Thanks.

Patch

diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi
index 843858ffb31..633a7e2f250 100644
--- a/gdb/doc/guile.texi
+++ b/gdb/doc/guile.texi
@@ -811,6 +811,11 @@  Return a new @code{<gdb:value>} object which is an rvalue reference to
 the value encapsulated by @code{<gdb:value>} object @var{value}.
 @end deffn
 
+@deffn {Scheme Procedure} value-const-value value
+Return a new @code{<gdb:value>} object which is a 'const' version of
+@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 2ab193f044a..fb753aeecf0 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -520,6 +520,24 @@  gdbscm_rvalue_reference_value (SCM self)
   return gdbscm_reference_value (self, TYPE_CODE_RVALUE_REF);
 }
 
+/* (value-const-value <gdb:value>) -> <gdb:value> */
+
+static SCM
+gdbscm_value_const_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 = make_cv_value (1, 0, value);
+      return vlscm_scm_from_value (res_val);
+    });
+}
+
 /* (value-type <gdb:value>) -> <gdb:type> */
 
 static SCM
@@ -1394,6 +1412,11 @@  Return a <gdb:value> object which is a reference to the given value." },
     "\
 Return a <gdb:value> object which is an rvalue reference to the given value." },
 
+  { "value-const-value", 1, 0, 0,
+    as_a_scm_t_subr (gdbscm_value_const_value),
+    "\
+Return a <gdb:value> object which is a 'const' version of 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 883c4bea72e..28b0fd83a9f 100644
--- a/gdb/testsuite/gdb.guile/scm-value.exp
+++ b/gdb/testsuite/gdb.guile/scm-value.exp
@@ -183,6 +183,9 @@  proc test_value_in_inferior {} {
 	"test 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"
+
+    gdb_test "gu (equal? (value-type (value-const-value argv)) (type-const (value-type argv)))" \
+	"#t"
 }
 
 proc test_strings {} {