This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Use target address size for DW_OP_deref in dwarf2expr.c


For DW_OP_deref, the DWARF standard states: "The size of the data
retrieved from the dereferenced address is the size of an address on
the target machine."  However, gdb always dereferenced as much as the
DWARF address size instead.

On (some/all) 64-bit big-endian systems this mismatch led to failures
with dw2-ifort-parameter.exp, where the DWARF address size is manually
set to 4 bytes.  DW_OP_deref only dereferenced the four higher-order
bytes of the 64-bit pointer 'ptr', and the result (typically zero) was
then used as a location of the formal parameter 'param'.

See also https://sourceware.org/ml/gdb-patches/2014-01/msg00757.html

gdb/
	* dwarf2expr.c (execute_stack_op): For DW_OP_deref, use the
	architecture's address size instead of the DWARF address size.
---
 gdb/dwarf2expr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
index 36c9f66..6c1c25f 100644
--- a/gdb/dwarf2expr.c
+++ b/gdb/dwarf2expr.c
@@ -1026,7 +1026,10 @@ execute_stack_op (struct dwarf_expr_context *ctx,
 	case DW_OP_deref_size:
 	case DW_OP_GNU_deref_type:
 	  {
-	    int addr_size = (op == DW_OP_deref ? ctx->addr_size : *op_ptr++);
+	    int addr_size =
+	      (op == DW_OP_deref
+	       ? (gdbarch_addr_bit (ctx->gdbarch) + 7) / 8
+	       : *op_ptr++);
 	    gdb_byte *buf = alloca (addr_size);
 	    CORE_ADDR addr = dwarf_expr_fetch_address (ctx, 0);
 	    struct type *type;
-- 
1.8.4.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]