From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13088 invoked by alias); 3 Jun 2011 14:46:39 -0000 Received: (qmail 13062 invoked by uid 22791); 3 Jun 2011 14:46:37 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Jun 2011 14:46:23 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 785342BB316; Fri, 3 Jun 2011 10:46:22 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 5xKHws3THGJg; Fri, 3 Jun 2011 10:46:22 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 466212BB2EB; Fri, 3 Jun 2011 10:46:22 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 9CB8A145615; Fri, 3 Jun 2011 07:46:19 -0700 (PDT) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [RFA/DWARF] address size can be different from DW_OP_deref size Date: Fri, 03 Jun 2011 14:46:00 -0000 Message-Id: <1307112377-17952-1-git-send-email-brobecker@adacore.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-06/txt/msg00052.txt.bz2 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