diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-02-12 12:06:15 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-02-24 16:58:04 +0000 |
commit | 02f7d26b0bc929eba44372fa0955bb1c72f2deb8 (patch) | |
tree | 6c374fb50907499dd222422acddab180d42b0237 /gdb | |
parent | b91919ac8b5550451093f232a596dfe52a71536c (diff) | |
download | gdb-02f7d26b0bc929eba44372fa0955bb1c72f2deb8.zip gdb-02f7d26b0bc929eba44372fa0955bb1c72f2deb8.tar.gz gdb-02f7d26b0bc929eba44372fa0955bb1c72f2deb8.tar.bz2 |
gdb: make the target_sections table private within program_space
Following on from earlier commits which made access to the
target_sections table more 'const', this commit makes the table
private within the program_space class and provides member functions
to access the table.
Ideally I would have liked for the new target_sections member
function (on program_space) to return a 'const' reference to the table
within the program_space. Unfortunately, there are two places in
solib-*.c, where code outside of the program_space class modifies the
target_sections table, and so to support this we need to return a
non-const reference.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* exec.c (exec_target::close): Call new clear_target_sections
function.
(program_space::add_target_sections): Update name of member
variable.
(program_space::foreach_target_section): New function.
(program_space::add_target_sections): Update name of member
variable.
(program_space::remove_target_sections): Likewise.
(exec_one_fork): Use new target_sections member function.
(exec_target::get_section_table): Likewise.
(exec_target::files_info): Likewise.
(set_section_command): Use new foreach_target_section member
function.
(exec_set_section_address): Likewise.
(exec_target::has_memory): Use new target_sections member
function.
* progspace.h (program_space::clear_target_sections): New member
function.
(program_space::target_sections): Rename member variable to
m_target_sections, replace with a new member function.
(program_space::foreach_target_section): Declare new member
function.
(program_space::m_target_sections): New member variable.
* solib-dsbt.c (scan_dyntag): Use new member function.
* solib-svr4.c (scan_dyntag): Likewise.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 24 | ||||
-rw-r--r-- | gdb/exec.c | 32 | ||||
-rw-r--r-- | gdb/progspace.h | 21 | ||||
-rw-r--r-- | gdb/solib-dsbt.c | 2 | ||||
-rw-r--r-- | gdb/solib-svr4.c | 2 |
5 files changed, 59 insertions, 22 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e59343b..841d51b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,29 @@ 2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com> + * exec.c (exec_target::close): Call new clear_target_sections + function. + (program_space::add_target_sections): Update name of member + variable. + (program_space::add_target_sections): Update name of member + variable. + (program_space::remove_target_sections): Likewise. + (exec_one_fork): Use new target_sections member function. + (exec_target::get_section_table): Likewise. + (exec_target::files_info): Likewise. + (set_section_command): Likewise. + (exec_set_section_address): Likewise. + (exec_target::has_memory): Use new target_sections member + function. + * progspace.h (program_space::clear_target_sections): New member + function. + (program_space::target_sections): Rename member variable to + m_target_sections, replace with a new member function. + (program_space::m_target_sections): New member variable. + * solib-dsbt.c (scan_dyntag): Use new member function. + * solib-svr4.c (scan_dyntag): Likewise. + +2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com> + * gdb/bfd-target.c (class target_bfd) <get_section_table>: Make return type const. * gdb/exec.c (struct exec_target) <get_section_table>: Likewise. @@ -156,7 +156,7 @@ exec_target::close () { for (struct program_space *ss : program_spaces) { - ss->target_sections.clear (); + ss->clear_target_sections (); ss->exec_close (); } } @@ -599,8 +599,8 @@ program_space::add_target_sections (void *owner, { for (const target_section &s : sections) { - target_sections.push_back (s); - target_sections.back ().owner = owner; + m_target_sections.push_back (s); + m_target_sections.back ().owner = owner; } scoped_restore_current_pspace_and_thread restore_pspace_thread; @@ -637,9 +637,9 @@ program_space::add_target_sections (struct objfile *objfile) if (bfd_section_size (osect->the_bfd_section) == 0) continue; - target_sections.emplace_back (obj_section_addr (osect), - obj_section_endaddr (osect), - osect->the_bfd_section, (void *) objfile); + m_target_sections.emplace_back (obj_section_addr (osect), + obj_section_endaddr (osect), + osect->the_bfd_section, (void *) objfile); } } @@ -651,18 +651,18 @@ program_space::remove_target_sections (void *owner) { gdb_assert (owner != NULL); - auto it = std::remove_if (target_sections.begin (), - target_sections.end (), + auto it = std::remove_if (m_target_sections.begin (), + m_target_sections.end (), [&] (target_section §) { return sect.owner == owner; }); - target_sections.erase (it, target_sections.end ()); + m_target_sections.erase (it, m_target_sections.end ()); /* If we don't have any more sections to read memory from, remove the file_stratum target from the stack of each inferior sharing the program space. */ - if (target_sections.empty ()) + if (m_target_sections.empty ()) { scoped_restore_current_pspace_and_thread restore_pspace_thread; @@ -682,7 +682,7 @@ program_space::remove_target_sections (void *owner) void exec_on_vfork () { - if (!current_program_space->target_sections.empty ()) + if (!current_program_space->target_sections ().empty ()) push_target (&exec_ops); } @@ -887,7 +887,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf, const target_section_table * exec_target::get_section_table () { - return ¤t_program_space->target_sections; + return ¤t_program_space->target_sections (); } enum target_xfer_status @@ -985,7 +985,7 @@ void exec_target::files_info () { if (current_program_space->exec_bfd ()) - print_section_info (¤t_program_space->target_sections, + print_section_info (¤t_program_space->target_sections (), current_program_space->exec_bfd ()); else puts_filtered (_("\t<no file loaded>\n")); @@ -1010,7 +1010,7 @@ set_section_command (const char *args, int from_tty) /* Parse out new virtual address. */ secaddr = parse_and_eval_address (args); - for (target_section &p : current_program_space->target_sections) + for (target_section &p : current_program_space->target_sections ()) { if (!strncmp (secname, bfd_section_name (p.the_bfd_section), seclen) && bfd_section_name (p.the_bfd_section)[seclen] == '\0') @@ -1036,7 +1036,7 @@ set_section_command (const char *args, int from_tty) void exec_set_section_address (const char *filename, int index, CORE_ADDR address) { - for (target_section &p : current_program_space->target_sections) + for (target_section &p : current_program_space->target_sections ()) { if (filename_cmp (filename, bfd_get_filename (p.the_bfd_section->owner)) == 0 @@ -1053,7 +1053,7 @@ exec_target::has_memory () { /* We can provide memory if we have any file/target sections to read from. */ - return !current_program_space->target_sections.empty (); + return !current_program_space->target_sections ().empty (); } gdb::unique_xmalloc_ptr<char> diff --git a/gdb/progspace.h b/gdb/progspace.h index 6ac8932..7906847 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -309,6 +309,18 @@ struct program_space sections. They are given OBJFILE as the "owner". */ void add_target_sections (struct objfile *objfile); + /* Clear all target sections from M_TARGET_SECTIONS table. */ + void clear_target_sections () + { + m_target_sections.clear (); + } + + /* Return a reference to the M_TARGET_SECTIONS table. */ + target_section_table &target_sections () + { + return m_target_sections; + } + /* Unique ID number. */ int num = 0; @@ -359,10 +371,6 @@ struct program_space /* All known objfiles are kept in a linked list. */ std::list<std::shared_ptr<objfile>> objfiles_list; - /* The set of target sections matching the sections mapped into - this program space. Managed by both exec_ops and solib.c. */ - target_section_table target_sections; - /* List of shared objects mapped into this space. Managed by solib.c. */ struct so_list *so_list = NULL; @@ -380,6 +388,11 @@ struct program_space /* Per pspace data-pointers required by other GDB modules. */ REGISTRY_FIELDS {}; + +private: + /* The set of target sections matching the sections mapped into + this program space. Managed by both exec_ops and solib.c. */ + target_section_table m_target_sections; }; /* An address space. It is used for comparing if diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c index 6d21806..4b1b756 100644 --- a/gdb/solib-dsbt.c +++ b/gdb/solib-dsbt.c @@ -425,7 +425,7 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr) bool found = false; for (const target_section &target_section - : current_program_space->target_sections) + : current_program_space->target_sections ()) if (sect == target_section.the_bfd_section) { dyn_addr = target_section.addr; diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index f8dd419..c7b3157 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -611,7 +611,7 @@ scan_dyntag (const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr, bool found = false; for (const target_section &target_section - : current_program_space->target_sections) + : current_program_space->target_sections ()) if (sect == target_section.the_bfd_section) { dyn_addr = target_section.addr; |