From: Luis Machado <lgustavo@codesourcery.com>
To: Andreas Arnez <arnez@linux.vnet.ibm.com>, <gdb-patches@sourceware.org>
Subject: Re: [PATCH 1/3] Fix PR12616 - gdb does not implement DW_AT_data_bit_offset
Date: Mon, 14 Nov 2016 15:38:00 -0000 [thread overview]
Message-ID: <21f0d548-0b8c-d0b8-657e-caaeea793ad9@codesourcery.com> (raw)
In-Reply-To: <1479135786-31150-2-git-send-email-arnez@linux.vnet.ibm.com>
On 11/14/2016 09:02 AM, Andreas Arnez wrote:
> The DW_AT_data_bit_offset attribute was introduced by DWARF V4 and
> allows specifying the offset of a data member within its containing
> entity. But although the new attribute was intended to replace
> DW_AT_bit_offset for this purpose, GDB ignores it, and thus GCC still
> emits DW_AT_bit_offset instead. See also
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71669.
>
> This change fixes GDB's lack of support for DW_AT_data_bit_offset and
> adds an appropriate test case.
>
> gdb/ChangeLog:
>
> PR gdb/12616
> * dwarf2read.c (dwarf2_add_field): Handle the DWARF V4 attribute
> DW_AT_data_bit_offset.
>
> gdb/testsuite/ChangeLog:
>
> PR gdb/12616
> * gdb.dwarf2/nonvar-access.exp: New testcase. Check that GDB
> respects the DW_AT_data_bit_offset attribute.
> ---
> gdb/dwarf2read.c | 4 ++
> gdb/testsuite/gdb.dwarf2/nonvar-access.exp | 103 +++++++++++++++++++++++++++++
> 2 files changed, 107 insertions(+)
> create mode 100644 gdb/testsuite/gdb.dwarf2/nonvar-access.exp
>
> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
> index 1ad6b00..558159a 100644
> --- a/gdb/dwarf2read.c
> +++ b/gdb/dwarf2read.c
> @@ -12584,6 +12584,10 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
> - bit_offset - FIELD_BITSIZE (*fp)));
> }
> }
> + attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
> + if (attr != NULL)
> + SET_FIELD_BITPOS (*fp, (FIELD_BITPOS (*fp)
> + + dwarf2_get_attr_constant_value (attr, 0)));
>
> /* Get name of field. */
> fieldname = dwarf2_name (die, cu);
> diff --git a/gdb/testsuite/gdb.dwarf2/nonvar-access.exp b/gdb/testsuite/gdb.dwarf2/nonvar-access.exp
> new file mode 100644
> index 0000000..21532a6
> --- /dev/null
> +++ b/gdb/testsuite/gdb.dwarf2/nonvar-access.exp
> @@ -0,0 +1,103 @@
> +# Copyright 2016 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# Test accessing "non-variable" variables, i.e., variables which are
> +# optimized to a constant DWARF location expression and/or
> +# partially/fully optimized out.
> +
> +load_lib dwarf.exp
> +
> +if {![dwarf2_support]} { return 0 }
> +
> +standard_testfile main.c nonvar-access-dw.S
> +
> +# Make some DWARF for the test.
> +set asm_file [standard_output_file $srcfile2]
> +
> +Dwarf::assemble $asm_file {
> + cu {} {
> + compile_unit {
> + {DW_AT_name main.c}
> + } {
> + declare_labels int_type_label short_type_label
> + declare_labels struct_s_label
> +
> + int_type_label: base_type {
> + {name "int"}
> + {encoding @DW_ATE_signed}
> + {byte_size 4 DW_FORM_sdata}
> + }
> +
> + struct_s_label: structure_type {
> + {name s}
> + {byte_size 4 DW_FORM_sdata}
> + } {
> + member {
> + {name a}
> + {type :$int_type_label}
> + {data_member_location 0 DW_FORM_udata}
> + {bit_size 8 DW_FORM_udata}
> + }
> + member {
> + {name b}
> + {type :$int_type_label}
> + {data_bit_offset 8 DW_FORM_udata}
> + {bit_size 24 DW_FORM_udata}
> + }
> + }
> +
> + DW_TAG_subprogram {
> + {name main}
> + {DW_AT_external 1 flag}
> + {low_pc [gdb_target_symbol main] DW_FORM_addr}
> + {high_pc [gdb_target_symbol main]+0x10000 DW_FORM_addr}
> + } {
> + DW_TAG_variable {
> + {name undef_int}
> + {type :$int_type_label}
> + }
> + DW_TAG_variable {
> + {name undef_s}
> + {type :$struct_s_label}
> + }
> + DW_TAG_variable {
> + {name def_s}
> + {type :$struct_s_label}
> + {location {
> + const1u 0
> + stack_value
> + bit_piece 8 0
> + const1s -1
> + stack_value
> + bit_piece 24 0
> + } SPECIAL_expr}
> + }
> + }
> + }
> + }
> +}
> +
> +if { [prepare_for_testing ${testfile}.exp ${testfile} \
> + [list $srcfile $asm_file] {nodebug}] } {
> + return -1
> +}
> +
> +if ![runto_main] {
> + return -1
> +}
> +
> +gdb_test "print def_s" " = \\{a = 0, b = -1\\}"
> +gdb_test "print undef_int" " = <optimized out>"
> +gdb_test "print undef_s.a" " = <optimized out>"
>
Looks good to me.
next prev parent reply other threads:[~2016-11-14 15:38 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-14 15:03 [PATCH 0/3] Support DW_AT_data_bit_offset Andreas Arnez
2016-11-14 15:04 ` [PATCH 1/3] Fix PR12616 - gdb does not implement DW_AT_data_bit_offset Andreas Arnez
2016-11-14 15:38 ` Luis Machado [this message]
2016-11-14 15:04 ` [PATCH 2/3] Fix copy_bitwise() Andreas Arnez
2016-11-14 15:38 ` Luis Machado
2016-11-14 17:54 ` Andreas Arnez
2016-11-14 17:58 ` Luis Machado
2016-11-15 18:58 ` Andreas Arnez
2016-11-15 19:42 ` Pedro Alves
2016-11-17 19:36 ` Andreas Arnez
2016-11-17 20:30 ` Pedro Alves
2016-11-18 15:06 ` Andreas Arnez
2016-11-22 23:18 ` Pedro Alves
2016-11-24 16:15 ` Andreas Arnez
2016-11-24 16:32 ` Pedro Alves
2016-11-24 16:55 ` Andreas Arnez
2016-11-14 15:05 ` [PATCH 3/3] Optimize byte-aligned copies in copy_bitwise() Andreas Arnez
2016-11-14 15:38 ` Luis Machado
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=21f0d548-0b8c-d0b8-657e-caaeea793ad9@codesourcery.com \
--to=lgustavo@codesourcery.com \
--cc=arnez@linux.vnet.ibm.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