This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] gdb.dwarf2: Don't hardcode certain constants in Dwarf::assemble constructs
- From: Kevin Buettner <kevinb at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 4 Nov 2015 15:28:22 -0700
- Subject: Re: [PATCH] gdb.dwarf2: Don't hardcode certain constants in Dwarf::assemble constructs
- Authentication-results: sourceware.org; auth=none
- References: <20151029220954 dot 3964b354 at pinnacle dot lan> <CADPb22T3-UpVh2yX4pUO1wvoExFWq1o5F-fQJNuE_mkr4hUU3g at mail dot gmail dot com>
On Sat, 31 Oct 2015 21:23:21 -0700
Doug Evans <dje@google.com> wrote:
> > @@ -63,15 +64,15 @@ Dwarf::assemble $asm_file {
> > {DW_AT_type :$integer_label}
> > {DW_AT_lower_bound {
> > DW_OP_push_object_address
> > - DW_OP_lit8
> > + DW_OP_const1u [expr {2 * $int_size}]
> > DW_OP_minus
> > - DW_OP_deref_size 4
> > + DW_OP_deref_size $int_size
> > } SPECIAL_expr}
> > {DW_AT_upper_bound {
> > DW_OP_push_object_address
> > DW_OP_lit4
> > DW_OP_minus
> > - DW_OP_deref_size 4
> > + DW_OP_deref_size $int_size
> > } SPECIAL_expr}
> > }
> > }
> >
>
> I don't know array bound support very well, but does the lit4 need to
> change too?
It does. Thanks for catching this.
I missed another crucial change too - for DW_AT_byte_size.
(Both that and the lit4 change didn't get transferred over from my
original patch in a different repository. I thought I had tested it,
but I must not have.)
> Seems odd to have lit8 for lower and lit4 for upper though. Bug?
That surprised me at first too, but I think it's correct. It appears
to me that the bounds occupy two int sized words prior to the start of
the array. The lower bound is first, so we subtract 2*$int_size to
find it. The upper bound is found by subtracting $int_size.
Here's what things look like on msp430 which has 16-bit integers:
(gdb) set lang ada
(gdb) p foo.three_ptr.all
$1 = (1, 2, 3)
(gdb) p foo.three_ptr
$2 = (access foo.array_type) 0x10006 <table_1_data+4>
(gdb) x/6hx 0x10002
0x10002 <table_1_data>: 0x0001 0x0003 0x0001 0x0002 0x0003 0x0006
So...
The first 0x0001 is the lower bound, followed by 0x0003, which is the upper
bound. After that comes the array data, 0x0001, etc.
Here's a new patch:
gdb.dwarf2: Don't hardcode certain constants in Dwarf::assemble constructs
Two tests in gdb.dwarf2, data-loc.exp and dynarr-ptr.exp assume that
sizeof(int) is 4. This patch looks up the integer size and uses this
constant for DW_AT_byte_size, DW_AT_lower_bound, and DW_AT_upper_bound.
I discovered this problem while looking at test results for this
msp430 multilib:
msp430-sim/-msim/-mcpu=msp430x/-mlarge/-mdata-region=either/-mcode-region=either
It fixes the following set of failures:
FAIL: gdb.dwarf2/dynarr-ptr.exp: print foo.three_ptr.all'first
FAIL: gdb.dwarf2/dynarr-ptr.exp: print foo.three_ptr'first
FAIL: gdb.dwarf2/dynarr-ptr.exp: print foo.three_ptr_tdef.all'first
FAIL: gdb.dwarf2/dynarr-ptr.exp: print foo.three_ptr_tdef'first
FAIL: gdb.dwarf2/dynarr-ptr.exp: print foo.five_ptr.all'first
FAIL: gdb.dwarf2/dynarr-ptr.exp: print foo.five_ptr'first
FAIL: gdb.dwarf2/dynarr-ptr.exp: print foo.five_ptr_tdef.all'first
FAIL: gdb.dwarf2/dynarr-ptr.exp: print foo.five_ptr_tdef'first
FAIL: gdb.dwarf2/data-loc.exp: print foo.three
FAIL: gdb.dwarf2/data-loc.exp: print foo.three(1)
FAIL: gdb.dwarf2/data-loc.exp: print foo.three(2)
FAIL: gdb.dwarf2/data-loc.exp: print foo.three(3)
FAIL: gdb.dwarf2/data-loc.exp: print foo.three_tdef
FAIL: gdb.dwarf2/data-loc.exp: print foo.three_tdef(1)
FAIL: gdb.dwarf2/data-loc.exp: print foo.three_tdef(2)
FAIL: gdb.dwarf2/data-loc.exp: print foo.three_tdef(3)
FAIL: gdb.dwarf2/data-loc.exp: print foo.five
FAIL: gdb.dwarf2/data-loc.exp: print foo.five(2)
FAIL: gdb.dwarf2/data-loc.exp: print foo.five(3)
FAIL: gdb.dwarf2/data-loc.exp: print foo.five(4)
FAIL: gdb.dwarf2/data-loc.exp: print foo.five(5)
FAIL: gdb.dwarf2/data-loc.exp: print foo.five(6)
FAIL: gdb.dwarf2/data-loc.exp: print foo.five_tdef
FAIL: gdb.dwarf2/data-loc.exp: print foo.five_tdef(2)
FAIL: gdb.dwarf2/data-loc.exp: print foo.five_tdef(3)
FAIL: gdb.dwarf2/data-loc.exp: print foo.five_tdef(4)
FAIL: gdb.dwarf2/data-loc.exp: print foo.five_tdef(5)
FAIL: gdb.dwarf2/data-loc.exp: print foo.five_tdef(6)
FAIL: gdb.dwarf2/data-loc.exp: print foo__three
FAIL: gdb.dwarf2/data-loc.exp: print foo__three_tdef
FAIL: gdb.dwarf2/data-loc.exp: print foo__five
FAIL: gdb.dwarf2/data-loc.exp: print foo__five_tdef
As I recall, there are still (other) problems with msp430 multilibs
which don't use -mlarge.
gdb/testsuite/ChangeLog:
* gdb.dwarf2/data-loc.exp (Dwarf::assemble): Don't hardcode
value associated with DW_AT_byte_size.
* gdb.dwarf2/dynarr-ptr.exp (Dwarf::assemble): Don't hardcode
constants for DW_AT_byte_size, DW_AT_lower_bound, and
DW_AT_upper_bound.
---
gdb/testsuite/gdb.dwarf2/data-loc.exp | 3 ++-
gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp | 11 ++++++-----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/gdb/testsuite/gdb.dwarf2/data-loc.exp b/gdb/testsuite/gdb.dwarf2/data-loc.exp
index a1fb772..1bc40e9 100644
--- a/gdb/testsuite/gdb.dwarf2/data-loc.exp
+++ b/gdb/testsuite/gdb.dwarf2/data-loc.exp
@@ -43,9 +43,10 @@ Dwarf::assemble $asm_file {
{DW_AT_comp_dir /tmp}
} {
declare_labels integer_label array_label array_ptr_label
+ set int_size [get_sizeof "int" 4]
integer_label: DW_TAG_base_type {
- {DW_AT_byte_size 4 DW_FORM_sdata}
+ {DW_AT_byte_size $int_size DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_signed}
{DW_AT_name integer}
}
diff --git a/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp b/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp
index 0a612fe..47f64c7 100644
--- a/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp
+++ b/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp
@@ -45,9 +45,10 @@ Dwarf::assemble $asm_file {
declare_labels integer_label array_label array_ptr_label \
array_typedef_label
set ptr_size [get_sizeof "void *" 96]
+ set int_size [get_sizeof "int" 4]
integer_label: DW_TAG_base_type {
- {DW_AT_byte_size 4 DW_FORM_sdata}
+ {DW_AT_byte_size $int_size DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_signed}
{DW_AT_name integer}
}
@@ -61,15 +62,15 @@ Dwarf::assemble $asm_file {
{DW_AT_type :$integer_label}
{DW_AT_lower_bound {
DW_OP_push_object_address
- DW_OP_lit8
+ DW_OP_const1u [expr {2 * $int_size}]
DW_OP_minus
- DW_OP_deref_size 4
+ DW_OP_deref_size $int_size
} SPECIAL_expr}
{DW_AT_upper_bound {
DW_OP_push_object_address
- DW_OP_lit4
+ DW_OP_const1u $int_size
DW_OP_minus
- DW_OP_deref_size 4
+ DW_OP_deref_size $int_size
} SPECIAL_expr}
}
}