Create dwarf2/attribute.[ch]
This moves the attribute-related code out of dwarf2read.c and into the
new files dwarf2/attribute.[ch].
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (struct attribute, DW_STRING)
(DW_STRING_IS_CANONICAL, DW_UNSND, DW_BLOCK, DW_SND, DW_ADDR)
(DW_SIGNATURE, struct dwarf_block, attr_value_as_address)
(attr_form_is_block, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Move.
* dwarf2/attribute.h: New file.
* dwarf2/attribute.c: New file, from dwarf2read.c.
* Makefile.in (COMMON_SFILES): Add dwarf2/attribute.c.
Change-Id: I1ea4c146256a1b9e38b66f1c605d782a14eeded7
2020-02-09 04:40:54 +08:00
|
|
|
/* DWARF attributes
|
|
|
|
|
2021-01-01 16:03:39 +08:00
|
|
|
Copyright (C) 1994-2021 Free Software Foundation, Inc.
|
Create dwarf2/attribute.[ch]
This moves the attribute-related code out of dwarf2read.c and into the
new files dwarf2/attribute.[ch].
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (struct attribute, DW_STRING)
(DW_STRING_IS_CANONICAL, DW_UNSND, DW_BLOCK, DW_SND, DW_ADDR)
(DW_SIGNATURE, struct dwarf_block, attr_value_as_address)
(attr_form_is_block, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Move.
* dwarf2/attribute.h: New file.
* dwarf2/attribute.c: New file, from dwarf2read.c.
* Makefile.in (COMMON_SFILES): Add dwarf2/attribute.c.
Change-Id: I1ea4c146256a1b9e38b66f1c605d782a14eeded7
2020-02-09 04:40:54 +08:00
|
|
|
|
|
|
|
Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
|
|
|
|
Inc. with support from Florida State University (under contract
|
|
|
|
with the Ada Joint Program Office), and Silicon Graphics, Inc.
|
|
|
|
Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
|
|
|
|
based on Fred Fish's (Cygnus Support) implementation of DWARF 1
|
|
|
|
support.
|
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
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/>. */
|
|
|
|
|
|
|
|
#ifndef GDB_DWARF2_ATTRIBUTE_H
|
|
|
|
#define GDB_DWARF2_ATTRIBUTE_H
|
|
|
|
|
|
|
|
#include "dwarf2.h"
|
Change two functions to be methods on struct attribute
This changes dwarf2_get_ref_die_offset and
dwarf2_get_attr_constant_value to be methods on struct attribute.
gdb/ChangeLog
2020-03-26 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (handle_data_member_location, dwarf2_add_field)
(mark_common_block_symbol_computed, read_tag_string_type)
(attr_to_dynamic_prop, read_subrange_type): Update.
(dwarf2_get_ref_die_offset, dwarf2_get_attr_constant_value): Move
to be methods on struct attribute.
(skip_one_die, process_imported_unit_die, read_namespace_alias)
(read_call_site_scope, partial_die_info::read)
(partial_die_info::read, lookup_die_type, follow_die_ref):
Update.
* dwarf2/attribute.c (attribute::get_ref_die_offset): New method,
from dwarf2_get_ref_die_offset.
(attribute::constant_value): New method, from
dwarf2_get_attr_constant_value.
* dwarf2/attribute.h (struct attribute) <get_ref_die_offset>:
Declare method.
<constant_value>: New method.
2020-03-26 23:28:08 +08:00
|
|
|
#include "gdbtypes.h"
|
2020-09-30 08:49:08 +08:00
|
|
|
#include "gdbsupport/gdb_optional.h"
|
Create dwarf2/attribute.[ch]
This moves the attribute-related code out of dwarf2read.c and into the
new files dwarf2/attribute.[ch].
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (struct attribute, DW_STRING)
(DW_STRING_IS_CANONICAL, DW_UNSND, DW_BLOCK, DW_SND, DW_ADDR)
(DW_SIGNATURE, struct dwarf_block, attr_value_as_address)
(attr_form_is_block, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Move.
* dwarf2/attribute.h: New file.
* dwarf2/attribute.c: New file, from dwarf2read.c.
* Makefile.in (COMMON_SFILES): Add dwarf2/attribute.c.
Change-Id: I1ea4c146256a1b9e38b66f1c605d782a14eeded7
2020-02-09 04:40:54 +08:00
|
|
|
|
|
|
|
/* Blocks are a bunch of untyped bytes. */
|
|
|
|
struct dwarf_block
|
|
|
|
{
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
/* Valid only if SIZE is not zero. */
|
|
|
|
const gdb_byte *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Attributes have a name and a value. */
|
|
|
|
struct attribute
|
|
|
|
{
|
Change some attribute functions to be methods
This changes most of the attribute-related functions to be methods.
(attr_form_is_block changed in a subsequent patch.)
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (dwarf2_find_base_address, )
(read_call_site_scope, rust_containing_type)
(dwarf2_get_pc_bounds, dwarf2_record_block_ranges)
(handle_data_member_location, dwarf2_add_member_fn)
(get_alignment, read_structure_type, process_structure_scope)
(mark_common_block_symbol_computed, read_common_block)
(read_tag_string_type, attr_to_dynamic_prop, read_subrange_type)
(partial_die_info::read, read_attribute_value, new_symbol)
(lookup_die_type, dwarf2_get_ref_die_offset)
(dwarf2_get_attr_constant_value, follow_die_ref_or_sig)
(dwarf2_fetch_die_loc_sect_off, get_DW_AT_signature_type)
(dwarf2_symbol_mark_computed): Update.
* dwarf2/attribute.h (struct attribute) <value_as_address,
form_is_section_offset, form_is_constant, form_is_ref>: Declare
methods.
(value_as_address, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Don't declare.
* dwarf2/attribute.c (attribute::value_as_address)
(attribute::form_is_section_offset, attribute::form_is_constant)
(attribute::form_is_ref): Now methods.
Change-Id: I320dad13002c59b848dc86c39d5d7111c8a15bdc
2020-02-09 04:40:54 +08:00
|
|
|
/* Read the given attribute value as an address, taking the
|
|
|
|
attribute's form into account. */
|
2020-09-30 08:49:08 +08:00
|
|
|
CORE_ADDR as_address () const;
|
Change some attribute functions to be methods
This changes most of the attribute-related functions to be methods.
(attr_form_is_block changed in a subsequent patch.)
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (dwarf2_find_base_address, )
(read_call_site_scope, rust_containing_type)
(dwarf2_get_pc_bounds, dwarf2_record_block_ranges)
(handle_data_member_location, dwarf2_add_member_fn)
(get_alignment, read_structure_type, process_structure_scope)
(mark_common_block_symbol_computed, read_common_block)
(read_tag_string_type, attr_to_dynamic_prop, read_subrange_type)
(partial_die_info::read, read_attribute_value, new_symbol)
(lookup_die_type, dwarf2_get_ref_die_offset)
(dwarf2_get_attr_constant_value, follow_die_ref_or_sig)
(dwarf2_fetch_die_loc_sect_off, get_DW_AT_signature_type)
(dwarf2_symbol_mark_computed): Update.
* dwarf2/attribute.h (struct attribute) <value_as_address,
form_is_section_offset, form_is_constant, form_is_ref>: Declare
methods.
(value_as_address, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Don't declare.
* dwarf2/attribute.c (attribute::value_as_address)
(attribute::form_is_section_offset, attribute::form_is_constant)
(attribute::form_is_ref): Now methods.
Change-Id: I320dad13002c59b848dc86c39d5d7111c8a15bdc
2020-02-09 04:40:54 +08:00
|
|
|
|
2020-04-25 05:35:01 +08:00
|
|
|
/* If the attribute has a string form, return the string value;
|
|
|
|
otherwise return NULL. */
|
2020-09-30 08:49:08 +08:00
|
|
|
const char *as_string () const;
|
2020-04-25 05:35:01 +08:00
|
|
|
|
Remove DW_BLOCK
This removes the DW_BLOCK accessor in favor of methods on struct
attribute. The methods, unlike the access, check the form.
Note that DW_FORM_data16 had to be handled by form_is_block, because
in practice that is how we store values of this form.
gdb/ChangeLog
2020-09-29 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (read_call_site_scope)
(handle_data_member_location, dwarf2_add_member_fn)
(mark_common_block_symbol_computed, attr_to_dynamic_prop)
(partial_die_info::read, read_attribute_value)
(var_decode_location, dwarf2_const_value_attr, dump_die_shallow)
(dwarf2_fetch_die_loc_sect_off, dwarf2_fetch_constant_bytes)
(dwarf2_symbol_mark_computed): Update.
* dwarf2/attribute.h (struct attribute) <as_block, set_block>: New
methods.
(DW_BLOCK): Remove.
* dwarf2/attribute.c (attribute::form_is_block): Add
DW_FORM_data16.
2020-09-30 08:49:08 +08:00
|
|
|
/* Return the block value. The attribute must have block form. */
|
|
|
|
dwarf_block *as_block () const
|
|
|
|
{
|
|
|
|
gdb_assert (form_is_block ());
|
|
|
|
return u.blk;
|
|
|
|
}
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Return the signature. The attribute must have signature
|
|
|
|
form. */
|
|
|
|
ULONGEST as_signature () const
|
|
|
|
{
|
|
|
|
gdb_assert (form == DW_FORM_ref_sig8);
|
|
|
|
return u.signature;
|
|
|
|
}
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Return the signed value. The attribute must have the appropriate
|
|
|
|
form. */
|
|
|
|
LONGEST as_signed () const
|
|
|
|
{
|
2021-02-25 06:58:42 +08:00
|
|
|
gdb_assert (form_is_signed ());
|
2020-09-30 08:49:08 +08:00
|
|
|
return u.snd;
|
|
|
|
}
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Return the unsigned value, but only for attributes requiring
|
|
|
|
reprocessing. */
|
|
|
|
ULONGEST as_unsigned_reprocess () const
|
|
|
|
{
|
|
|
|
gdb_assert (form_requires_reprocessing ());
|
|
|
|
gdb_assert (requires_reprocessing);
|
|
|
|
return u.unsnd;
|
|
|
|
}
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Return the unsigned value. Requires that the form be an unsigned
|
|
|
|
form, and that reprocessing not be needed. */
|
|
|
|
ULONGEST as_unsigned () const
|
|
|
|
{
|
|
|
|
gdb_assert (form_is_unsigned ());
|
|
|
|
gdb_assert (!requires_reprocessing);
|
|
|
|
return u.unsnd;
|
|
|
|
}
|
|
|
|
|
2021-02-25 06:58:42 +08:00
|
|
|
/* Return true if the value is nonnegative. Requires that that
|
|
|
|
reprocessing not be needed. */
|
|
|
|
bool is_nonnegative () const
|
|
|
|
{
|
|
|
|
if (form_is_unsigned ())
|
|
|
|
return true;
|
|
|
|
if (form_is_signed ())
|
|
|
|
return as_signed () >= 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the nonnegative value. Requires that that reprocessing not be
|
|
|
|
needed. */
|
|
|
|
ULONGEST as_nonnegative () const
|
|
|
|
{
|
|
|
|
if (form_is_unsigned ())
|
|
|
|
return as_unsigned ();
|
|
|
|
if (form_is_signed ())
|
|
|
|
return (ULONGEST)as_signed ();
|
|
|
|
gdb_assert (false);
|
|
|
|
}
|
|
|
|
|
Change some attribute functions to be methods
This changes most of the attribute-related functions to be methods.
(attr_form_is_block changed in a subsequent patch.)
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (dwarf2_find_base_address, )
(read_call_site_scope, rust_containing_type)
(dwarf2_get_pc_bounds, dwarf2_record_block_ranges)
(handle_data_member_location, dwarf2_add_member_fn)
(get_alignment, read_structure_type, process_structure_scope)
(mark_common_block_symbol_computed, read_common_block)
(read_tag_string_type, attr_to_dynamic_prop, read_subrange_type)
(partial_die_info::read, read_attribute_value, new_symbol)
(lookup_die_type, dwarf2_get_ref_die_offset)
(dwarf2_get_attr_constant_value, follow_die_ref_or_sig)
(dwarf2_fetch_die_loc_sect_off, get_DW_AT_signature_type)
(dwarf2_symbol_mark_computed): Update.
* dwarf2/attribute.h (struct attribute) <value_as_address,
form_is_section_offset, form_is_constant, form_is_ref>: Declare
methods.
(value_as_address, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Don't declare.
* dwarf2/attribute.c (attribute::value_as_address)
(attribute::form_is_section_offset, attribute::form_is_constant)
(attribute::form_is_ref): Now methods.
Change-Id: I320dad13002c59b848dc86c39d5d7111c8a15bdc
2020-02-09 04:40:54 +08:00
|
|
|
/* Return non-zero if ATTR's value is a section offset --- classes
|
|
|
|
lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
|
2020-09-30 08:49:08 +08:00
|
|
|
You may use the as_unsigned method to retrieve such offsets.
|
Change some attribute functions to be methods
This changes most of the attribute-related functions to be methods.
(attr_form_is_block changed in a subsequent patch.)
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (dwarf2_find_base_address, )
(read_call_site_scope, rust_containing_type)
(dwarf2_get_pc_bounds, dwarf2_record_block_ranges)
(handle_data_member_location, dwarf2_add_member_fn)
(get_alignment, read_structure_type, process_structure_scope)
(mark_common_block_symbol_computed, read_common_block)
(read_tag_string_type, attr_to_dynamic_prop, read_subrange_type)
(partial_die_info::read, read_attribute_value, new_symbol)
(lookup_die_type, dwarf2_get_ref_die_offset)
(dwarf2_get_attr_constant_value, follow_die_ref_or_sig)
(dwarf2_fetch_die_loc_sect_off, get_DW_AT_signature_type)
(dwarf2_symbol_mark_computed): Update.
* dwarf2/attribute.h (struct attribute) <value_as_address,
form_is_section_offset, form_is_constant, form_is_ref>: Declare
methods.
(value_as_address, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Don't declare.
* dwarf2/attribute.c (attribute::value_as_address)
(attribute::form_is_section_offset, attribute::form_is_constant)
(attribute::form_is_ref): Now methods.
Change-Id: I320dad13002c59b848dc86c39d5d7111c8a15bdc
2020-02-09 04:40:54 +08:00
|
|
|
|
|
|
|
Section 7.5.4, "Attribute Encodings", explains that no attribute
|
|
|
|
may have a value that belongs to more than one of these classes; it
|
|
|
|
would be ambiguous if we did, because we use the same forms for all
|
|
|
|
of them. */
|
|
|
|
|
|
|
|
bool form_is_section_offset () const;
|
|
|
|
|
|
|
|
/* Return non-zero if ATTR's value falls in the 'constant' class, or
|
|
|
|
zero otherwise. When this function returns true, you can apply
|
2020-03-28 23:25:41 +08:00
|
|
|
the constant_value method to it.
|
Change some attribute functions to be methods
This changes most of the attribute-related functions to be methods.
(attr_form_is_block changed in a subsequent patch.)
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (dwarf2_find_base_address, )
(read_call_site_scope, rust_containing_type)
(dwarf2_get_pc_bounds, dwarf2_record_block_ranges)
(handle_data_member_location, dwarf2_add_member_fn)
(get_alignment, read_structure_type, process_structure_scope)
(mark_common_block_symbol_computed, read_common_block)
(read_tag_string_type, attr_to_dynamic_prop, read_subrange_type)
(partial_die_info::read, read_attribute_value, new_symbol)
(lookup_die_type, dwarf2_get_ref_die_offset)
(dwarf2_get_attr_constant_value, follow_die_ref_or_sig)
(dwarf2_fetch_die_loc_sect_off, get_DW_AT_signature_type)
(dwarf2_symbol_mark_computed): Update.
* dwarf2/attribute.h (struct attribute) <value_as_address,
form_is_section_offset, form_is_constant, form_is_ref>: Declare
methods.
(value_as_address, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Don't declare.
* dwarf2/attribute.c (attribute::value_as_address)
(attribute::form_is_section_offset, attribute::form_is_constant)
(attribute::form_is_ref): Now methods.
Change-Id: I320dad13002c59b848dc86c39d5d7111c8a15bdc
2020-02-09 04:40:54 +08:00
|
|
|
|
|
|
|
However, note that for some attributes you must check
|
|
|
|
attr_form_is_section_offset before using this test. DW_FORM_data4
|
|
|
|
and DW_FORM_data8 are members of both the constant class, and of
|
|
|
|
the classes that contain offsets into other debug sections
|
|
|
|
(lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
|
|
|
|
that, if an attribute's can be either a constant or one of the
|
|
|
|
section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
|
|
|
|
taken as section offsets, not constants.
|
|
|
|
|
2020-03-28 23:25:41 +08:00
|
|
|
DW_FORM_data16 is not considered as constant_value cannot handle
|
|
|
|
that. */
|
Change some attribute functions to be methods
This changes most of the attribute-related functions to be methods.
(attr_form_is_block changed in a subsequent patch.)
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (dwarf2_find_base_address, )
(read_call_site_scope, rust_containing_type)
(dwarf2_get_pc_bounds, dwarf2_record_block_ranges)
(handle_data_member_location, dwarf2_add_member_fn)
(get_alignment, read_structure_type, process_structure_scope)
(mark_common_block_symbol_computed, read_common_block)
(read_tag_string_type, attr_to_dynamic_prop, read_subrange_type)
(partial_die_info::read, read_attribute_value, new_symbol)
(lookup_die_type, dwarf2_get_ref_die_offset)
(dwarf2_get_attr_constant_value, follow_die_ref_or_sig)
(dwarf2_fetch_die_loc_sect_off, get_DW_AT_signature_type)
(dwarf2_symbol_mark_computed): Update.
* dwarf2/attribute.h (struct attribute) <value_as_address,
form_is_section_offset, form_is_constant, form_is_ref>: Declare
methods.
(value_as_address, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Don't declare.
* dwarf2/attribute.c (attribute::value_as_address)
(attribute::form_is_section_offset, attribute::form_is_constant)
(attribute::form_is_ref): Now methods.
Change-Id: I320dad13002c59b848dc86c39d5d7111c8a15bdc
2020-02-09 04:40:54 +08:00
|
|
|
|
|
|
|
bool form_is_constant () const;
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* The address is always stored already as sect_offset; despite for
|
|
|
|
the forms besides DW_FORM_ref_addr it is stored as cu_offset in
|
|
|
|
the DWARF file. */
|
Change some attribute functions to be methods
This changes most of the attribute-related functions to be methods.
(attr_form_is_block changed in a subsequent patch.)
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (dwarf2_find_base_address, )
(read_call_site_scope, rust_containing_type)
(dwarf2_get_pc_bounds, dwarf2_record_block_ranges)
(handle_data_member_location, dwarf2_add_member_fn)
(get_alignment, read_structure_type, process_structure_scope)
(mark_common_block_symbol_computed, read_common_block)
(read_tag_string_type, attr_to_dynamic_prop, read_subrange_type)
(partial_die_info::read, read_attribute_value, new_symbol)
(lookup_die_type, dwarf2_get_ref_die_offset)
(dwarf2_get_attr_constant_value, follow_die_ref_or_sig)
(dwarf2_fetch_die_loc_sect_off, get_DW_AT_signature_type)
(dwarf2_symbol_mark_computed): Update.
* dwarf2/attribute.h (struct attribute) <value_as_address,
form_is_section_offset, form_is_constant, form_is_ref>: Declare
methods.
(value_as_address, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Don't declare.
* dwarf2/attribute.c (attribute::value_as_address)
(attribute::form_is_section_offset, attribute::form_is_constant)
(attribute::form_is_ref): Now methods.
Change-Id: I320dad13002c59b848dc86c39d5d7111c8a15bdc
2020-02-09 04:40:54 +08:00
|
|
|
|
2020-05-28 01:48:18 +08:00
|
|
|
bool form_is_ref () const
|
|
|
|
{
|
|
|
|
return (form == DW_FORM_ref_addr
|
|
|
|
|| form == DW_FORM_ref1
|
|
|
|
|| form == DW_FORM_ref2
|
|
|
|
|| form == DW_FORM_ref4
|
|
|
|
|| form == DW_FORM_ref8
|
|
|
|
|| form == DW_FORM_ref_udata
|
|
|
|
|| form == DW_FORM_GNU_ref_alt);
|
|
|
|
}
|
Change some attribute functions to be methods
This changes most of the attribute-related functions to be methods.
(attr_form_is_block changed in a subsequent patch.)
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (dwarf2_find_base_address, )
(read_call_site_scope, rust_containing_type)
(dwarf2_get_pc_bounds, dwarf2_record_block_ranges)
(handle_data_member_location, dwarf2_add_member_fn)
(get_alignment, read_structure_type, process_structure_scope)
(mark_common_block_symbol_computed, read_common_block)
(read_tag_string_type, attr_to_dynamic_prop, read_subrange_type)
(partial_die_info::read, read_attribute_value, new_symbol)
(lookup_die_type, dwarf2_get_ref_die_offset)
(dwarf2_get_attr_constant_value, follow_die_ref_or_sig)
(dwarf2_fetch_die_loc_sect_off, get_DW_AT_signature_type)
(dwarf2_symbol_mark_computed): Update.
* dwarf2/attribute.h (struct attribute) <value_as_address,
form_is_section_offset, form_is_constant, form_is_ref>: Declare
methods.
(value_as_address, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Don't declare.
* dwarf2/attribute.c (attribute::value_as_address)
(attribute::form_is_section_offset, attribute::form_is_constant)
(attribute::form_is_ref): Now methods.
Change-Id: I320dad13002c59b848dc86c39d5d7111c8a15bdc
2020-02-09 04:40:54 +08:00
|
|
|
|
Change attr_form_is_block to be a method
This changes attr_form_is_block to be a method. This is done
separately because, unlike the other attribute functions,
attr_form_is_block had special handling for the case where the
argument was NULL. This required auditing each call site; in most
cases, NULL was already ruled out, but in a few spots, an additional
check was needed.
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (read_call_site_scope)
(handle_data_member_location, dwarf2_add_member_fn)
(mark_common_block_symbol_computed, read_common_block)
(attr_to_dynamic_prop, partial_die_info::read)
(var_decode_location, dwarf2_fetch_die_loc_sect_off)
(dwarf2_symbol_mark_computed, set_die_type): Update.
* dwarf2/attribute.h (struct attribute) <form_is_block>: Declare
method.
(attr_form_is_block): Don't declare.
* dwarf2/attribute.c (attribute::form_is_block): Now a method.
Change-Id: Idfb290c61d738301ab991666f43e0b9cf577b2ae
2020-02-09 04:40:54 +08:00
|
|
|
/* Check if the attribute's form is a DW_FORM_block*
|
|
|
|
if so return true else false. */
|
|
|
|
|
|
|
|
bool form_is_block () const;
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Check if the attribute's form is a string form. */
|
|
|
|
bool form_is_string () const;
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Check if the attribute's form is an unsigned integer form. */
|
|
|
|
bool form_is_unsigned () const;
|
|
|
|
|
2021-02-25 06:58:42 +08:00
|
|
|
/* Check if the attribute's form is a signed integer form. */
|
|
|
|
bool form_is_signed () const;
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Check if the attribute's form is a form that requires
|
|
|
|
"reprocessing". */
|
|
|
|
bool form_requires_reprocessing () const;
|
|
|
|
|
Change two functions to be methods on struct attribute
This changes dwarf2_get_ref_die_offset and
dwarf2_get_attr_constant_value to be methods on struct attribute.
gdb/ChangeLog
2020-03-26 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (handle_data_member_location, dwarf2_add_field)
(mark_common_block_symbol_computed, read_tag_string_type)
(attr_to_dynamic_prop, read_subrange_type): Update.
(dwarf2_get_ref_die_offset, dwarf2_get_attr_constant_value): Move
to be methods on struct attribute.
(skip_one_die, process_imported_unit_die, read_namespace_alias)
(read_call_site_scope, partial_die_info::read)
(partial_die_info::read, lookup_die_type, follow_die_ref):
Update.
* dwarf2/attribute.c (attribute::get_ref_die_offset): New method,
from dwarf2_get_ref_die_offset.
(attribute::constant_value): New method, from
dwarf2_get_attr_constant_value.
* dwarf2/attribute.h (struct attribute) <get_ref_die_offset>:
Declare method.
<constant_value>: New method.
2020-03-26 23:28:08 +08:00
|
|
|
/* Return DIE offset of this attribute. Return 0 with complaint if
|
|
|
|
the attribute is not of the required kind. */
|
|
|
|
|
2020-05-28 01:48:18 +08:00
|
|
|
sect_offset get_ref_die_offset () const
|
|
|
|
{
|
|
|
|
if (form_is_ref ())
|
|
|
|
return (sect_offset) u.unsnd;
|
|
|
|
get_ref_die_offset_complaint ();
|
|
|
|
return {};
|
|
|
|
}
|
Change two functions to be methods on struct attribute
This changes dwarf2_get_ref_die_offset and
dwarf2_get_attr_constant_value to be methods on struct attribute.
gdb/ChangeLog
2020-03-26 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (handle_data_member_location, dwarf2_add_field)
(mark_common_block_symbol_computed, read_tag_string_type)
(attr_to_dynamic_prop, read_subrange_type): Update.
(dwarf2_get_ref_die_offset, dwarf2_get_attr_constant_value): Move
to be methods on struct attribute.
(skip_one_die, process_imported_unit_die, read_namespace_alias)
(read_call_site_scope, partial_die_info::read)
(partial_die_info::read, lookup_die_type, follow_die_ref):
Update.
* dwarf2/attribute.c (attribute::get_ref_die_offset): New method,
from dwarf2_get_ref_die_offset.
(attribute::constant_value): New method, from
dwarf2_get_attr_constant_value.
* dwarf2/attribute.h (struct attribute) <get_ref_die_offset>:
Declare method.
<constant_value>: New method.
2020-03-26 23:28:08 +08:00
|
|
|
|
|
|
|
/* Return the constant value held by this attribute. Return
|
|
|
|
DEFAULT_VALUE if the value held by the attribute is not
|
|
|
|
constant. */
|
|
|
|
|
|
|
|
LONGEST constant_value (int default_value) const;
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Return true if this attribute holds a canonical string. In some
|
|
|
|
cases, like C++ names, gdb will rewrite the name of a DIE to a
|
|
|
|
canonical form. This makes lookups robust when a name can be
|
|
|
|
spelled different ways (e.g., "signed" or "signed int"). This
|
|
|
|
flag indicates whether the value has been canonicalized. */
|
|
|
|
bool canonical_string_p () const
|
|
|
|
{
|
2020-09-30 08:49:08 +08:00
|
|
|
gdb_assert (form_is_string ());
|
2020-09-30 08:49:08 +08:00
|
|
|
return string_is_canonical;
|
|
|
|
}
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Initialize this attribute to hold a non-canonical string
|
|
|
|
value. */
|
|
|
|
void set_string_noncanonical (const char *str)
|
|
|
|
{
|
|
|
|
gdb_assert (form_is_string ());
|
|
|
|
u.str = str;
|
|
|
|
string_is_canonical = 0;
|
2020-09-30 08:49:08 +08:00
|
|
|
requires_reprocessing = 0;
|
2020-09-30 08:49:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the canonical string value for this attribute. */
|
|
|
|
void set_string_canonical (const char *str)
|
|
|
|
{
|
|
|
|
gdb_assert (form_is_string ());
|
|
|
|
u.str = str;
|
|
|
|
string_is_canonical = 1;
|
|
|
|
}
|
|
|
|
|
Remove DW_BLOCK
This removes the DW_BLOCK accessor in favor of methods on struct
attribute. The methods, unlike the access, check the form.
Note that DW_FORM_data16 had to be handled by form_is_block, because
in practice that is how we store values of this form.
gdb/ChangeLog
2020-09-29 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (read_call_site_scope)
(handle_data_member_location, dwarf2_add_member_fn)
(mark_common_block_symbol_computed, attr_to_dynamic_prop)
(partial_die_info::read, read_attribute_value)
(var_decode_location, dwarf2_const_value_attr, dump_die_shallow)
(dwarf2_fetch_die_loc_sect_off, dwarf2_fetch_constant_bytes)
(dwarf2_symbol_mark_computed): Update.
* dwarf2/attribute.h (struct attribute) <as_block, set_block>: New
methods.
(DW_BLOCK): Remove.
* dwarf2/attribute.c (attribute::form_is_block): Add
DW_FORM_data16.
2020-09-30 08:49:08 +08:00
|
|
|
/* Set the block value for this attribute. */
|
|
|
|
void set_block (dwarf_block *blk)
|
|
|
|
{
|
|
|
|
gdb_assert (form_is_block ());
|
|
|
|
u.blk = blk;
|
|
|
|
}
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Set the signature value for this attribute. */
|
|
|
|
void set_signature (ULONGEST signature)
|
|
|
|
{
|
|
|
|
gdb_assert (form == DW_FORM_ref_sig8);
|
|
|
|
u.signature = signature;
|
|
|
|
}
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Set this attribute to a signed integer. */
|
|
|
|
void set_signed (LONGEST snd)
|
|
|
|
{
|
|
|
|
gdb_assert (form == DW_FORM_sdata || form == DW_FORM_implicit_const);
|
|
|
|
u.snd = snd;
|
|
|
|
}
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Set this attribute to an unsigned integer. */
|
|
|
|
void set_unsigned (ULONGEST unsnd)
|
|
|
|
{
|
|
|
|
gdb_assert (form_is_unsigned ());
|
|
|
|
u.unsnd = unsnd;
|
gdb/dwarf: few fixes for handling DW_FORM_{rng,loc}listx
We hit an assertion when loading the binary from PR 26813. When fixing
it, execution goes a up bit further but then hits another assert, and
another, and another. With these fours fixes, I am able to load the
binary and get to the prompt. An error is shown (index pointing outside
of the section), because the DW_FORM_rnglistx attribute is not read
correctly, but that one is taken care of by the next patch.
The four fixes are:
- attribute::form_requires_reprocessing needs to handle forms
DW_FORM_rnglistx and DW_FORM_loclistx, because set_unsigned_reprocess
is called for them in read_attribute_value.
- read_attribute_reprocess must call set_unsigned for them, not
set_address. The parameter of set_address is a CORE_ADDR, meaning
it's for program addresses. Post-reprocess, DW_FORM_rnglistx and
DW_FORM_loclistx are offsets into their respective sections
(.debug_rnglists and .debug_loclists). set_unsigned is the current
attribute value setter that fits the best. But perhaps we should have
a setter that takes a sect_offset?
- read_attribute_process must call as_unsigned_reprocess instead of
as_unsigned to get the pre-reprocess value, otherwise we hit the
assert inside as_unsigned that makes sure the attribute doesn't need
reprocessing.
- attribute::set_unsigned needs to clear the requires_reprocessing flag,
otherwise it stays set when reprocessing DW_FORM_rnglistx and
DW_FORM_loclistx attributes.
There's another assert that we hit once the next patch is applied, but
since it's in the same vein as the changes in this patch, I included it
in this patch:
- attribute::form_is_unsigned must handle form DW_FORM_loclistx,
otherwise we hit the assert when trying to call set_unsigned for an
attribute of this form. DW_FORM_rnglistx is already handled.
gdb/ChangeLog:
PR gdb/26813
* dwarf2/attribute.h (struct attribute) <set_unsigned>: Clear
requires_reprocessing flag.
* dwarf2/attribute.c (attribute::form_is_unsigned): Handle
DW_FORM_loclistx.
(attribute::form_requires_reprocessing): Handle DW_FORM_rnglistx
and DW_FORM_loclistx.
* dwarf2/read.c (read_attribute_reprocess): Use set_unsigned
instead of set_address for DW_FORM_loclistx and
DW_FORM_rnglistx.
Change-Id: I06c156fa3913ca98e4e39085f4ef171645b4bc1e
2021-02-02 23:40:51 +08:00
|
|
|
requires_reprocessing = 0;
|
2020-09-30 08:49:08 +08:00
|
|
|
}
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Temporarily set this attribute to an unsigned integer. This is
|
|
|
|
used only for those forms that require reprocessing. */
|
|
|
|
void set_unsigned_reprocess (ULONGEST unsnd)
|
|
|
|
{
|
|
|
|
gdb_assert (form_requires_reprocessing ());
|
|
|
|
u.unsnd = unsnd;
|
|
|
|
requires_reprocessing = 1;
|
|
|
|
}
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Set this attribute to an address. */
|
|
|
|
void set_address (CORE_ADDR addr)
|
|
|
|
{
|
|
|
|
gdb_assert (form == DW_FORM_addr
|
|
|
|
|| ((form == DW_FORM_addrx
|
|
|
|
|| form == DW_FORM_GNU_addr_index)
|
|
|
|
&& requires_reprocessing));
|
|
|
|
u.addr = addr;
|
|
|
|
requires_reprocessing = 0;
|
|
|
|
}
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* True if this attribute requires reprocessing. */
|
|
|
|
bool requires_reprocessing_p () const
|
|
|
|
{
|
|
|
|
return requires_reprocessing;
|
|
|
|
}
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Return the value as one of the recognized enum
|
|
|
|
dwarf_defaulted_attribute constants according to DWARF5 spec,
|
|
|
|
Table 7.24. If the value is incorrect, or if this attribute has
|
|
|
|
the wrong form, then a complaint is issued and DW_DEFAULTED_no is
|
|
|
|
returned. */
|
|
|
|
dwarf_defaulted_attribute defaulted () const;
|
2020-09-30 08:49:08 +08:00
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Return the attribute's value as a dwarf_virtuality_attribute
|
|
|
|
constant according to DWARF spec. An unrecognized value will
|
|
|
|
issue a complaint and return DW_VIRTUALITY_none. */
|
|
|
|
dwarf_virtuality_attribute as_virtuality () const;
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Return the attribute's value as a boolean. An unrecognized form
|
|
|
|
will issue a complaint and return false. */
|
|
|
|
bool as_boolean () const;
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
ENUM_BITFIELD(dwarf_attribute) name : 15;
|
|
|
|
|
|
|
|
/* A boolean that is used for forms that require reprocessing. A
|
|
|
|
form may require data not directly available in the attribute.
|
|
|
|
E.g., DW_FORM_strx requires the corresponding
|
|
|
|
DW_AT_str_offsets_base. In this case, the processing for the
|
|
|
|
attribute must be done in two passes. In the first past, this
|
|
|
|
flag is set and the value is an unsigned. In the second pass,
|
|
|
|
the unsigned value is turned into the correct value for the form,
|
|
|
|
and this flag is cleared. This flag is unused for other
|
|
|
|
forms. */
|
|
|
|
unsigned int requires_reprocessing : 1;
|
Change some attribute functions to be methods
This changes most of the attribute-related functions to be methods.
(attr_form_is_block changed in a subsequent patch.)
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (dwarf2_find_base_address, )
(read_call_site_scope, rust_containing_type)
(dwarf2_get_pc_bounds, dwarf2_record_block_ranges)
(handle_data_member_location, dwarf2_add_member_fn)
(get_alignment, read_structure_type, process_structure_scope)
(mark_common_block_symbol_computed, read_common_block)
(read_tag_string_type, attr_to_dynamic_prop, read_subrange_type)
(partial_die_info::read, read_attribute_value, new_symbol)
(lookup_die_type, dwarf2_get_ref_die_offset)
(dwarf2_get_attr_constant_value, follow_die_ref_or_sig)
(dwarf2_fetch_die_loc_sect_off, get_DW_AT_signature_type)
(dwarf2_symbol_mark_computed): Update.
* dwarf2/attribute.h (struct attribute) <value_as_address,
form_is_section_offset, form_is_constant, form_is_ref>: Declare
methods.
(value_as_address, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Don't declare.
* dwarf2/attribute.c (attribute::value_as_address)
(attribute::form_is_section_offset, attribute::form_is_constant)
(attribute::form_is_ref): Now methods.
Change-Id: I320dad13002c59b848dc86c39d5d7111c8a15bdc
2020-02-09 04:40:54 +08:00
|
|
|
|
Create dwarf2/attribute.[ch]
This moves the attribute-related code out of dwarf2read.c and into the
new files dwarf2/attribute.[ch].
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (struct attribute, DW_STRING)
(DW_STRING_IS_CANONICAL, DW_UNSND, DW_BLOCK, DW_SND, DW_ADDR)
(DW_SIGNATURE, struct dwarf_block, attr_value_as_address)
(attr_form_is_block, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Move.
* dwarf2/attribute.h: New file.
* dwarf2/attribute.c: New file, from dwarf2read.c.
* Makefile.in (COMMON_SFILES): Add dwarf2/attribute.c.
Change-Id: I1ea4c146256a1b9e38b66f1c605d782a14eeded7
2020-02-09 04:40:54 +08:00
|
|
|
ENUM_BITFIELD(dwarf_form) form : 15;
|
|
|
|
|
2020-09-30 08:49:08 +08:00
|
|
|
/* Has u.str already been updated by dwarf2_canonicalize_name? This
|
|
|
|
field should be in u.str but it is kept here for better struct
|
|
|
|
attribute alignment. */
|
Create dwarf2/attribute.[ch]
This moves the attribute-related code out of dwarf2read.c and into the
new files dwarf2/attribute.[ch].
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (struct attribute, DW_STRING)
(DW_STRING_IS_CANONICAL, DW_UNSND, DW_BLOCK, DW_SND, DW_ADDR)
(DW_SIGNATURE, struct dwarf_block, attr_value_as_address)
(attr_form_is_block, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Move.
* dwarf2/attribute.h: New file.
* dwarf2/attribute.c: New file, from dwarf2read.c.
* Makefile.in (COMMON_SFILES): Add dwarf2/attribute.c.
Change-Id: I1ea4c146256a1b9e38b66f1c605d782a14eeded7
2020-02-09 04:40:54 +08:00
|
|
|
unsigned int string_is_canonical : 1;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
struct dwarf_block *blk;
|
|
|
|
ULONGEST unsnd;
|
|
|
|
LONGEST snd;
|
|
|
|
CORE_ADDR addr;
|
|
|
|
ULONGEST signature;
|
|
|
|
}
|
|
|
|
u;
|
2020-05-28 01:48:18 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/* Used by get_ref_die_offset to issue a complaint. */
|
|
|
|
|
|
|
|
void get_ref_die_offset_complaint () const;
|
Create dwarf2/attribute.[ch]
This moves the attribute-related code out of dwarf2read.c and into the
new files dwarf2/attribute.[ch].
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2read.c (struct attribute, DW_STRING)
(DW_STRING_IS_CANONICAL, DW_UNSND, DW_BLOCK, DW_SND, DW_ADDR)
(DW_SIGNATURE, struct dwarf_block, attr_value_as_address)
(attr_form_is_block, attr_form_is_section_offset)
(attr_form_is_constant, attr_form_is_ref): Move.
* dwarf2/attribute.h: New file.
* dwarf2/attribute.c: New file, from dwarf2read.c.
* Makefile.in (COMMON_SFILES): Add dwarf2/attribute.c.
Change-Id: I1ea4c146256a1b9e38b66f1c605d782a14eeded7
2020-02-09 04:40:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GDB_DWARF2_ATTRIBUTE_H */
|