* [RFA/DWARF] address size can be different from DW_OP_deref size
@ 2011-06-03 14:46 Joel Brobecker
2011-06-03 16:28 ` Tom Tromey
0 siblings, 1 reply; 4+ messages in thread
From: Joel Brobecker @ 2011-06-03 14:46 UTC (permalink / raw)
To: gdb-patches; +Cc: Joel Brobecker
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [RFA/DWARF] address size can be different from DW_OP_deref size
2011-06-03 14:46 [RFA/DWARF] address size can be different from DW_OP_deref size Joel Brobecker
@ 2011-06-03 16:28 ` Tom Tromey
2011-06-03 17:47 ` Joel Brobecker
0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2011-06-03 16:28 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:
Joel> * dwarf2expr.c (execute_stack_op) [DW_OP_deref]: Handle
Joel> the case where ADDR_SIZE is different from TYPE_LENGTH (type).
This looks correct to me. I also looked at the typed DWARF extension
and I believe this code is appropriate for that as well.
I think it is suitable for 7.3 as well, FWIW.
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFA/DWARF] address size can be different from DW_OP_deref size
2011-06-03 16:28 ` Tom Tromey
@ 2011-06-03 17:47 ` Joel Brobecker
2011-06-03 18:54 ` Tom Tromey
0 siblings, 1 reply; 4+ messages in thread
From: Joel Brobecker @ 2011-06-03 17:47 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
> >>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:
>
> Joel> * dwarf2expr.c (execute_stack_op) [DW_OP_deref]: Handle
> Joel> the case where ADDR_SIZE is different from TYPE_LENGTH (type).
>
> This looks correct to me. I also looked at the typed DWARF extension
> and I believe this code is appropriate for that as well.
Thanks for the review. I've now checked the patch in.
> I think it is suitable for 7.3 as well, FWIW.
It looks fine on the branch, though. Were you planning on checking in
the typed-dwarf series on the branch as well?
--
Joel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFA/DWARF] address size can be different from DW_OP_deref size
2011-06-03 17:47 ` Joel Brobecker
@ 2011-06-03 18:54 ` Tom Tromey
0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2011-06-03 18:54 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:
Tom> I think it is suitable for 7.3 as well, FWIW.
Joel> It looks fine on the branch, though. Were you planning on checking in
Joel> the typed-dwarf series on the branch as well?
I wasn't going to.
I didn't realize this was a regression, sorry about that.
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-06-03 18:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-03 14:46 [RFA/DWARF] address size can be different from DW_OP_deref size Joel Brobecker
2011-06-03 16:28 ` Tom Tromey
2011-06-03 17:47 ` Joel Brobecker
2011-06-03 18:54 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox