Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 02/11] gdb/solib: use early return in solib_read_symbols
Date: Tue,  9 Dec 2025 14:32:06 -0500	[thread overview]
Message-ID: <20251209193610.296085-3-simon.marchi@efficios.com> (raw)
In-Reply-To: <20251209193610.296085-1-simon.marchi@efficios.com>

From: Simon Marchi <simon.marchi@polymtl.ca>

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


  parent reply	other threads:[~2025-12-09 19:36 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-09 19:32 [PATCH 00/11] Multiple solib_ops in a program_space Simon Marchi
2025-12-09 19:32 ` [PATCH 01/11] gdb/solib-rocm: assert that host ops isn't rocm_solib_ops Simon Marchi
2026-05-07 17:56   ` [PATCH 1/11] " Lancelot SIX
2026-05-08  1:37     ` Simon Marchi
2026-05-08 10:36       ` Lancelot SIX
2026-06-08 18:36         ` Simon Marchi
2025-12-09 19:32 ` Simon Marchi [this message]
2026-04-28 16:16   ` [PATCH 02/11] gdb/solib: use early return in solib_read_symbols Tom Tromey
2026-05-08  1:44     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 03/11] gdb/solib-rocm: pass reference to cache to rocm_code_object_stream_file Simon Marchi
2026-05-07 18:20   ` [PATCH 3/11] " Lancelot SIX
2026-05-08  1:48     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 04/11] gdb/solib-rocm: add cached_fd to manage cached fd lifetime Simon Marchi
2026-05-07 20:17   ` [PATCH 4/11] " Lancelot SIX
2026-05-08  1:52     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 05/11] gdb: de-constify some methods of solib_ops Simon Marchi
2025-12-09 19:32 ` [PATCH 06/11] gdb/solib-rocm: move per-inferior data to rocm_solib_ops Simon Marchi
2026-04-28 16:19   ` Tom Tromey
2026-05-08  2:02     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 07/11] gdb/solib-rocm: save inferior in rocm_solib_ops Simon Marchi
     [not found]   ` <87a4unm59w.fsf@tromey.com>
2026-05-08  2:10     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 08/11] gdb/solib: add remove_solib function Simon Marchi
2026-04-28 16:23   ` Tom Tromey
2025-12-09 19:32 ` [PATCH 09/11] gdb: add objfile -> solib backlink Simon Marchi
2026-04-28 16:28   ` Tom Tromey
2026-05-08  2:25     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 10/11] gdb: change default objfile iteration order to start with current objfile Simon Marchi
2026-04-28 16:42   ` Tom Tromey
2026-05-08  2:40     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 11/11] gdb: multiple solib_ops per program space Simon Marchi
2026-04-28 17:27   ` Tom Tromey
2026-05-08  2:52     ` Simon Marchi
2026-04-28 16:00 ` [PATCH 00/11] Multiple solib_ops in a program_space Simon Marchi
2026-04-28 17:28   ` Tom Tromey
2026-05-08  2:40     ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251209193610.296085-3-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox