aboutsummaryrefslogtreecommitdiff
path: root/gdb/objfiles.h
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-06-28 15:28:26 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-06-28 15:28:26 -0400
commit0c1bcd23274e9f465dc43eda4fc467150631f824 (patch)
treea7ebad33d064631f80c6b016da5cb3e2df3eedae /gdb/objfiles.h
parentf07fad95a949b070e51a18276b8f1e03cf86490f (diff)
downloadgdb-0c1bcd23274e9f465dc43eda4fc467150631f824.zip
gdb-0c1bcd23274e9f465dc43eda4fc467150631f824.tar.gz
gdb-0c1bcd23274e9f465dc43eda4fc467150631f824.tar.bz2
gdb: convert obj_section macros to methods
Convert these three macros to methods of obj_section. The problem fixed by the following patch is caused by an out of bound access of the objfile::section_offsets vector. Since this is deep in macros, we don't get a clear backtrace and it's difficult to debug. Changing that to methods means we can step in them and break on them. Because their implementation requires knowing about struct objfile, move struct obj_section below struct objfile in objfiles.h. The obj_section_offset was used in one place as an lvalue to set offsets, in machoread.c. Replace that with a set_offset method. Add the objfile::section_offset and objfile::set_section_offset methods to improve encapsulation (reduce other objects poking into struct objfile's internals). gdb/ChangeLog: * objfiles.h (struct obj_section): Move down. <offset, set_offset, addr, endaddr>: New. (obj_section_offset, obj_section_addr, obj_section_endaddr), replace all users to use obj_section methods. (struct objfile) <section_offset, set_section_offset>: New. Change-Id: I97e8fcae93ab2353fbdadcb4a5ec10d7949a7334
Diffstat (limited to 'gdb/objfiles.h')
-rw-r--r--gdb/objfiles.h93
1 files changed, 62 insertions, 31 deletions
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index f947d69..766c4b4 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -127,37 +127,6 @@ struct entry_info
unsigned initialized : 1;
};
-/* Sections in an objfile. The section offsets are stored in the
- OBJFILE. */
-
-struct obj_section
-{
- /* BFD section pointer */
- struct bfd_section *the_bfd_section;
-
- /* Objfile this section is part of. */
- struct objfile *objfile;
-
- /* True if this "overlay section" is mapped into an "overlay region". */
- int ovly_mapped;
-};
-
-/* Relocation offset applied to S. */
-#define obj_section_offset(s) \
- (((s)->objfile->section_offsets)[gdb_bfd_section_index ((s)->objfile->obfd, (s)->the_bfd_section)])
-
-/* The memory address of section S (vma + offset). */
-#define obj_section_addr(s) \
- (bfd_section_vma (s->the_bfd_section) \
- + obj_section_offset (s))
-
-/* The one-passed-the-end memory address of section S
- (vma + size + offset). */
-#define obj_section_endaddr(s) \
- (bfd_section_vma (s->the_bfd_section) \
- + bfd_section_size ((s)->the_bfd_section) \
- + obj_section_offset (s))
-
#define ALL_OBJFILE_OSECTIONS(objfile, osect) \
for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
if (osect->the_bfd_section == NULL) \
@@ -664,6 +633,27 @@ public:
/* See quick_symbol_functions. */
void require_partial_symbols (bool verbose);
+ /* Return the relocation offset applied to SECTION. */
+ CORE_ADDR section_offset (bfd_section *section) const
+ {
+ /* The section's owner can be nullptr if it is one of the _bfd_std_section
+ section. */
+ gdb_assert (section->owner == nullptr || section->owner == this->obfd);
+
+ int idx = gdb_bfd_section_index (this->obfd, section);
+ return this->section_offsets[idx];
+ }
+
+ /* Set the relocation offset applied to SECTION. */
+ void set_section_offset (bfd_section *section, CORE_ADDR offset)
+ {
+ /* The section's owner can be nullptr if it is one of the _bfd_std_section
+ section. */
+ gdb_assert (section->owner == nullptr || section->owner == this->obfd);
+
+ int idx = gdb_bfd_section_index (this->obfd, section);
+ this->section_offsets[idx] = offset;
+ }
/* The object file's original name as specified by the user,
made absolute, and tilde-expanded. However, it is not canonicalized
@@ -836,6 +826,47 @@ struct objfile_deleter
typedef std::unique_ptr<objfile, objfile_deleter> objfile_up;
+
+/* Sections in an objfile. The section offsets are stored in the
+ OBJFILE. */
+
+struct obj_section
+{
+ /* Relocation offset applied to the section. */
+ CORE_ADDR offset () const
+ {
+ return this->objfile->section_offset (this->the_bfd_section);
+ }
+
+ /* Set the relocation offset applied to the section. */
+ void set_offset (CORE_ADDR offset)
+ {
+ this->objfile->set_section_offset (this->the_bfd_section, offset);
+ }
+
+ /* The memory address of the section (vma + offset). */
+ CORE_ADDR addr () const
+ {
+ return bfd_section_vma (this->the_bfd_section) + this->offset ();
+ }
+
+ /* The one-passed-the-end memory address of the section
+ (vma + size + offset). */
+ CORE_ADDR endaddr () const
+ {
+ return this->addr () + bfd_section_size (this->the_bfd_section);
+ }
+
+ /* BFD section pointer */
+ struct bfd_section *the_bfd_section;
+
+ /* Objfile this section is part of. */
+ struct objfile *objfile;
+
+ /* True if this "overlay section" is mapped into an "overlay region". */
+ int ovly_mapped;
+};
+
/* Declarations for functions defined in objfiles.c */
extern int entry_point_address_query (CORE_ADDR *entry_p);