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]

[RFA/DWARF] address size can be different from DW_OP_deref size


This is a problem that showed up on AVR when trying to print a local
variable (a string).  The debugger was printing the wrong value.
The variable has a DWARF location list that looks like this:

        .byte   0x4      ;  DW_AT_location
        .byte   0x8c     ;  DW_OP_breg28
        .sleb128 11
        .byte   0x94     ;  DW_OP_deref_size
        .byte   0x2

The problem happens during the execution of the DW_OP_deref_size
operation, because it is 2 bytes long, while the address size
is 4 bytes.  As a result, we try to use a 2-bytes buffer as
the source of a 4-byte type:

    int addr_size = (op == DW_OP_deref ? ctx->addr_size : *op_ptr++);
    gdb_byte *buf = alloca (addr_size);
    [...]
    (ctx->read_mem) (ctx->baton, buf, addr, addr_size);
    result_val = value_from_contents_and_address (type, buf, addr);

The solution is to create a new buffer with the correct size and
containing the same value, zero-extended.

gdb/ChangeLog:

        * dwarf2expr.c (execute_stack_op) [DW_OP_deref]: Handle
        the case where ADDR_SIZE is different from TYPE_LENGTH (type).

Tested on x86-linux. No regression. Also tested on x86-linux and
AVR with AdaCore's testsuite.

---
 gdb/dwarf2expr.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
index 5cd33a6..d5ae588 100644
--- a/gdb/dwarf2expr.c
+++ b/gdb/dwarf2expr.c
@@ -855,6 +855,19 @@ execute_stack_op (struct dwarf_expr_context *ctx,
 	      type = address_type;
 
 	    (ctx->read_mem) (ctx->baton, buf, addr, addr_size);
+
+	    /* If the size of the object read from memory is different
+	       from the type length, we need to zero-extend it.  */
+	    if (TYPE_LENGTH (type) != addr_size)
+	      {
+		ULONGEST result =
+		  extract_unsigned_integer (buf, addr_size, byte_order);
+
+		buf = alloca (TYPE_LENGTH (type));
+		store_unsigned_integer (buf, TYPE_LENGTH (type),
+					byte_order, result);
+	      }
+
 	    result_val = value_from_contents_and_address (type, buf, addr);
 	    break;
 	  }
-- 
1.7.1


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