Re: [PATCH 17/20] Change die_info methods to check the attribute's form

Simon Marchi
2020-03-30T16:02:51Z

On 2020-03-28 3:22 p.m., Tom Tromey wrote:
> This changes two die_info methods to check the form of the attribute
> before using it.
>
> 2020-03-28 Tom Tromey <tom@tromey.com>
>
> * dwarf2/die.h (struct die_info) <addr_base, ranges_base>: Check
> the attribute's form.
> ---
> gdb/ChangeLog | 5 +++++
> gdb/dwarf2/die.h | 14 ++++++++------
> 2 files changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/gdb/dwarf2/die.h b/gdb/dwarf2/die.h
> index 5522ebdf311..37f83a45a50 100644
> --- a/gdb/dwarf2/die.h
> +++ b/gdb/dwarf2/die.h
> @@ -39,11 +39,12 @@ struct die_info
> gdb::optional<ULONGEST> addr_base ()
> {
> for (unsigned i = 0; i < num_attrs; ++i)
> - if (attrs[i].name == DW_AT_addr_base
> - || attrs[i].name == DW_AT_GNU_addr_base)
> + if ((attrs[i].name == DW_AT_addr_base
> + || attrs[i].name == DW_AT_GNU_addr_base)
> + && attrs[i].form_is_unsigned ())
> {
> /* If both exist, just use the first one. */
> - return DW_UNSND (&attrs[i]);
> + return attrs[i].get_unsigned ();
> }
> return gdb::optional<ULONGEST> ();
> }

A bit like in the previous patch, if there is a DW_AT_addr_base, but it's
not of the right form, I think we should emit a warning saying that we ignore
it, instead of just ignoring it silently.

That's probably out of the scope of this patch though, but I'm just noting it.

Simon