From patchwork Tue Jun 10 09:39:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 114138 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1CB3C382C092 for ; Tue, 10 Jun 2025 09:40:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1CB3C382C092 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Yi4Nw5/H X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 65589382C08E for ; Tue, 10 Jun 2025 09:39:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 65589382C08E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 65589382C08E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749548388; cv=none; b=Skcazj3jHEP9QqNWHGGD/bt/7HkcEb29ScxOwLMzXxvk8pb+4277EK3HHTDInbM3ryyDHpu155cSZGCYeAKeQQxcabY6UCRb//Mc8ynRQt5Sw10hzLIVDDE5dF1SvoWvYi5HxFFXAh24uZtBj9sXDK5zHTF5S04+lbwNAwT9K9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749548388; c=relaxed/simple; bh=X/g6Z3qk0RxK1uvopQvvwAFP9UZrdsHO/GAMHx8WH/k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=cF4vjG6e5ubWWnUFPO2F7W0nP15Z/cVfVslLuG6jCjPxqSxhgVB2V7vGSlxbceQ4YswkmKTC80LgCMraIT7AlDmHIwDqq8WziVyIbjZ4DW1eoqAzgTEeI2kETcughyNDpYYz2IvomSxw5qfP9MPnAJRovPK1o/YUnThwGDD+rHA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 65589382C08E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749548388; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=5NkXIQjYEMsEnf77//ygiw1ujVrTGQXm/1gxZQhf1i4=; b=Yi4Nw5/HGUHs073j2kmCDeHv6UO6SA+eSyvyRUc/8dkaJkAJF2ogCSCkvdzm1afzBlQ6Qc 93zqTNQdE/VqTejR35k2KvZGlIN6awFD0f1I8x5FwpU8sIVwkaoAiKBvLQ8Z12GvgGZ6S9 AefY6mESFlsRhSF0Ku5BWyJcMyKgKOA= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-640-uPTrpEkaN9-j5bN-2zb--A-1; Tue, 10 Jun 2025 05:39:46 -0400 X-MC-Unique: uPTrpEkaN9-j5bN-2zb--A-1 X-Mimecast-MFC-AGG-ID: uPTrpEkaN9-j5bN-2zb--A_1749548385 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BFF1D18002ED for ; Tue, 10 Jun 2025 09:39:45 +0000 (UTC) Received: from localhost (unknown [10.44.22.13]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0236E180045B for ; Tue, 10 Jun 2025 09:39:45 +0000 (UTC) Received: by localhost (Postfix, from userid 1000) id 971335077C51; Tue, 10 Jun 2025 11:39:42 +0200 (CEST) From: Dodji Seketeli To: libabigail@sourceware.org Subject: [PATCH, applied] Change debuginfo root paths type from vector to vector Organization: Red Hat / France X-Operating-System: AlmaLinux 9.6 X-URL: http://www.redhat.com Date: Tue, 10 Jun 2025 11:39:42 +0200 Message-ID: <87zfegorz5.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: uVcJBdzkgiNyg4YKV7bh3a3OzmU3_DzVZpU7L5cA1jw_1749548385 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libabigail-bounces~patchwork=sourceware.org@sourceware.org Hello, Now that the debuginfo root paths are all setup for elfutils in elf_reader::priv::crack_open_elf_file by elf_reader::priv::initialize_debug_info_root_paths, higher level client code does not need to know about the inner workings of how elfutils handles debuginfo dir path and what not. As such, using vector for a vector of debuginfo directories provided by the user makes more sense than the char** type that elfutils expects at lower levels. This patch cleans up the entire code base to make char** appear only at the lowest level when setting up elfutils. All other higher level parts use the more logical vector type. * include/abg-btf-reader.h (btf::create_reader): Take vector& instead of vector& for debug_info_root_paths. * include/abg-ctf-reader.h (ctf::{create,reset}_reader): Likewise. * include/abg-dwarf-reader.h (dwarf::{create,reset}_reader) (read_corpus_from_elf): Likewise. * include/abg-elf-based-reader.h (elf_based_reader::initialize): Likewise. * include/abg-elf-reader.h (elf::reader::{reader, initialize, debug_info_root_paths}): Likewise. * include/abg-tools-utils.h (file_has_{dwarf,ctf,btf}_debug_info) (create_best_elf_based_reader): Likewise. (get_file_path_dirs_under_dir): Declare new function. (make_path_absolute): Add an overload for string. * src/abg-btf-reader.cc (btf::reader::{initialize, reader, create, create_reader}): Take vector& instead of vector& for debug_info_root_paths. * src/abg-ctf-reader.cc (ctf::reader::{reader, initialize, create_reader, reset_reader}): Likewise. * src/abg-dwarf-reader.cc (dwarf::reader::{reader, initialize, create, create_reader, read_corpus_from_elf}): Likewise. * src/abg-elf-based-reader.cc (elf_based_reader::{elf_based_reader, initialize}): Likewise. * src/abg-elf-reader.cc (elf::reader::priv::debug_info_root_paths): Change the type of this data member from vector to vector. (elf::reader::priv::{priv, initialize}): Take vector& instead of vector& for debug_info_root_paths and adjust the body accordingly. (elf::reader::{reader, initialize, debug_info_root_paths}): Take or return vector& instead of vector& * src/abg-tools-utils.cc (file_has_{dwarf,ctf,btf}_debug_info) (load_vmlinux_corpus, create_best_elf_based_reader): Likewise. (make_path_absolute): New overload for const string&. (build_corpus_group_from_kernel_dist_under): Adjust to using vector instead of vector. * tests/print-diff-tree.cc (main): Likewise. * tests/test-diff-dwarf.cc (main): Likewise. * tests/test-ir-walker.cc (main): Likewise. * tests/test-read-btf.cc (test_task_btf::perform(): Likewise. * tests/test-read-ctf.cc (test_task_ctf::perform): Likewise. * tests/test-symtab.cc (read_corpus): Likewise. * tools/abicompat.cc (options::{app_di_root_path, lib1_di_root_path, lib2_di_root_path}): Switch types of these data member from shared_ptr to string. (parse_command_line): Adjust to using the string overload of tools_utils::make_path_absolute. (read_corpus): Take a vector instead of vector for debuginfo root dirs. (main): Adjust to using string & vector for debuginfo root directories instead of char* and vector. * tools/abidiff.cc (options::{di_root_paths[12]}): Change the types of these data members from vector to vector. (options::prepared_di_root_paths[12]): Remove these data members. (options::~options): Remove. (parse_command_line): Adjust to using the string overload of tools_utils::make_path_absolute. (prepare_di_root_paths): Remove. (handle_error): Adjust. (main): Remove call to prepare_di_root_paths & adjust. * tools/abidw.cc (options::di_root_paths): Adjust type to vector from vector (options::prepared_di_root_paths1): Remove data member. (options::~options): Remove. (load_corpus_and_write_abixml): Adjust. (prepare_di_root_paths): Remove. * tools/abilint.cc (options::di_root_path): Change type from shared_ptr to string. (parse_command_line): Adjust. (main): Adjust. * tools/abipkgdiff.cc (compare, compare_to_self): Adjust. Signed-off-by: Dodji Seketeli Applied to the mainline. --- include/abg-btf-reader.h | 2 +- include/abg-ctf-reader.h | 4 +-- include/abg-dwarf-reader.h | 6 ++-- include/abg-elf-based-reader.h | 6 ++-- include/abg-elf-reader.h | 6 ++-- include/abg-tools-utils.h | 14 +++++--- src/abg-btf-reader.cc | 8 ++--- src/abg-ctf-reader.cc | 10 +++--- src/abg-dwarf-reader.cc | 12 +++---- src/abg-elf-based-reader.cc | 6 ++-- src/abg-elf-reader.cc | 20 +++++------ src/abg-tools-utils.cc | 54 +++++++++++++++++++--------- tests/print-diff-tree.cc | 2 +- tests/test-diff-dwarf.cc | 2 +- tests/test-ir-walker.cc | 2 +- tests/test-read-btf.cc | 2 +- tests/test-read-ctf.cc | 2 +- tests/test-symtab.cc | 2 +- tools/abicompat.cc | 37 +++++++++---------- tools/abidiff.cc | 65 +++++++++------------------------- tools/abidw.cc | 27 ++------------ tools/abilint.cc | 14 ++++---- tools/abipkgdiff.cc | 26 +++++++------- 23 files changed, 152 insertions(+), 177 deletions(-) diff --git a/include/abg-btf-reader.h b/include/abg-btf-reader.h index c6400ed4..542bf8bb 100644 --- a/include/abg-btf-reader.h +++ b/include/abg-btf-reader.h @@ -56,7 +56,7 @@ namespace btf /// @return a smart pointer to the resulting btf::reader. elf_based_reader_sptr create_reader(const std::string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& env, bool load_all_types = false, bool linux_kernel_mode = false); diff --git a/include/abg-ctf-reader.h b/include/abg-ctf-reader.h index d9839966..d0eeabe7 100644 --- a/include/abg-ctf-reader.h +++ b/include/abg-ctf-reader.h @@ -30,13 +30,13 @@ namespace ctf elf_based_reader_sptr create_reader(const std::string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& env); void reset_reader(elf_based_reader& ctxt, const std::string& elf_path, - const vector& debug_info_root_path); + const vector& debug_info_root_path); } // end namespace ctf_reader } // end namespace abigail diff --git a/include/abg-dwarf-reader.h b/include/abg-dwarf-reader.h index 38c6b394..a059bef4 100644 --- a/include/abg-dwarf-reader.h +++ b/include/abg-dwarf-reader.h @@ -31,7 +31,7 @@ using namespace abigail::ir; elf_based_reader_sptr create_reader(const std::string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& environment, bool read_all_types = false, bool linux_kernel_mode = false); @@ -39,13 +39,13 @@ create_reader(const std::string& elf_path, void reset_reader(elf_based_reader& rdr, const std::string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, bool read_all_types = false, bool linux_kernel_mode = false); corpus_sptr read_corpus_from_elf(const std::string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& environment, bool load_all_types, fe_iface::status& status); diff --git a/include/abg-elf-based-reader.h b/include/abg-elf-based-reader.h index 23bca961..0f270eb3 100644 --- a/include/abg-elf-based-reader.h +++ b/include/abg-elf-based-reader.h @@ -43,7 +43,7 @@ protected: /// method to create a reader instance as this constructor is /// protected. elf_based_reader(const std::string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& env); public: @@ -51,7 +51,7 @@ public: virtual void initialize(const std::string& elf_path, - const vector& debug_info_root_paths); + const vector& debug_info_root_paths); virtual ir::corpus_sptr read_and_add_corpus_to_group(ir::corpus_group& group, @@ -59,7 +59,7 @@ public: virtual void initialize(const string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, bool load_all_types, bool linux_kernel_mode) = 0; diff --git a/include/abg-elf-reader.h b/include/abg-elf-reader.h index 343cd253..7fde1804 100644 --- a/include/abg-elf-reader.h +++ b/include/abg-elf-reader.h @@ -67,19 +67,19 @@ class reader : public fe_iface public: reader(const std::string& elf_path, - const vector& debug_info_roots, + const vector& debug_info_roots, environment& env); ~reader(); virtual void initialize(const std::string& elf_path, - const vector& debug_info_roots); + const vector& debug_info_roots); virtual void initialize(const std::string& elf_path); - const vector& + const vector& debug_info_root_paths() const; const Dwfl_Callbacks& diff --git a/include/abg-tools-utils.h b/include/abg-tools-utils.h index c418bc47..1762de96 100644 --- a/include/abg-tools-utils.h +++ b/include/abg-tools-utils.h @@ -40,11 +40,11 @@ const char* get_anonymous_subrange_internal_name_prefix(); bool file_exists(const string&); bool is_regular_file(const string&); bool file_has_dwarf_debug_info(const string& elf_file_path, - const vector& debug_info_root_paths); + const vector& debug_info_root_paths); bool file_has_ctf_debug_info(const string& elf_file_path, - const vector& debug_info_root_paths); + const vector& debug_info_root_paths); bool file_has_btf_debug_info(const string& elf_file_path, - const vector& debug_info_root_paths); + const vector& debug_info_root_paths); bool is_dir(const string&); bool dir_exists(const string&); bool dir_is_empty(const string &); @@ -114,6 +114,9 @@ get_binary_paths_from_kernel_dist(const string& dist_root, string& vmlinux_path, vector& module_paths); +bool +get_file_path_dirs_under_dir(const string& root, vector& dirs); + string get_default_system_suppression_file_path(); @@ -366,6 +369,9 @@ file_is_kernel_debuginfo_package(const string& file_path, std::shared_ptr make_path_absolute(const char*p); +string +make_path_absolute(const string& p); + char* make_path_absolute_to_be_freed(const char*p); @@ -382,7 +388,7 @@ build_corpus_group_from_kernel_dist_under(const string& root, elf_based_reader_sptr create_best_elf_based_reader(const string& elf_file_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& env, corpus::origin requested_debug_info_kind, bool show_all_types, diff --git a/src/abg-btf-reader.cc b/src/abg-btf-reader.cc index f3ac3f1f..89132dfd 100644 --- a/src/abg-btf-reader.cc +++ b/src/abg-btf-reader.cc @@ -409,7 +409,7 @@ protected: /// @param linux_kernel_mode void initialize(const string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, bool load_all_types, bool linux_kernel_mode) { @@ -448,7 +448,7 @@ protected: /// @param linux_kernel_mode if true, then consider the binary being /// analyzed as a linux kernel binary. reader(const string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& environment, bool load_all_types, bool linux_kernel_mode) @@ -479,7 +479,7 @@ public: /// analyzed as a linux kernel binary. static btf::reader_sptr create(const string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& environment, bool load_all_types, bool linux_kernel_mode) @@ -1330,7 +1330,7 @@ public: /// @return a smart pointer to the resulting btf::reader. elf_based_reader_sptr create_reader(const std::string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& env, bool load_all_types, bool linux_kernel_mode) diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc index 52745f62..aec24dbe 100644 --- a/src/abg-ctf-reader.cc +++ b/src/abg-ctf-reader.cc @@ -261,7 +261,7 @@ public: /// that ABI artifacts that are to be compared all need to be /// created within the same environment. reader(const string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& env) : elf_based_reader(elf_path, debug_info_root_paths, env), ctfa(), ctf_sect(), symtab_sect(), strtab_sect() @@ -311,7 +311,7 @@ public: /// void initialize(const string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, bool load_all_types = false, bool linux_kernel_mode = false) { @@ -385,7 +385,7 @@ public: // for vmlinux.ctfa should be provided with --debug-info-dir // option. for (const auto& path : debug_info_root_paths()) - if (tools_utils::find_file_under_dir(*path, "vmlinux.ctfa", ctfa_file)) + if (tools_utils::find_file_under_dir(path, "vmlinux.ctfa", ctfa_file)) return true; return false; @@ -1753,7 +1753,7 @@ fill_ctf_section(const Elf_Scn *elf_section, ctf_sect_t *ctf_section) /// @param env a libabigail IR environment. elf_based_reader_sptr create_reader(const std::string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& env) { reader_sptr result(new reader(elf_path, @@ -1781,7 +1781,7 @@ create_reader(const std::string& elf_path, void reset_reader(elf_based_reader& rdr, const std::string& elf_path, - const vector& debug_info_root_path) + const vector& debug_info_root_path) { ctf::reader& r = dynamic_cast(rdr); r.initialize(elf_path, debug_info_root_path); diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index ece58378..f1fdc1d3 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -2114,7 +2114,7 @@ protected: /// linux kernel symbol tables when determining if a symbol is /// exported or not. reader(const string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& environment, bool load_all_types, bool linux_kernel_mode) @@ -2215,7 +2215,7 @@ public: /// is exported or not. void initialize(const string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, bool load_all_types, bool linux_kernel_mode) { @@ -2242,7 +2242,7 @@ public: /// is exported or not. static dwarf::reader_sptr create(const std::string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& environment, bool load_all_types, bool linux_kernel_mode) @@ -17801,7 +17801,7 @@ build_ir_node_from_die(reader& rdr, /// @return a smart pointer to the resulting dwarf::reader. elf_based_reader_sptr create_reader(const std::string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& environment, bool load_all_types, bool linux_kernel_mode) @@ -17852,7 +17852,7 @@ create_reader(const std::string& elf_path, void reset_reader(elf_based_reader& rdr, const std::string& elf_path, - const vector&debug_info_root_path, + const vector&debug_info_root_path, bool read_all_types, bool linux_kernel_mode) { @@ -17895,7 +17895,7 @@ reset_reader(elf_based_reader& rdr, /// @return the resulting status. corpus_sptr read_corpus_from_elf(const std::string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& environment, bool load_all_types, fe_iface::status& status) diff --git a/src/abg-elf-based-reader.cc b/src/abg-elf-based-reader.cc index 1a1a1bb0..d13175dc 100644 --- a/src/abg-elf-based-reader.cc +++ b/src/abg-elf-based-reader.cc @@ -49,7 +49,7 @@ struct elf_based_reader::priv /// /// @param env the environment used by the reader. elf_based_reader::elf_based_reader(const std::string& elf_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& env) : elf::reader(elf_path, debug_info_root_paths, env), priv_(new priv) @@ -72,7 +72,7 @@ elf_based_reader::~elf_based_reader() /// split debug info files. void elf_based_reader::initialize(const std::string& elf_path, - const vector& debug_info_root_paths) + const vector& debug_info_root_paths) { elf::reader::initialize(elf_path, debug_info_root_paths); priv_->initialize(); @@ -88,7 +88,7 @@ void elf_based_reader::initialize(const std::string& corpus_path) { fe_iface::initialize(corpus_path); - vector v; + vector v; initialize(corpus_path, v, /*load_all_type=*/false, /*linux_kernel_mode=*/false); } diff --git a/src/abg-elf-reader.cc b/src/abg-elf-reader.cc index bf590f8f..13d497ff 100644 --- a/src/abg-elf-reader.cc +++ b/src/abg-elf-reader.cc @@ -112,7 +112,7 @@ struct reader::priv // demand. mutable symtab_reader::symtab_sptr symt; // Where split debug info is to be searched for on disk. - vector debug_info_root_paths; + vector debug_info_root_paths; // The formatted string version of debug_info_root_paths. The // format is according to what elfutils expects. For the details of // what elfutils expects, please read the comments of the function @@ -145,7 +145,7 @@ struct reader::priv Elf_Scn* btf_section = nullptr; priv(reader& reeder, const std::string& elf_path, - const vector& debug_info_roots) + const vector& debug_info_roots) : rdr(reeder) { rdr.corpus_path(elf_path); @@ -163,7 +163,7 @@ struct reader::priv /// @param debug_info_roots the vector of new directories where to /// look for split debug info file. void - initialize(const vector& debug_info_roots) + initialize(const vector& debug_info_roots) { clear_alt_dwarf_debug_info_data(); clear_alt_ctf_debug_info_data(); @@ -207,8 +207,8 @@ struct reader::priv { if (formated_di_root_paths.empty()) formated_di_root_paths = "-"; - if (*path) - formated_di_root_paths += string(*path) + string (":"); + if (!path.empty()) + formated_di_root_paths += path + ":"; } raw_formated_di_root_paths = const_cast(formated_di_root_paths.c_str()); @@ -325,7 +325,7 @@ struct reader::priv for (const auto& path : rdr.debug_info_root_paths()) { std::string file_path; - if (!tools_utils::find_file_under_dir(*path, name, file_path)) + if (!tools_utils::find_file_under_dir(path, name, file_path)) continue; if ((alt_ctf_fd = open(file_path.c_str(), O_RDONLY)) == -1) @@ -371,7 +371,7 @@ struct reader::priv /// /// @param env the environment which the reader operates in. reader::reader(const string& elf_path, - const vector& debug_info_roots, + const vector& debug_info_roots, ir::environment& env) : fe_iface(elf_path, env), priv_(new priv(*this, elf_path, debug_info_roots)) @@ -397,7 +397,7 @@ reader::~reader() /// for split debug information files. void reader::initialize(const std::string& elf_path, - const vector& debug_info_roots) + const vector& debug_info_roots) { fe_iface::initialize(elf_path); corpus_path(elf_path); @@ -417,7 +417,7 @@ reader::initialize(const std::string& elf_path, void reader::initialize(const std::string& elf_path) { - vector v; + vector v; initialize(elf_path, v); } @@ -426,7 +426,7 @@ reader::initialize(const std::string& elf_path) /// /// @return the vector of directory paths to look into for split /// debug information files. -const vector& +const vector& reader::debug_info_root_paths() const {return priv_->debug_info_root_paths;} diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc index 7bc813d7..b296f8a0 100644 --- a/src/abg-tools-utils.cc +++ b/src/abg-tools-utils.cc @@ -461,7 +461,7 @@ dir_contains_ctf_archive(const string& directory, /// that contains debug info. bool file_has_dwarf_debug_info(const string& elf_file_path, - const vector& debug_info_root_paths) + const vector& debug_info_root_paths) { if (guess_file_type(elf_file_path) != FILE_TYPE_ELF) return false; @@ -497,7 +497,7 @@ file_has_dwarf_debug_info(const string& elf_file_path, /// that contains debug info. bool file_has_ctf_debug_info(const string& elf_file_path, - const vector& debug_info_root_paths) + const vector& debug_info_root_paths) { if (guess_file_type(elf_file_path) != FILE_TYPE_ELF) return false; @@ -521,7 +521,7 @@ file_has_ctf_debug_info(const string& elf_file_path, // vmlinux.ctfa could be provided with --debug-info-dir for (const auto& path : debug_info_root_paths) - if (path && *path && find_file_under_dir(*path, "vmlinux.ctfa", vmlinux)) + if (!path.empty() && find_file_under_dir(path, "vmlinux.ctfa", vmlinux)) return true; return false; @@ -541,7 +541,7 @@ file_has_ctf_debug_info(const string& elf_file_path, /// that contains debug info. bool file_has_btf_debug_info(const string& elf_file_path, - const vector& debug_info_root_paths) + const vector& debug_info_root_paths) { if (guess_file_type(elf_file_path) != FILE_TYPE_ELF) return false; @@ -2174,6 +2174,31 @@ make_path_absolute(const char*p) return result; } +/// Return a copy of the path given in argument, turning it into an +/// absolute path by prefixing it with the concatenation of the result +/// of get_current_dir_name() and the '/' character. +/// +/// +/// @param p the path to turn into an absolute path. +/// +/// @return The resulting absolute path. +string +make_path_absolute(const string& p) +{ + string result; + + if (!p.empty() && p[0] != '/') + { + shared_ptr pwd(get_current_dir_name(), + malloced_char_star_deleter()); + result = string(pwd.get()) + "/" + p; + } + else if (!p.empty()) + result = p; + + return result; +} + /// Return a copy of the path given in argument, turning it into an /// absolute path by prefixing it with the concatenation of the result /// of get_current_dir_name() and the '/' character. @@ -3210,7 +3235,7 @@ load_vmlinux_corpus(elf_based_reader_sptr rdr, const string& vmlinux, vector& modules, const string& root, - vector& di_roots, + vector& di_roots, vector& suppr_paths, vector& kabi_wl_paths, suppressions_type& supprs, @@ -3372,20 +3397,17 @@ build_corpus_group_from_kernel_dist_under(const string& root, if (got_binary_paths) { - shared_ptr di_root = - make_path_absolute(debug_info_root.c_str()); - char *di_root_ptr = di_root.get(); - vector di_roots; - di_roots.push_back(&di_root_ptr); + string di_root = + make_path_absolute(debug_info_root); + vector di_roots; + di_roots.push_back(di_root); #ifdef WITH_CTF - shared_ptr di_root_ctf; - char *di_root_ctf_ptr; + string di_root_ctf; if (requested_fe_kind & corpus::CTF_ORIGIN) { - di_root_ctf = make_path_absolute(root.c_str()); - di_root_ctf_ptr = di_root_ctf.get(); - di_roots.push_back(&di_root_ctf_ptr); + di_root_ctf = make_path_absolute(root); + di_roots.push_back(di_root_ctf); } #endif @@ -3443,7 +3465,7 @@ build_corpus_group_from_kernel_dist_under(const string& root, /// designated by @p elf_file_path. elf_based_reader_sptr create_best_elf_based_reader(const string& elf_file_path, - const vector& debug_info_root_paths, + const vector& debug_info_root_paths, environment& env, corpus::origin requested_fe_kind, bool show_all_types, diff --git a/tests/print-diff-tree.cc b/tests/print-diff-tree.cc index aa23a6b5..2a54591b 100644 --- a/tests/print-diff-tree.cc +++ b/tests/print-diff-tree.cc @@ -104,7 +104,7 @@ main(int argc, char* argv[]) corpus_sptr c1, c2; environment env; - vector di_roots; + vector di_roots; c1 = dwarf::read_corpus_from_elf(opts.elf1, di_roots, env, /*load_all_types=*/false, c1_status); diff --git a/tests/test-diff-dwarf.cc b/tests/test-diff-dwarf.cc index a4e8de01..34b18897 100644 --- a/tests/test-diff-dwarf.cc +++ b/tests/test-diff-dwarf.cc @@ -385,7 +385,7 @@ main() abigail::fe_iface::STATUS_UNKNOWN; environment env; - std::vector di_roots; + std::vector di_roots; abigail::corpus_sptr corp0 = dwarf::read_corpus_from_elf(in_elfv0_path, /*debug_info_root_path=*/di_roots, diff --git a/tests/test-ir-walker.cc b/tests/test-ir-walker.cc index 362a541d..5eca6cd3 100644 --- a/tests/test-ir-walker.cc +++ b/tests/test-ir-walker.cc @@ -160,7 +160,7 @@ main(int argc, char **argv) abigail::ir::environment env; abigail::corpus_sptr c; abigail::fe_iface::status status = abigail::fe_iface::STATUS_OK; - std::vector di_roots; + std::vector di_roots; if (!(c = dwarf::read_corpus_from_elf(file_name, di_roots, env, /*load_all_type=*/false, status))) diff --git a/tests/test-read-btf.cc b/tests/test-read-btf.cc index b42e717a..abadca29 100644 --- a/tests/test-read-btf.cc +++ b/tests/test-read-btf.cc @@ -107,7 +107,7 @@ test_task_btf::perform() abigail::fe_iface::status status = abigail::fe_iface::STATUS_UNKNOWN; - vector di_roots; + vector di_roots; ABG_ASSERT(abigail::tools_utils::file_exists(in_elf_path)); abigail::elf_based_reader_sptr rdr = abigail::btf::create_reader(in_elf_path, diff --git a/tests/test-read-ctf.cc b/tests/test-read-ctf.cc index 381442ff..52e2e9c9 100644 --- a/tests/test-read-ctf.cc +++ b/tests/test-read-ctf.cc @@ -452,7 +452,7 @@ test_task_ctf::perform() abigail::fe_iface::status status = abigail::fe_iface::STATUS_UNKNOWN; - vector di_roots; + vector di_roots; ABG_ASSERT(abigail::tools_utils::file_exists(in_elf_path)); abigail::elf_based_reader_sptr rdr = ctf::create_reader(in_elf_path, diff --git a/tests/test-symtab.cc b/tests/test-symtab.cc index d6a3de40..135c0310 100644 --- a/tests/test-symtab.cc +++ b/tests/test-symtab.cc @@ -48,7 +48,7 @@ read_corpus(const std::string& path, const std::string& absolute_path = test_data_dir + path; environment env; - const std::vector debug_info_root_paths; + const std::vector debug_info_root_paths; abigail::elf_based_reader_sptr rdr = dwarf::create_reader(absolute_path, debug_info_root_paths, env, /* load_all_type = */ true, diff --git a/tools/abicompat.cc b/tools/abicompat.cc index abe662a9..c6924fd2 100644 --- a/tools/abicompat.cc +++ b/tools/abicompat.cc @@ -85,8 +85,6 @@ using abigail::suppr::suppression_sptr; using abigail::suppr::suppressions_type; using abigail::suppr::read_suppressions; - - class options { options(); @@ -97,9 +95,9 @@ public: string app_path; string lib1_path; string lib2_path; - shared_ptr app_di_root_path; - shared_ptr lib1_di_root_path; - shared_ptr lib2_di_root_path; + string app_di_root_path; + string lib1_di_root_path; + string lib2_di_root_path; vector suppression_paths; bool display_help; bool display_version; @@ -295,7 +293,7 @@ parse_command_line(int argc, char* argv[], options& opts) // elfutils wants the root path to the debug info to be // absolute. opts.app_di_root_path = - abigail::tools_utils::make_path_absolute(argv[i + 1]); + abigail::tools_utils::make_path_absolute(string(argv[i + 1])); ++i; } else if (!strcmp(argv[i], "--lib-debug-info-dir1") @@ -307,7 +305,7 @@ parse_command_line(int argc, char* argv[], options& opts) // elfutils wants the root path to the debug info to be // absolute. opts.lib1_di_root_path = - abigail::tools_utils::make_path_absolute(argv[i + 1]); + abigail::tools_utils::make_path_absolute(string(argv[i + 1])); ++i; } else if (!strcmp(argv[i], "--lib-debug-info-dir2") @@ -319,7 +317,7 @@ parse_command_line(int argc, char* argv[], options& opts) // elfutils wants the root path to the debug info to be // absolute. opts.lib2_di_root_path = - abigail::tools_utils::make_path_absolute(argv[i + 1]); + abigail::tools_utils::make_path_absolute(string(argv[i + 1])); ++i; } else if (!strcmp(argv[i], "--suppressions") @@ -849,7 +847,7 @@ perform_compat_check_in_weak_mode(options& opts, static corpus_sptr read_corpus(options opts, abigail::fe_iface::status& status, - const vector di_roots, + const vector di_roots, environment &env, const string &path) { @@ -982,9 +980,10 @@ main(int argc, char* argv[]) return abigail::tools_utils::ABIDIFF_OK; // Read the application ELF file. - char * app_di_root = opts.app_di_root_path.get(); - vector app_di_roots; - app_di_roots.push_back(&app_di_root); + string& app_di_root = opts.app_di_root_path; + vector app_di_roots; + if (!app_di_root.empty()) + app_di_roots.push_back(app_di_root); abigail::fe_iface::status status = abigail::fe_iface::STATUS_UNKNOWN; environment env; @@ -1042,9 +1041,10 @@ main(int argc, char* argv[]) if (!abigail::tools_utils::check_file(opts.lib1_path, cerr, opts.prog_name)) return abigail::tools_utils::ABIDIFF_ERROR; - char * lib1_di_root = opts.lib1_di_root_path.get(); - vector lib1_di_roots; - lib1_di_roots.push_back(&lib1_di_root); + string& lib1_di_root = opts.lib1_di_root_path; + vector lib1_di_roots; + if (!lib1_di_root.empty()) + lib1_di_roots.push_back(lib1_di_root); corpus_sptr lib1_corpus = read_corpus(opts, status, lib1_di_roots, env, opts.lib1_path); @@ -1077,9 +1077,10 @@ main(int argc, char* argv[]) if (!opts.weak_mode) { ABG_ASSERT(!opts.lib2_path.empty()); - char * lib2_di_root = opts.lib2_di_root_path.get(); - vector lib2_di_roots; - lib2_di_roots.push_back(&lib2_di_root); + string& lib2_di_root = opts.lib2_di_root_path; + vector lib2_di_roots; + if (!lib2_di_root.empty()) + lib2_di_roots.push_back(lib2_di_root); lib2_corpus = read_corpus(opts, status, lib2_di_roots, env, opts.lib2_path); diff --git a/tools/abidiff.cc b/tools/abidiff.cc index c1c16b87..8c85d4a3 100644 --- a/tools/abidiff.cc +++ b/tools/abidiff.cc @@ -138,10 +138,8 @@ struct options #ifdef WITH_BTF bool use_btf; #endif - vector di_root_paths1; - vector di_root_paths2; - vector prepared_di_root_paths1; - vector prepared_di_root_paths2; + vector di_root_paths1; + vector di_root_paths2; vector added_bins_dirs1; vector added_bins_dirs2; vector added_bins1; @@ -209,18 +207,6 @@ struct options ~options() { - for (vector::iterator i = di_root_paths1.begin(); - i != di_root_paths1.end(); - ++i) - free(*i); - - for (vector::iterator i = di_root_paths2.begin(); - i != di_root_paths2.end(); - ++i) - free(*i); - - prepared_di_root_paths1.clear(); - prepared_di_root_paths2.clear(); } };//end struct options; @@ -371,7 +357,7 @@ parse_command_line(int argc, char* argv[], options& opts) // elfutils wants the root path to the debug info to be // absolute. opts.di_root_paths1.push_back - (abigail::tools_utils::make_path_absolute_to_be_freed(argv[j])); + (abigail::tools_utils::make_path_absolute(string(argv[j]))); ++i; } else if (!strcmp(argv[i], "--debug-info-dir2") @@ -1094,21 +1080,6 @@ adjust_diff_context_for_kmidiff(diff_context &ctxt) ctxt.show_linkage_names(false); } -/// Convert options::di_root_paths{1,2} into -/// options::prepared_di_root_paths{1,2} which is the suitable type -/// format that the dwarf_reader expects. -/// -/// @param o the options to consider. -static void -prepare_di_root_paths(options& o) -{ - abigail::tools_utils::convert_char_stars_to_char_star_stars - (o.di_root_paths1, o.prepared_di_root_paths1); - - abigail::tools_utils::convert_char_stars_to_char_star_stars - (o.di_root_paths2, o.prepared_di_root_paths2); -} - /// Emit an appropriate error message if necessary, given an error /// code. /// @@ -1156,7 +1127,7 @@ handle_error(abigail::fe_iface::status status_code, emit_prefix(prog_name, cerr) << "could not find the debug info\n"; { - if (opts.prepared_di_root_paths1.empty() == 0) + if (opts.di_root_paths1.empty() == 0) emit_prefix(prog_name, cerr) << "Maybe you should consider using the " "--debug-info-dir1 option to tell me about the " @@ -1166,21 +1137,21 @@ handle_error(abigail::fe_iface::status status_code, { emit_prefix(prog_name, cerr) << "Maybe the root path to the debug information '"; - for (vector::const_iterator i - = opts.prepared_di_root_paths1.begin(); - i != opts.prepared_di_root_paths1.end(); + for (vector::const_iterator i + = opts.di_root_paths1.begin(); + i != opts.di_root_paths1.end(); ++i) { - if (i != opts.prepared_di_root_paths1.end()) + if (i != opts.di_root_paths1.end()) cerr << ", "; - cerr << **i; + cerr << *i; } cerr << "' is wrong?\n"; } } { - if (opts.prepared_di_root_paths2.empty()) + if (opts.di_root_paths2.empty()) emit_prefix(prog_name, cerr) << "Maybe you should consider using the " "--debug-info-dir2 option to tell me about the " @@ -1190,14 +1161,14 @@ handle_error(abigail::fe_iface::status status_code, { emit_prefix(prog_name, cerr) << "Maybe the root path to the debug information '"; - for (vector::const_iterator i - = opts.prepared_di_root_paths2.begin(); - i != opts.prepared_di_root_paths2.end(); + for (vector::const_iterator i + = opts.di_root_paths2.begin(); + i != opts.di_root_paths2.end(); ++i) { - if (i != opts.prepared_di_root_paths2.end()) + if (i != opts.di_root_paths2.end()) cerr << ", "; - cerr << **i; + cerr << *i; } cerr << "' is wrong?\n"; } @@ -1350,8 +1321,6 @@ main(int argc, char* argv[]) return 0; } - prepare_di_root_paths(opts); - if (!maybe_check_suppression_files(opts)) return (abigail::tools_utils::ABIDIFF_USAGE_ERROR | abigail::tools_utils::ABIDIFF_ERROR); @@ -1427,7 +1396,7 @@ main(int argc, char* argv[]) #endif abigail::elf_based_reader_sptr rdr = create_best_elf_based_reader(opts.file1, - opts.prepared_di_root_paths1, + opts.di_root_paths1, env, requested_fe_kind, opts.show_all_types, opts.linux_kernel_mode); @@ -1518,7 +1487,7 @@ main(int argc, char* argv[]) #endif abigail::elf_based_reader_sptr rdr = create_best_elf_based_reader(opts.file2, - opts.prepared_di_root_paths2, + opts.di_root_paths2, env, requested_fe_kind, opts.show_all_types, opts.linux_kernel_mode); diff --git a/tools/abidw.cc b/tools/abidw.cc index 63fdaddd..61d4f5ee 100644 --- a/tools/abidw.cc +++ b/tools/abidw.cc @@ -87,8 +87,7 @@ struct options string wrong_option; string in_file_path; string out_file_path; - vector di_root_paths; - vector prepared_di_root_paths; + vector di_root_paths; vector headers_dirs; vector header_files; vector added_bins_dirs; @@ -189,12 +188,6 @@ struct options ~options() { - for (vector::iterator i = di_root_paths.begin(); - i != di_root_paths.end(); - ++i) - free(*i); - - prepared_di_root_paths.clear(); } }; @@ -789,7 +782,7 @@ load_corpus_and_write_abixml(char* argv[], // specfied in opts ... abigail::elf_based_reader_sptr reader = create_best_elf_based_reader(opts.in_file_path, - opts.prepared_di_root_paths, + opts.di_root_paths, env, requested_fe_kind, opts.load_all_types, opts.linux_kernel_mode); @@ -865,7 +858,7 @@ load_corpus_and_write_abixml(char* argv[], emit_prefix(argv[0], cerr) << "Could not read debug info for '" << opts.in_file_path << "' from debug info root directory '"; - for (vector::const_iterator i = + for (vector::const_iterator i = opts.di_root_paths.begin(); i != opts.di_root_paths.end(); ++i) @@ -1127,18 +1120,6 @@ load_kernel_corpus_group_and_write_abixml(char* argv[], return exit_code; } -/// Convert options::di_root_paths into -/// options::prepared_di_root_paths which is the suitable type format -/// that the dwarf_reader expects. -/// -/// @param o the options to consider. -static void -prepare_di_root_paths(options& o) -{ - tools_utils::convert_char_stars_to_char_star_stars(o.di_root_paths, - o.prepared_di_root_paths); -} - int main(int argc, char* argv[]) { @@ -1186,8 +1167,6 @@ main(int argc, char* argv[]) return 1; } - prepare_di_root_paths(opts); - if (!maybe_check_suppression_files(opts)) return 1; diff --git a/tools/abilint.cc b/tools/abilint.cc index 7f456fe8..55014328 100644 --- a/tools/abilint.cc +++ b/tools/abilint.cc @@ -86,7 +86,7 @@ struct options #ifdef WITH_CTF bool use_ctf; #endif - std::shared_ptr di_root_path; + string di_root_path; vector suppression_paths; string headers_dir; vector header_files; @@ -544,7 +544,7 @@ parse_command_line(int argc, char* argv[], options& opts) // elfutils wants the root path to the debug info to be // absolute. opts.di_root_path = - abigail::tools_utils::make_path_absolute(argv[i + 1]); + abigail::tools_utils::make_path_absolute(string(argv[i + 1])); ++i; } else if (!strcmp(argv[i], "--headers-dir") @@ -778,7 +778,7 @@ main(int argc, char* argv[]) abigail::corpus_sptr corp; abigail::corpus_group_sptr group; abigail::fe_iface::status s = abigail::fe_iface::STATUS_OK; - char* di_root_path = 0; + string di_root_path; file_type type = guess_file_type(opts.file_path); switch (type) @@ -800,9 +800,9 @@ main(int argc, char* argv[]) case abigail::tools_utils::FILE_TYPE_ELF: case abigail::tools_utils::FILE_TYPE_AR: { - di_root_path = opts.di_root_path.get(); - vector di_roots; - di_roots.push_back(&di_root_path); + di_root_path = opts.di_root_path; + vector di_roots; + di_roots.push_back(di_root_path); abigail::elf_based_reader_sptr rdr; #ifdef WITH_CTF if (opts.use_ctf) @@ -855,7 +855,7 @@ main(int argc, char* argv[]) if (s & abigail::fe_iface::STATUS_DEBUG_INFO_NOT_FOUND) { cerr << "could not find the debug info"; - if(di_root_path == 0) + if(di_root_path.empty()) emit_prefix(argv[0], cerr) << " Maybe you should consider using the " "--debug-info-dir1 option to tell me about the " diff --git a/tools/abipkgdiff.cc b/tools/abipkgdiff.cc index 686e36f2..013285e4 100644 --- a/tools/abipkgdiff.cc +++ b/tools/abipkgdiff.cc @@ -1532,12 +1532,11 @@ compare(const elf_file& elf1, ostream& out, abigail::fe_iface::status* detailed_error_status = 0) { - char *di_dir1 = (char*) debug_dir1.c_str(), - *di_dir2 = (char*) debug_dir2.c_str(); - - vector di_dirs1, di_dirs2; - di_dirs1.push_back(&di_dir1); - di_dirs2.push_back(&di_dir2); + vector di_dirs1, di_dirs2; + if (!debug_dir1.empty()) + di_dirs1.push_back(debug_dir1); + if (!debug_dir2.empty()) + di_dirs2.push_back(debug_dir2); if (opts.verbose) emit_prefix("abipkgdiff", cerr) @@ -1645,8 +1644,8 @@ compare(const elf_file& elf1, << "while reading file" << elf1.path << "\n"; emit_prefix("abipkgdiff", cerr) << "Could not find debug info file"; - if (di_dir1 && strcmp(di_dir1, "")) - cerr << " under " << di_dir1 << "\n"; + if (!debug_dir1.empty()) + cerr << " under " << debug_dir1 << "\n"; else cerr << "\n"; @@ -1734,8 +1733,8 @@ compare(const elf_file& elf1, << "while reading file" << elf2.path << "\n"; emit_prefix("abipkgdiff", cerr) << "Could not find debug info file"; - if (di_dir2 && strcmp(di_dir2, "")) - cerr << " under " << di_dir2 << "\n"; + if (!debug_dir2.empty()) + cerr << " under " << debug_dir2 << "\n"; else cerr << "\n"; @@ -1815,10 +1814,9 @@ compare_to_self(const elf_file& elf, ostream& out, abigail::fe_iface::status* detailed_error_status = 0) { - char *di_dir = (char*) debug_dir.c_str(); - - vector di_dirs; - di_dirs.push_back(&di_dir); + vector di_dirs; + if (!debug_dir.empty()) + di_dirs.push_back(debug_dir); abigail::fe_iface::status c_status = abigail::fe_iface::STATUS_OK;