btf-reader: Fix re-use of the BTF reader for several binaries in a row
Commit Message
Hello,
When analyzing a Linux Kernel tree, the BTF reader needs to be reset
after each binary (vmlinux or module) read. It turns out the reset
was not being done properly. Fixed thus. Also, I noticed that
reader::read_debug_info_into_corpus would not return an empty corpus
when no BTF information was found in the binary. Fixed as well.
* src/abg-btf-reader.cc (reader::initialize): Free the btf handle
first thing as part of the re-initialization.
(reader::~reader): Once the BTF handle has been freed, set it to
nil to show that it's been deleted.
(reader::read_debug_info_into_corpus): If no BTF handle could be
retrieved then it means no BTF data was found on the binary.
Thus, return an empty corpus.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Applying to the master branch.
---
src/abg-btf-reader.cc | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
@@ -238,8 +238,9 @@ protected:
bool load_all_types,
bool linux_kernel_mode)
{
- elf_based_reader::initialize(elf_path, debug_info_root_paths);
btf__free(btf_handle_);
+ btf_handle_ = nullptr;
+ elf_based_reader::initialize(elf_path, debug_info_root_paths);
options().load_all_types = load_all_types;
options().load_in_linux_kernel_mode = linux_kernel_mode;
}
@@ -305,6 +306,7 @@ public:
~reader()
{
btf__free(btf_handle_);
+ btf_handle_ = nullptr;
}
/// Read the ELF information as well as the BTF type information to
@@ -346,7 +348,8 @@ public:
corpus_sptr
read_debug_info_into_corpus()
{
- btf_handle();
+ if (!btf_handle())
+ return corpus_sptr();
translation_unit_sptr artificial_tu
(new translation_unit(env(), "", /*address_size=*/64));