Hello,
In the use case laid out by the "Library Splitting support" at
https://sourceware.org/bugzilla/show_bug.cgi?id=30034, tools might
want to be able to re-initialize a given front-end to load several
corpora in a row, independently from the kind of front-end (elf-based,
ABIXML, etc). So we need a fe_iface::initialize() interface that is
similar to the elf_based_reader::initialize() interface but, unlike
that one, it should not depend on parameters that only make sense in a
elf-based context. For instance, the fe_iface::initialize() interface
should not contain paths to debug-info as that information does not
make sense in an ABIXML context.
This patch thus renames fe_iface::reset() into fe_iface::initialize()
and makes it virtual. It adjusts the plumbing accordingly, basically
making the other ::initialize() methods of classes that inherit
fe_iface use fe_iface::initialize() when appropriate.
The patch also provides an elf_based_reader::initialize()
implementation of the fe_iface::initialize() interface, so that
invoking ::initialize on elf_based_reader through the fe_iface
interface does the right thing so that the initial use case presented
at the beginning of this comment is supported.
* include/abg-elf-based-reader.h (elf_based_reader::initialize):
Rename elf_based_reader::reset into this. Add a new virtual
overload that implements fe_iface::initialize.
* include/abg-elf-reader.h (reader::initialize): Rename
elf_reader::reset into this. Add a new virtual overload that
implements fe_iface::initialize.
* include/abg-fe-iface.h (fe_iface::initialize): Rename
fe_iface::reset into this and make it virtual.
* src/abg-btf-reader.cc (btf::reader::initialize): Adjust call to
elf_based_reader::reset to elf_based_reader::initialize.
* src/abg-ctf-reader.cc (ctf::reader::initialize): Likewise.
* src/abg-dwarf-reader.cc (dwarf::reader::initialize): Likewise.
* src/abg-elf-based-reader.cc (elf_based_reader::initialize):
Rename elf_based_reader::reset into this. Adjust call to
elf::reader::reset into elf::reader::initialize. Add a new
virtual overload that implements fe_iface::initialize.
* src/abg-elf-reader.cc (reader::initialize): Rename
elf::reader::reset into this. Adjust call to fe_iface::reset into
fe_iface::initialize. Add a new virtual overload that implements
fe_iface::initialize.
* src/abg-fe-iface.cc (fe_iface::priv::initialize): Reset the
corpus too.
(fe_iface::initialize): Rename fe_iface::reset into this. Invoke
priv::initialize and set the new corpus_path.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Applied to master.
---
include/abg-elf-based-reader.h | 8 ++++++--
include/abg-elf-reader.h | 9 ++++++---
include/abg-fe-iface.h | 4 ++--
src/abg-btf-reader.cc | 2 +-
src/abg-ctf-reader.cc | 2 +-
src/abg-dwarf-reader.cc | 2 +-
src/abg-elf-based-reader.cc | 23 +++++++++++++++++++----
src/abg-elf-reader.cc | 25 +++++++++++++++++++------
src/abg-fe-iface.cc | 11 ++++-------
9 files changed, 59 insertions(+), 27 deletions(-)
@@ -50,17 +50,21 @@ public:
~elf_based_reader();
virtual void
- reset(const std::string& elf_path,
- const vector<char**>& debug_info_root_paths);
+ initialize(const std::string& elf_path,
+ const vector<char**>& debug_info_root_paths);
virtual ir::corpus_sptr
read_and_add_corpus_to_group(ir::corpus_group& group,
fe_iface::status& status);
+
virtual void
initialize(const string& elf_path,
const vector<char**>& debug_info_root_paths,
bool load_all_types,
bool linux_kernel_mode) = 0;
+
+ virtual void
+ initialize(const std::string& corpus_path);
};//end class elf_based_reader
typedef std::shared_ptr<elf_based_reader> elf_based_reader_sptr;
@@ -72,9 +72,12 @@ class reader : public fe_iface
~reader();
- void
- reset(const std::string& elf_path,
- const vector<char**>& debug_info_roots);
+ virtual void
+ initialize(const std::string& elf_path,
+ const vector<char**>& debug_info_roots);
+
+ virtual void
+ initialize(const std::string& elf_path);
const vector<char**>&
debug_info_root_paths() const;
@@ -74,8 +74,8 @@ protected:
virtual ~fe_iface();
- void
- reset(const std::string& corpus_path, environment& e);
+ virtual void
+ initialize(const std::string& corpus_path);
const options_type&
options() const;
@@ -237,7 +237,7 @@ protected:
bool load_all_types,
bool linux_kernel_mode)
{
- reset(elf_path, debug_info_root_paths);
+ elf_based_reader::initialize(elf_path, debug_info_root_paths);
btf__free(btf_handle_);
options().load_all_types = load_all_types;
options().load_in_linux_kernel_mode = linux_kernel_mode;
@@ -288,7 +288,7 @@ public:
{
load_all_types = load_all_types;
linux_kernel_mode = linux_kernel_mode;
- reset(elf_path, debug_info_root_paths);
+ elf_based_reader::initialize(elf_path, debug_info_root_paths);
}
/// Setter of the current translation unit.
@@ -2018,7 +2018,7 @@ public:
bool load_all_types,
bool linux_kernel_mode)
{
- reset(elf_path, debug_info_root_paths);
+ elf_based_reader::initialize(elf_path, debug_info_root_paths);
initialize(load_all_types, linux_kernel_mode);
}
@@ -61,7 +61,7 @@ elf_based_reader::elf_based_reader(const std::string& elf_path,
elf_based_reader::~elf_based_reader()
{delete priv_;}
-/// Reset (re-initialize) the resources used by the current reader.
+/// (re)Initialize) the resources used by the current reader.
///
/// This frees the resources of the current reader and gets it ready
/// to read data from another ELF file.
@@ -71,13 +71,28 @@ elf_based_reader::~elf_based_reader()
/// @param debug_info_root_paths a vector of paths to look into for
/// split debug info files.
void
-elf_based_reader::reset(const std::string& elf_path,
- const vector<char**>& debug_info_root_paths)
+elf_based_reader::initialize(const std::string& elf_path,
+ const vector<char**>& debug_info_root_paths)
{
- elf::reader::reset(elf_path, debug_info_root_paths);
+ elf::reader::initialize(elf_path, debug_info_root_paths);
priv_->initialize();
}
+/// (re)Initialize the resources used by the current reader.
+///
+/// This invokes fe_iface::initialize as wel as the virtual pure
+/// elf_based_reader::initialize() interface.
+///
+/// @param corpus_path path to the corpus to be built.
+void
+elf_based_reader::initialize(const std::string& corpus_path)
+{
+ fe_iface::initialize(corpus_path);
+ vector<char**> v;
+ initialize(corpus_path, v, /*load_all_type=*/false,
+ /*linux_kernel_mode=*/false);
+}
+
/// Read an ABI corpus and add it to a given corpus group.
///
/// @param group the corpus group to consider. The new corpus is
@@ -527,8 +527,8 @@ reader::reader(const string& elf_path,
reader::~reader()
{delete priv_;}
-/// Resets (erase) the resources used by the current @ref
-/// elf::reader type.
+/// Re-initialize the resources used by the current @ref elf::reader
+/// type.
///
/// This lets the reader in a state where it's ready to read from
/// another ELF file.
@@ -538,11 +538,10 @@ reader::~reader()
/// @param debug_info_roots a vector of directory paths to look into
/// for split debug information files.
void
-reader::reset(const std::string& elf_path,
- const vector<char**>& debug_info_roots)
+reader::initialize(const std::string& elf_path,
+ const vector<char**>& debug_info_roots)
{
- fe_iface::options_type opts = options();
- fe_iface::reset(elf_path, opts.env);
+ fe_iface::initialize(elf_path);
corpus_path(elf_path);
priv_->initialize(debug_info_roots);
priv_->crack_open_elf_file();
@@ -550,6 +549,20 @@ reader::reset(const std::string& elf_path,
priv_->locate_ctf_debug_info();
}
+/// Re-initialize the resources used by the current @ref elf::reader
+/// type.
+///
+/// This lets the reader in a state where it's ready to read from
+/// another ELF file.
+///
+/// @param elf_path the new ELF path to read from.
+void
+reader::initialize(const std::string& elf_path)
+{
+ vector<char**> v;
+ initialize(elf_path, v);
+}
+
/// Getter of the vector of directory paths to look into for split
/// debug information files.
///
@@ -43,11 +43,11 @@ struct fe_iface::priv
void
initialize()
{
- //TODO: initialize the options.
corpus_path.clear();
dt_soname.clear();
suppressions.clear();
corpus_group.reset();
+ corpus.reset();
}
}; //end struct fe_iface::priv
@@ -78,14 +78,11 @@ fe_iface::~fe_iface()
///
/// @param corpus_path the path to the file for which a new corpus is
/// to be created.
-///
-/// @param e the environment in which the Front End operates.
void
-fe_iface::reset(const std::string& corpus_path,
- environment& e)
+fe_iface::initialize(const std::string& corpus_path)
{
- delete priv_;
- priv_ = new fe_iface::priv(corpus_path, e);
+ priv_->initialize();
+ priv_->corpus_path = corpus_path;
}
/// Getter of the the options of the current Front End Interface.