public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 4/9] Introduce value_at_non_lval
Date: Fri,  7 Oct 2022 12:01:15 -0600	[thread overview]
Message-ID: <20221007180120.1866772-5-tromey@adacore.com> (raw)
In-Reply-To: <20221007180120.1866772-1-tromey@adacore.com>

In some cases, while a value might be read from memory, gdb should not
record the value as being equivalent to that memory.

In Ada, the inferior call code will call ada_convert_actual -- and
here, if the argument is already in memory, that address will simply
be reused.  However, for a call like "f(g())", the result of "g" might
be on the stack and thus overwritten by the call to "f".

This patch introduces a new function that is like value_at but that
ensures that the result is non-lvalue.
---
 gdb/valops.c | 10 ++++++++++
 gdb/value.h  |  4 ++++
 2 files changed, 14 insertions(+)

diff --git a/gdb/valops.c b/gdb/valops.c
index de8a68888e4..be4ce025c89 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1018,6 +1018,16 @@ value_at (struct type *type, CORE_ADDR addr)
   return get_value_at (type, addr, 0);
 }
 
+/* See value.h.  */
+
+struct value *
+value_at_non_lval (struct type *type, CORE_ADDR addr)
+{
+  struct value *result = value_at (type, addr);
+  VALUE_LVAL (result) = not_lval;
+  return result;
+}
+
 /* Return a lazy value with type TYPE located at ADDR (cf. value_at).
    The type of the created value may differ from the passed type TYPE.
    Make sure to retrieve the returned values's new type after this call
diff --git a/gdb/value.h b/gdb/value.h
index 52752df1f4c..86e06a54d7d 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -690,6 +690,10 @@ extern struct value *value_from_component (struct value *, struct type *,
 extern struct value *value_at (struct type *type, CORE_ADDR addr);
 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
 
+/* Like value_at, but ensures that the result is marked not_lval.
+   This can be important if the memory is "volatile".  */
+extern struct value *value_at_non_lval (struct type *type, CORE_ADDR addr);
+
 extern struct value *value_from_contents_and_address_unresolved
      (struct type *, const gdb_byte *, CORE_ADDR);
 extern struct value *value_from_contents_and_address (struct type *,
-- 
2.34.3


  parent reply	other threads:[~2022-10-07 18:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-07 18:01 [PATCH 0/9] Fix "finish" with variably-sized types Tom Tromey
2022-10-07 18:01 ` [PATCH 1/9] Fix crash in amd64-tdep.c Tom Tromey
2022-10-07 18:01 ` [PATCH 2/9] Add new overload of gdbarch_return_value Tom Tromey
2022-10-07 18:01 ` [PATCH 3/9] Don't emit gdbarch_return_value Tom Tromey
2022-10-07 18:01 ` Tom Tromey [this message]
2022-10-07 18:01 ` [PATCH 5/9] Don't let property evaluation affect the current language Tom Tromey
2022-10-07 18:01 ` [PATCH 6/9] Convert selected architectures to gdbarch_return_value_as_value Tom Tromey
2022-10-07 18:01 ` [PATCH 7/9] Fix inferior calls with variably-sized return type Tom Tromey
2022-10-07 18:01 ` [PATCH 8/9] Use value_at_non_lval in get_call_return_value Tom Tromey
2022-10-07 18:01 ` [PATCH 9/9] Add test case for "finish" with variably-sized types Tom Tromey
2023-01-03 16:44 ` [PATCH 0/9] Fix " Tom Tromey

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=20221007180120.1866772-5-tromey@adacore.com \
    --to=tromey@adacore.com \
    --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).