public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: George Barrett <bob@bob131.so>
To: gdb-patches@sourceware.org
Cc: George Barrett <bob@bob131.so>
Subject: [PATCH v3 3/3] Guile: add value-const-value
Date: Thu, 29 Apr 2021 02:27:49 +1000	[thread overview]
Message-ID: <q4on2w667ekxl9y0d3k2u83fqa9wdd54wfsifzo_ba6p9s/855.8@mail.bob131.so> (raw)
In-Reply-To: <&e1lx8mojs1b03hu3o_asydo0za8-nyh&337akgbzjn.o13/-otj@mail.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-29  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.
	* NEWS (Guile API): Note the addition of the new procedure.

gdb/doc/ChangeLog:

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

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

gdb/testsuite/ChangeLog:

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

	* gdb.guile/scm-value.exp (test_value_in_inferior): Add test
	for value-const-value.
---
 gdb/NEWS                              |  5 +++--
 gdb/doc/guile.texi                    |  5 +++++
 gdb/guile/scm-value.c                 | 23 +++++++++++++++++++++++
 gdb/testsuite/gdb.guile/scm-value.exp |  3 +++
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 0c51f5fceca..9e18aa6cc68 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -192,8 +192,9 @@ QMemTags
      value-referenced-value procedure now handles rvalue reference
      values.
 
-  ** New procedures for obtaining reference values:
-     value-reference-value and rvalue-reference-value.
+  ** New procedures for obtaining value variants:
+     value-reference-value, rvalue-reference-value and
+     value-const-value.
 
 *** Changes in GDB 10
 
diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi
index 18782bb7589..a3ff75979e8 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 @samp{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 {} {
-- 
2.30.2

  parent reply	other threads:[~2021-04-28 16:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28 16:27 [PATCH v3 0/3] Guile: add value-{reference,const}-value George Barrett
2021-04-28 16:27 ` [PATCH v3 1/3] Guile: improved rvalue reference support George Barrett
2021-04-28 16:38   ` Eli Zaretskii
2021-04-28 16:54   ` Andrew Burgess
2021-04-28 16:27 ` [PATCH v3 2/3] Guile: add {r,}value-reference-value George Barrett
2021-04-28 16:40   ` Eli Zaretskii
2021-04-28 16:59   ` Andrew Burgess
2021-04-28 17:11     ` George Barrett
2021-04-28 16:27 ` George Barrett [this message]
2021-04-28 16:39   ` [PATCH v3 3/3] Guile: add value-const-value Eli Zaretskii
2021-04-28 17:00   ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=q4on2w667ekxl9y0d3k2u83fqa9wdd54wfsifzo_ba6p9s/855.8@mail.bob131.so \
    --to=bob@bob131.so \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).