Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [RFA/DWARF] address size can be different from DW_OP_deref size
Date: Fri, 03 Jun 2011 14:46:00 -0000	[thread overview]
Message-ID: <1307112377-17952-1-git-send-email-brobecker@adacore.com> (raw)

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


             reply	other threads:[~2011-06-03 14:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-03 14:46 Joel Brobecker [this message]
2011-06-03 16:28 ` Tom Tromey
2011-06-03 17:47   ` Joel Brobecker
2011-06-03 18:54     ` Tom Tromey

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=1307112377-17952-1-git-send-email-brobecker@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@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: link
Be 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