mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-10-19 13:53:29 +08:00
Store objfiles on a std::list
This removes objfile::next and changes objfiles to be stored in a std::list. gdb/ChangeLog 2019-12-12 Tom Tromey <tom@tromey.com> * progspace.c (program_space::add_objfile) (program_space::remove_objfile): Update. (program_space::multi_objfile_p): Remove. * objfiles.h (struct objfile) <next>: Remove. * objfiles.c (objfile::objfile): Update. (put_objfile_before): Update. (unlink_objfile): Update. * progspace.h (object_files): Remove. (struct program_space) <objfiles_head>: Remove. <objfiles_list>: New member. <objfiles_range, objfiles_safe_range>: Change type. (objfiles): Change return type. (objfiles_safe): Update. (multi_objfile_p): Rewrite and inline. (object_files): Remove macro. Change-Id: Ib4430e3db6f9a390399924379a5c10426c514853
This commit is contained in:
@ -1,3 +1,21 @@
|
|||||||
|
2019-12-12 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* progspace.c (program_space::add_objfile)
|
||||||
|
(program_space::remove_objfile): Update.
|
||||||
|
(program_space::multi_objfile_p): Remove.
|
||||||
|
* objfiles.h (struct objfile) <next>: Remove.
|
||||||
|
* objfiles.c (objfile::objfile): Update.
|
||||||
|
(put_objfile_before): Update.
|
||||||
|
(unlink_objfile): Update.
|
||||||
|
* progspace.h (object_files): Remove.
|
||||||
|
(struct program_space) <objfiles_head>: Remove.
|
||||||
|
<objfiles_list>: New member.
|
||||||
|
<objfiles_range, objfiles_safe_range>: Change type.
|
||||||
|
(objfiles): Change return type.
|
||||||
|
(objfiles_safe): Update.
|
||||||
|
(multi_objfile_p): Rewrite and inline.
|
||||||
|
(object_files): Remove macro.
|
||||||
|
|
||||||
2019-12-12 Tom Tromey <tom@tromey.com>
|
2019-12-12 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* gdbsupport/safe-iterator.h (basic_safe_iterator): Simplify. Add
|
* gdbsupport/safe-iterator.h (basic_safe_iterator): Simplify. Add
|
||||||
|
@ -54,6 +54,7 @@
|
|||||||
#include "btrace.h"
|
#include "btrace.h"
|
||||||
#include "gdbsupport/pathstuff.h"
|
#include "gdbsupport/pathstuff.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/* Keep a registry of per-objfile data-pointers required by other GDB
|
/* Keep a registry of per-objfile data-pointers required by other GDB
|
||||||
|
@ -486,12 +486,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* All struct objfile's are chained together by their next pointers.
|
|
||||||
The program space field "objfiles" (frequently referenced via
|
|
||||||
the macro "object_files") points to the first link in this chain. */
|
|
||||||
|
|
||||||
struct objfile *next = nullptr;
|
|
||||||
|
|
||||||
/* The object file's original name as specified by the user,
|
/* The object file's original name as specified by the user,
|
||||||
made absolute, and tilde-expanded. However, it is not canonicalized
|
made absolute, and tilde-expanded. However, it is not canonicalized
|
||||||
(i.e., it has not been passed through gdb_realpath).
|
(i.e., it has not been passed through gdb_realpath).
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "solib.h"
|
#include "solib.h"
|
||||||
#include "gdbthread.h"
|
#include "gdbthread.h"
|
||||||
#include "inferior.h"
|
#include "inferior.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
/* The last program space number assigned. */
|
/* The last program space number assigned. */
|
||||||
int last_program_space_num = 0;
|
int last_program_space_num = 0;
|
||||||
@ -158,21 +159,15 @@ program_space::~program_space ()
|
|||||||
void
|
void
|
||||||
program_space::add_objfile (struct objfile *objfile, struct objfile *before)
|
program_space::add_objfile (struct objfile *objfile, struct objfile *before)
|
||||||
{
|
{
|
||||||
for (struct objfile **objp = &objfiles_head;
|
if (before == nullptr)
|
||||||
*objp != NULL;
|
objfiles_list.push_back (objfile);
|
||||||
objp = &((*objp)->next))
|
else
|
||||||
{
|
{
|
||||||
if (*objp == before)
|
auto iter = std::find (objfiles_list.begin (), objfiles_list.end (),
|
||||||
{
|
before);
|
||||||
objfile->next = *objp;
|
gdb_assert (iter != objfiles_list.end ());
|
||||||
*objp = objfile;
|
objfiles_list.insert (iter, objfile);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal_error (__FILE__, __LINE__,
|
|
||||||
_("put_objfile_before: before objfile not in list"));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See progspace.h. */
|
/* See progspace.h. */
|
||||||
@ -180,32 +175,13 @@ program_space::add_objfile (struct objfile *objfile, struct objfile *before)
|
|||||||
void
|
void
|
||||||
program_space::remove_objfile (struct objfile *objfile)
|
program_space::remove_objfile (struct objfile *objfile)
|
||||||
{
|
{
|
||||||
struct objfile **objpp;
|
auto iter = std::find (objfiles_list.begin (), objfiles_list.end (),
|
||||||
|
objfile);
|
||||||
for (objpp = &object_files; *objpp != NULL; objpp = &((*objpp)->next))
|
gdb_assert (iter != objfiles_list.end ());
|
||||||
{
|
objfiles_list.erase (iter);
|
||||||
if (*objpp == objfile)
|
|
||||||
{
|
|
||||||
*objpp = (*objpp)->next;
|
|
||||||
objfile->next = NULL;
|
|
||||||
|
|
||||||
if (objfile == symfile_object_file)
|
if (objfile == symfile_object_file)
|
||||||
symfile_object_file = NULL;
|
symfile_object_file = NULL;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal_error (__FILE__, __LINE__,
|
|
||||||
_("remove_objfile: objfile already unlinked"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See progspace.h. */
|
|
||||||
|
|
||||||
bool
|
|
||||||
program_space::multi_objfile_p () const
|
|
||||||
{
|
|
||||||
return objfiles_head != nullptr && objfiles_head->next != nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copies program space SRC to DEST. Copies the main executable file,
|
/* Copies program space SRC to DEST. Copies the main executable file,
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "registry.h"
|
#include "registry.h"
|
||||||
#include "gdbsupport/next-iterator.h"
|
#include "gdbsupport/next-iterator.h"
|
||||||
#include "gdbsupport/safe-iterator.h"
|
#include "gdbsupport/safe-iterator.h"
|
||||||
|
#include <list>
|
||||||
|
|
||||||
struct target_ops;
|
struct target_ops;
|
||||||
struct bfd;
|
struct bfd;
|
||||||
@ -138,20 +139,18 @@ struct program_space
|
|||||||
program_space (address_space *aspace_);
|
program_space (address_space *aspace_);
|
||||||
~program_space ();
|
~program_space ();
|
||||||
|
|
||||||
typedef next_adapter<struct objfile> objfiles_range;
|
typedef std::list<struct objfile *> objfiles_range;
|
||||||
|
|
||||||
/* Return an iterable object that can be used to iterate over all
|
/* Return an iterable object that can be used to iterate over all
|
||||||
objfiles. The basic use is in a foreach, like:
|
objfiles. The basic use is in a foreach, like:
|
||||||
|
|
||||||
for (objfile *objf : pspace->objfiles ()) { ... } */
|
for (objfile *objf : pspace->objfiles ()) { ... } */
|
||||||
objfiles_range objfiles ()
|
objfiles_range &objfiles ()
|
||||||
{
|
{
|
||||||
return objfiles_range (objfiles_head);
|
return objfiles_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef next_adapter<struct objfile,
|
typedef basic_safe_range<objfiles_range> objfiles_safe_range;
|
||||||
basic_safe_iterator<next_iterator<objfile>>>
|
|
||||||
objfiles_safe_range;
|
|
||||||
|
|
||||||
/* An iterable object that can be used to iterate over all objfiles.
|
/* An iterable object that can be used to iterate over all objfiles.
|
||||||
The basic use is in a foreach, like:
|
The basic use is in a foreach, like:
|
||||||
@ -162,7 +161,7 @@ struct program_space
|
|||||||
deleted during iteration. */
|
deleted during iteration. */
|
||||||
objfiles_safe_range objfiles_safe ()
|
objfiles_safe_range objfiles_safe ()
|
||||||
{
|
{
|
||||||
return objfiles_safe_range (objfiles_head);
|
return objfiles_safe_range (objfiles_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add OBJFILE to the list of objfiles, putting it just before
|
/* Add OBJFILE to the list of objfiles, putting it just before
|
||||||
@ -175,7 +174,10 @@ struct program_space
|
|||||||
|
|
||||||
/* Return true if there is more than one object file loaded; false
|
/* Return true if there is more than one object file loaded; false
|
||||||
otherwise. */
|
otherwise. */
|
||||||
bool multi_objfile_p () const;
|
bool multi_objfile_p () const
|
||||||
|
{
|
||||||
|
return objfiles_list.size () > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Pointer to next in linked list. */
|
/* Pointer to next in linked list. */
|
||||||
@ -228,9 +230,8 @@ struct program_space
|
|||||||
(e.g. the argument to the "symbol-file" or "file" command). */
|
(e.g. the argument to the "symbol-file" or "file" command). */
|
||||||
struct objfile *symfile_object_file = NULL;
|
struct objfile *symfile_object_file = NULL;
|
||||||
|
|
||||||
/* All known objfiles are kept in a linked list. This points to
|
/* All known objfiles are kept in a linked list. */
|
||||||
the head of this list. */
|
std::list<struct objfile *> objfiles_list;
|
||||||
struct objfile *objfiles_head = NULL;
|
|
||||||
|
|
||||||
/* The set of target sections matching the sections mapped into
|
/* The set of target sections matching the sections mapped into
|
||||||
this program space. Managed by both exec_ops and solib.c. */
|
this program space. Managed by both exec_ops and solib.c. */
|
||||||
@ -271,10 +272,6 @@ struct address_space
|
|||||||
|
|
||||||
#define symfile_objfile current_program_space->symfile_object_file
|
#define symfile_objfile current_program_space->symfile_object_file
|
||||||
|
|
||||||
/* All known objfiles are kept in a linked list. This points to the
|
|
||||||
root of this list. */
|
|
||||||
#define object_files current_program_space->objfiles_head
|
|
||||||
|
|
||||||
/* The set of target sections matching the sections mapped into the
|
/* The set of target sections matching the sections mapped into the
|
||||||
current program space. */
|
current program space. */
|
||||||
#define current_target_sections (¤t_program_space->target_sections)
|
#define current_target_sections (¤t_program_space->target_sections)
|
||||||
|
Reference in New Issue
Block a user