From 19a4ae130da2e00aec44ef0d2c6e59d7317eca05 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Fri, 31 May 2024 15:29:48 +0200 Subject: [PATCH] btf-reader: Fix re-use of the BTF reader for several binaries in a row 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 --- src/abg-btf-reader.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/abg-btf-reader.cc b/src/abg-btf-reader.cc index 1cf92dfb..a8131fd7 100644 --- a/src/abg-btf-reader.cc +++ b/src/abg-btf-reader.cc @@ -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));