From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ynb5N0x6OGkyTikAWB0awg (envelope-from ) for ; Tue, 09 Dec 2025 14:36:44 -0500 Received: by simark.ca (Postfix, from userid 112) id C28581E0C2; Tue, 09 Dec 2025 14:36:44 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A8D761E08D for ; Tue, 09 Dec 2025 14:36:43 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id BBDF54BA2E06 for ; Tue, 9 Dec 2025 19:36:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBDF54BA2E06 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id B12C34BA2E01 for ; Tue, 9 Dec 2025 19:36:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B12C34BA2E01 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B12C34BA2E01 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1765308975; cv=none; b=X3bxffgVKnmwkECyZ0KkvLX9pM58Oj1BtUD0xdrKkJlSBRjrGynvd9XpN6WNvAOdcdoK1XqavnLAI9vggZCffo72C3FyXwUx6Jbp3+YJJTYnZ9UnkW87v0Fg6dOM3PrDlbh4bhr0BtbrypHK9HBKpdeFHnz+11KpJaL4G8rJ8QQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1765308975; c=relaxed/simple; bh=JmvHHcOlTWr4O0CD724uVMLvHuJOgXqDPMlrdqKCk3E=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Xo4GVWz6taXiEv6YSm2KIiMfAMwTO8tRcnh1pSS0XNZn/K4EG645Drc6Eoka8gagg6sHCg2tcCycZWTxBTDoUPjB6ytPFRwGsLVjJUZXwjSEmHH0MIKukl+wdltI+SqmgbIJFwHdu5VkrKUVgFEaQY5lqPzqwUR6AYcUdBbF/Q0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B12C34BA2E01 Received: by simark.ca (Postfix) id 34DEE1E0B3; Tue, 09 Dec 2025 14:36:15 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 02/11] gdb/solib: use early return in solib_read_symbols Date: Tue, 9 Dec 2025 14:32:06 -0500 Message-ID: <20251209193610.296085-3-simon.marchi@efficios.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251209193610.296085-1-simon.marchi@efficios.com> References: <20251209193610.296085-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Simon Marchi This reduces the indent a bit, and makes it clearer where the "interesting" part of the function is. At the same time, move the comment to solib.h. Change-Id: I8004895757ce296742bcec929799a0ce6041938b --- gdb/solib.c | 73 +++++++++++++++++++++++++---------------------------- gdb/solib.h | 6 ++++- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/gdb/solib.c b/gdb/solib.c index dade2a76a48c..ac674f4e9720 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -621,8 +621,7 @@ solib::clear () lm_info::~lm_info () = default; -/* Read in symbols for shared object SO. If SYMFILE_VERBOSE is set in FLAGS, - be chatty about it. Return true if any symbols were actually loaded. */ +/* See solib.h. */ bool solib_read_symbols (solib &so, symfile_add_flags flags) @@ -630,52 +629,50 @@ solib_read_symbols (solib &so, symfile_add_flags flags) if (so.symbols_loaded) { /* If needed, we've already warned in our caller. */ + return false; } - else if (so.abfd == NULL) + + if (so.abfd == nullptr) { - /* We've already warned about this library, when trying to open - it. */ + /* We've already warned about this library, when trying to open it. */ + return false; } - else + + flags |= current_inferior ()->symfile_flags; + + try { - flags |= current_inferior ()->symfile_flags; + /* Have we already loaded this shared object? */ + so.objfile = nullptr; + for (objfile &objfile : current_program_space->objfiles ()) + if (objfile.addr_low == so.addr_low) + { + so.objfile = &objfile; + break; + } - try + if (so.objfile == nullptr) { - /* Have we already loaded this shared object? */ - so.objfile = nullptr; - for (objfile &objfile : current_program_space->objfiles ()) - if (objfile.addr_low == so.addr_low) - { - so.objfile = &objfile; - break; - } - - if (so.objfile == NULL) - { - section_addr_info sap - = build_section_addr_info_from_section_table (so.sections); - gdb_bfd_ref_ptr tmp_bfd = so.abfd; - so.objfile - = symbol_file_add_from_bfd (tmp_bfd, so.name.c_str (), - flags, &sap, OBJF_SHARED, nullptr); - so.objfile->addr_low = so.addr_low; - } - - so.symbols_loaded = true; - } - catch (const gdb_exception_error &e) - { - exception_fprintf (gdb_stderr, e, - _("Error while reading shared" - " library symbols for %s:\n"), - so.name.c_str ()); + section_addr_info sap + = build_section_addr_info_from_section_table (so.sections); + gdb_bfd_ref_ptr tmp_bfd = so.abfd; + so.objfile = symbol_file_add_from_bfd (tmp_bfd, so.name.c_str (), + flags, &sap, OBJF_SHARED, + nullptr); + so.objfile->addr_low = so.addr_low; } - return true; + so.symbols_loaded = true; + } + catch (const gdb_exception_error &e) + { + exception_fprintf (gdb_stderr, e, + _("Error while reading shared" + " library symbols for %s:\n"), + so.name.c_str ()); } - return false; + return true; } /* Return true if KNOWN->objfile is used by any other solib object diff --git a/gdb/solib.h b/gdb/solib.h index 85ea6675b799..92a485dbca4c 100644 --- a/gdb/solib.h +++ b/gdb/solib.h @@ -318,7 +318,11 @@ extern void clear_solib (program_space *pspace); /* Called to add symbols from a shared library to gdb's symbol table. */ extern void solib_add (const char *, int, int); -extern bool solib_read_symbols (solib &, symfile_add_flags); + +/* Read in symbols for shared object SO. If SYMFILE_VERBOSE is set in FLAGS, + be chatty about it. Return true if any symbols were actually loaded. */ + +extern bool solib_read_symbols (solib &so, symfile_add_flags flags); /* Function to be called when the inferior starts up, to discover the names of shared libraries that are dynamically linked, the base -- 2.52.0