diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2023-10-19 20:40:52 +0000 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2023-10-20 22:00:23 -0400 |
commit | 0e17d3fc080f543d81e6c2520ba0bd8046ea3a95 (patch) | |
tree | 2f0a495b079cc9edb11114028e480890a1c1f866 /gdb/target-section.h | |
parent | 4a6daabb94982ccc17ea45ebb6f6e8efa8f86399 (diff) | |
download | gdb-0e17d3fc080f543d81e6c2520ba0bd8046ea3a95.zip gdb-0e17d3fc080f543d81e6c2520ba0bd8046ea3a95.tar.gz gdb-0e17d3fc080f543d81e6c2520ba0bd8046ea3a95.tar.bz2 |
gdb: fix owner passed to remove_target_sections in clear_solib
Commit 8971d2788e7 ("gdb: link so_list using intrusive_list") introduced
a bug in clear_solib. Instead of passing an `so_list *` to
remove_target_sections, it passed an `so_list **`. This was not caught
by the compiler, because remove_target_sections takes a `void *` as the
"owner", so you can pass it any pointer and it won't complain.
This happened because I previously had a patch to change the type of the
disposer parameter to be a reference rather than a pointer, so had to
change `so` to `&so`. When dropping that patch, I forgot to revert this
bit and / or it got re-introduced when handling subsequent merge
conflicts. And I didn't properly retest.
Fix that, but try to make things less error prone. Add a union to
represent the possible owner kinds for a target_section. Trying to pass
a pointer to another type than those will not compile.
Change-Id: I600cab5ea0408ccc5638467b760768161ca3036c
Diffstat (limited to 'gdb/target-section.h')
-rw-r--r-- | gdb/target-section.h | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/gdb/target-section.h b/gdb/target-section.h index 1c902ba..62149d3 100644 --- a/gdb/target-section.h +++ b/gdb/target-section.h @@ -20,6 +20,38 @@ #ifndef GDB_TARGET_SECTION_H #define GDB_TARGET_SECTION_H +struct bfd; +struct objfile; +struct shobj; + +/* A union representing the possible owner types of a target_section. */ + +union target_section_owner +{ + target_section_owner () : m_v (nullptr) {} + target_section_owner (const bfd *bfd) : bfd (bfd) {} + target_section_owner (const objfile *objfile) : objfile (objfile) {} + target_section_owner (const shobj *shobj) : shobj (shobj) {} + + /* Use this to access the type-erased version of the owner, for + comparisons, printing, etc. We don't access the M_V member + directly, because pedantically it is not valid to access a + non-active union member. */ + const void *v () const + { + void *tmp; + memcpy (&tmp, this, sizeof (*this)); + return tmp; + } + + const struct bfd *bfd; + const struct objfile *objfile; + const struct shobj *shobj; + +private: + const void *m_v; +}; + /* Struct target_section maps address ranges to file sections. It is mostly used with BFD files, but can be used without (e.g. for handling raw disks, or files not in formats handled by BFD). */ @@ -27,7 +59,7 @@ struct target_section { target_section (CORE_ADDR addr_, CORE_ADDR end_, struct bfd_section *sect_, - void *owner_ = nullptr) + target_section_owner owner_ = {}) : addr (addr_), endaddr (end_), the_bfd_section (sect_), @@ -44,11 +76,11 @@ struct target_section struct bfd_section *the_bfd_section; /* The "owner" of the section. - It can be any unique value. It is set by add_target_sections - and used by remove_target_sections. + + It is set by add_target_sections and used by remove_target_sections. For example, for executables it is a pointer to exec_bfd and - for shlibs it is the so_list pointer. */ - const void *owner; + for shlibs it is the shobj pointer. */ + target_section_owner owner; }; #endif /* GDB_TARGET_SECTION_H */ |