public inbox for gdb-cvs@sourceware.org help / color / mirror / Atom feed
From: Tom de Vries <vries@sourceware.org> To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/exp] Redo cast handling for indirection Date: Mon, 6 May 2024 12:22:55 +0000 (GMT) [thread overview] Message-ID: <20240506122255.A1D083858D1E@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5edbb6ed920057df4cca423e3fc54f27f7685def commit 5edbb6ed920057df4cca423e3fc54f27f7685def Author: Tom de Vries <tdevries@suse.de> Date: Mon May 6 14:23:25 2024 +0200 [gdb/exp] Redo cast handling for indirection In commit ed8fd0a342f ("[gdb/exp] Fix cast handling for indirection"), I introduced the behaviour that even though we have: ... (gdb) p *a_loc () 'a_loc' has unknown return type; cast the call to its declared return type ... we get: ... (gdb) p (char)*a_loc () $1 = 97 'a' ... In other words, the unknown return type of a_loc is inferred from the cast, effectually evaluating: ... (gdb) p (char)*(char *)a_loc () ... This is convient for the case that errno is defined as: ... #define errno (*__errno_location ()) ... and the return type of __errno_location is unknown but the macro definition is known, such that we can use: ... (gdb) p (int)errno ... instead of ... (gdb) p *(int *)__errno_location () ... However, as Pedro has pointed out in post-commit review [1], this makes it harder to reason about the semantics of an expression. For instance, this: ... (gdb) p (long long)*a_loc ()" ... would be evaluated without debug info as: ... (gdb) p (long long)*(long long *)a_loc ()" ... but with debug info as: ... (gdb) p (long long)*(char *)a_loc ()" ... Fix this by instead simply erroring out for this case: ... (gdb) p (char)*a_loc () 'a_loc' has unknown return type; cast the call to its declared return type ... Tested on x86_64-linux. Approved-By: Pedro Alves <pedro@palves.net> [1] https://sourceware.org/pipermail/gdb-patches/2024-May/208821.html Diff: --- gdb/expop.h | 5 +---- gdb/testsuite/gdb.base/cast-indirection.exp | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/gdb/expop.h b/gdb/expop.h index 1967d9779b7..2d46a9dad6a 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -1513,11 +1513,8 @@ public: struct expression *exp, enum noside noside) override { - struct type *pointer_to_expect_type = (expect_type != nullptr - ? lookup_pointer_type (expect_type) - : nullptr); value *val - = std::get<0> (m_storage)->evaluate (pointer_to_expect_type, exp, noside); + = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); return eval_op_ind (expect_type, exp, noside, val); } diff --git a/gdb/testsuite/gdb.base/cast-indirection.exp b/gdb/testsuite/gdb.base/cast-indirection.exp index d2c6d58e3ca..7b9b5a5d677 100644 --- a/gdb/testsuite/gdb.base/cast-indirection.exp +++ b/gdb/testsuite/gdb.base/cast-indirection.exp @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -# Check that "p (char)*a_loc ()" is handled as "p (char)*(char *)a_loc ()". +# Check that "p (char)*a_loc ()" is handled correctly. standard_testfile @@ -37,4 +37,5 @@ gdb_test "p *(char *)a_loc ()" " = 97 'a'" gdb_test "p (char)*(char *)a_loc ()" " = 97 'a'" # Regression test for PR31693. -gdb_test "p (char)*a_loc ()" " = 97 'a'" +gdb_test "p (char)*a_loc ()" \ + "'a_loc' has unknown return type; cast the call to its declared return type"
reply other threads:[~2024-05-06 12:22 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20240506122255.A1D083858D1E@sourceware.org \ --to=vries@sourceware.org \ --cc=gdb-cvs@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: linkBe 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).