From 5edbb6ed920057df4cca423e3fc54f27f7685def Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Mon, 6 May 2024 14:23:25 +0200 Subject: [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 [1] https://sourceware.org/pipermail/gdb-patches/2024-May/208821.html --- gdb/expop.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'gdb/expop.h') diff --git a/gdb/expop.h b/gdb/expop.h index 1967d97..2d46a9d 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); } -- cgit v1.1