aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-02-08 13:40:54 -0700
committerTom Tromey <tom@tromey.com>2020-02-08 13:40:55 -0700
commit96b792931fe4dd30f42eecd711ad5e44b6b135a3 (patch)
treeefd2622f44db1359e92b6e18209b073b095059c7 /gdb/dwarf2
parent2c86cff96f47cdc7fe16e231f29566b3da2f756b (diff)
downloadbinutils-96b792931fe4dd30f42eecd711ad5e44b6b135a3.zip
binutils-96b792931fe4dd30f42eecd711ad5e44b6b135a3.tar.gz
binutils-96b792931fe4dd30f42eecd711ad5e44b6b135a3.tar.bz2
Change section functions to be methods of dwarf2_section_info
This changes various section-related functions to be methods on dwarf2_section_info. I think this clarifies the role of these functions. This also changes one such function to return bool. gdb/ChangeLog 2020-02-08 Tom Tromey <tom@tromey.com> * dwarf2read.c (dwarf2_section_buffer_overflow_complaint) (dwarf2_section_size, dwarf2_get_section_info) (create_signatured_type_table_from_debug_names) (create_addrmap_from_aranges, read_debug_names_from_section) (get_gdb_index_contents_from_section, read_comp_unit_head) (error_check_comp_unit_head, read_abbrev_offset) (create_debug_type_hash_table, init_cu_die_reader) (read_cutu_die_from_dwo, dwarf2_build_psymtabs_hard) (read_comp_units_from_section, create_cus_hash_table) (create_dwp_hash_table, create_dwo_unit_in_dwp_v1) (create_dwp_v2_section, dwarf2_rnglists_process) (dwarf2_ranges_process, read_die_and_siblings, read_full_die) (abbrev_table_read_table, read_indirect_string_at_offset_from) (read_indirect_string_from_dwz, read_addr_index_1) (read_str_index, dwarf_decode_line_header, skip_form_bytes) (dwarf_decode_macro_bytes, dwarf_decode_macros) (fill_in_loclist_baton): Update. * dwarf2/section.h (struct dwarf2_section_info) <get_name, get_containing_section, get_bfd_owner, get_bfd_section, get_file_name, get_id, get_flags, empty, read>: Declare methods. (dwarf2_read_section, get_section_name, get_section_file_name) (get_containing_section, get_section_bfd_owner) (get_section_bfd_section, get_section_name, get_section_file_name) (get_section_id, get_section_flags, dwarf2_section_empty_p): Don't declare. * dwarf2/section.c (dwarf2_section_info::get_containing_section) (dwarf2_section_info::get_bfd_owner) (dwarf2_section_info::get_bfd_section) (dwarf2_section_info::get_name) (dwarf2_section_info::get_file_name, dwarf2_section_info::get_id) (dwarf2_section_info::get_flags, dwarf2_section_info::empty) (dwarf2_section_info::read): Now methods. * dwarf-index-write.c (class debug_names): Update. Change-Id: Ic849f182f57a18bad6b1c7c3b9368005d307758a
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r--gdb/dwarf2/section.c81
-rw-r--r--gdb/dwarf2/section.h87
2 files changed, 77 insertions, 91 deletions
diff --git a/gdb/dwarf2/section.c b/gdb/dwarf2/section.c
index 618ab9a..5e33809 100644
--- a/gdb/dwarf2/section.c
+++ b/gdb/dwarf2/section.c
@@ -30,55 +30,57 @@
#include "objfiles.h"
struct dwarf2_section_info *
-get_containing_section (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_containing_section () const
{
- gdb_assert (section->is_virtual);
- return section->s.containing_section;
+ gdb_assert (is_virtual);
+ return s.containing_section;
}
struct bfd *
-get_section_bfd_owner (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_bfd_owner () const
{
- if (section->is_virtual)
+ const dwarf2_section_info *section = this;
+ if (is_virtual)
{
- section = get_containing_section (section);
+ section = get_containing_section ();
gdb_assert (!section->is_virtual);
}
return section->s.section->owner;
}
asection *
-get_section_bfd_section (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_bfd_section () const
{
+ const dwarf2_section_info *section = this;
if (section->is_virtual)
{
- section = get_containing_section (section);
+ section = get_containing_section ();
gdb_assert (!section->is_virtual);
}
return section->s.section;
}
const char *
-get_section_name (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_name () const
{
- asection *sectp = get_section_bfd_section (section);
+ asection *sectp = get_bfd_section ();
gdb_assert (sectp != NULL);
return bfd_section_name (sectp);
}
const char *
-get_section_file_name (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_file_name () const
{
- bfd *abfd = get_section_bfd_owner (section);
+ bfd *abfd = get_bfd_owner ();
return bfd_get_filename (abfd);
}
int
-get_section_id (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_id () const
{
- asection *sectp = get_section_bfd_section (section);
+ asection *sectp = get_bfd_section ();
if (sectp == NULL)
return 0;
@@ -86,61 +88,60 @@ get_section_id (const struct dwarf2_section_info *section)
}
int
-get_section_flags (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_flags () const
{
- asection *sectp = get_section_bfd_section (section);
+ asection *sectp = get_bfd_section ();
gdb_assert (sectp != NULL);
return bfd_section_flags (sectp);
}
-int
-dwarf2_section_empty_p (const struct dwarf2_section_info *section)
+bool
+dwarf2_section_info::empty () const
{
- if (section->is_virtual)
- return section->size == 0;
- return section->s.section == NULL || section->size == 0;
+ if (is_virtual)
+ return size == 0;
+ return s.section == NULL || size == 0;
}
void
-dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info)
+dwarf2_section_info::read (struct objfile *objfile)
{
asection *sectp;
bfd *abfd;
gdb_byte *buf, *retbuf;
- if (info->readin)
+ if (readin)
return;
- info->buffer = NULL;
- info->readin = true;
+ buffer = NULL;
+ readin = true;
- if (dwarf2_section_empty_p (info))
+ if (empty ())
return;
- sectp = get_section_bfd_section (info);
+ sectp = get_bfd_section ();
/* If this is a virtual section we need to read in the real one first. */
- if (info->is_virtual)
+ if (is_virtual)
{
struct dwarf2_section_info *containing_section =
- get_containing_section (info);
+ get_containing_section ();
gdb_assert (sectp != NULL);
if ((sectp->flags & SEC_RELOC) != 0)
{
error (_("Dwarf Error: DWP format V2 with relocations is not"
" supported in section %s [in module %s]"),
- get_section_name (info), get_section_file_name (info));
+ get_name (), get_file_name ());
}
- dwarf2_read_section (objfile, containing_section);
+ containing_section->read (objfile);
/* Other code should have already caught virtual sections that don't
fit. */
- gdb_assert (info->virtual_offset + info->size
- <= containing_section->size);
+ gdb_assert (virtual_offset + size <= containing_section->size);
/* If the real section is empty or there was a problem reading the
section we shouldn't get here. */
gdb_assert (containing_section->buffer != NULL);
- info->buffer = containing_section->buffer + info->virtual_offset;
+ buffer = containing_section->buffer + virtual_offset;
return;
}
@@ -148,12 +149,12 @@ dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info)
Otherwise we attach it to the BFD. */
if ((sectp->flags & SEC_RELOC) == 0)
{
- info->buffer = gdb_bfd_map_section (sectp, &info->size);
+ buffer = gdb_bfd_map_section (sectp, &size);
return;
}
- buf = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, info->size);
- info->buffer = buf;
+ buf = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, size);
+ buffer = buf;
/* When debugging .o files, we may need to apply relocations; see
http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
@@ -162,15 +163,15 @@ dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info)
retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
if (retbuf != NULL)
{
- info->buffer = retbuf;
+ buffer = retbuf;
return;
}
- abfd = get_section_bfd_owner (info);
+ abfd = get_bfd_owner ();
gdb_assert (abfd != NULL);
if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
- || bfd_bread (buf, info->size, abfd) != info->size)
+ || bfd_bread (buf, size, abfd) != size)
{
error (_("Dwarf Error: Can't read DWARF data"
" in section %s [in module %s]"),
diff --git a/gdb/dwarf2/section.h b/gdb/dwarf2/section.h
index a1acc5f..f76f1ef 100644
--- a/gdb/dwarf2/section.h
+++ b/gdb/dwarf2/section.h
@@ -45,6 +45,42 @@
struct dwarf2_section_info
{
+ /* Return the name of this section. */
+ const char *get_name () const;
+
+ /* Return the containing section of this section, which must be a
+ virtual section. */
+ struct dwarf2_section_info *get_containing_section () const;
+
+ /* Return the bfd owner of this section. */
+ struct bfd *get_bfd_owner () const;
+
+ /* Return the bfd section of this section.
+ Returns NULL if the section is not present. */
+ asection *get_bfd_section () const;
+
+ /* Return the name of the file this section is in. */
+ const char *get_file_name () const;
+
+ /* Return the id of this section.
+ Returns 0 if this section doesn't exist. */
+ int get_id () const;
+
+ /* Return the flags of this section. This section (or containing
+ section if this is a virtual section) must exist. */
+ int get_flags () const;
+
+ /* Return true if this section does not exist or if it has no
+ contents. */
+ bool empty () const;
+
+ /* Read the contents of this section.
+ OBJFILE is the main object file, but not necessarily the file where
+ the section comes from. E.g., for DWO files the bfd of INFO is the bfd
+ of the DWO file.
+ If the section is compressed, uncompress it before returning. */
+ void read (struct objfile *objfile);
+
union
{
/* If this is a real section, the bfd section. */
@@ -67,55 +103,4 @@ struct dwarf2_section_info
bool is_virtual;
};
-/* Read the contents of the section INFO.
- OBJFILE is the main object file, but not necessarily the file where
- the section comes from. E.g., for DWO files the bfd of INFO is the bfd
- of the DWO file.
- If the section is compressed, uncompress it before returning. */
-
-extern void dwarf2_read_section (struct objfile *objfile,
- dwarf2_section_info *info);
-
-extern const char *get_section_name (const struct dwarf2_section_info *);
-
-extern const char *get_section_file_name (const struct dwarf2_section_info *);
-
-/* Return the containing section of virtual section SECTION. */
-
-extern struct dwarf2_section_info *get_containing_section
- (const struct dwarf2_section_info *section);
-
-/* Return the bfd owner of SECTION. */
-
-extern struct bfd *get_section_bfd_owner
- (const struct dwarf2_section_info *section);
-
-/* Return the bfd section of SECTION.
- Returns NULL if the section is not present. */
-
-extern asection *get_section_bfd_section
- (const struct dwarf2_section_info *section);
-
-/* Return the name of SECTION. */
-
-extern const char *get_section_name
- (const struct dwarf2_section_info *section);
-
-/* Return the name of the file SECTION is in. */
-
-extern const char *get_section_file_name
- (const struct dwarf2_section_info *section);
-
-/* Return the id of SECTION.
- Returns 0 if SECTION doesn't exist. */
-
-extern int get_section_id (const struct dwarf2_section_info *section);
-
-/* Return the flags of SECTION.
- SECTION (or containing section if this is a virtual section) must exist. */
-
-extern int get_section_flags (const struct dwarf2_section_info *section);
-
-extern int dwarf2_section_empty_p (const struct dwarf2_section_info *section);
-
#endif /* GDB_DWARF2_SECTION_H */