]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/solib: use early return in solib_read_symbols
authorSimon Marchi <simon.marchi@polymtl.ca>
Tue, 9 Dec 2025 19:32:06 +0000 (14:32 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Fri, 8 May 2026 01:45:42 +0000 (21:45 -0400)
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
Approved-By: Tom Tromey <tom@tromey.com>
gdb/solib.c
gdb/solib.h

index 782b844aa2f9eefe426073d42ef96d159447ad70..158c58d96890d2373228299152054c667de91e3e 100644 (file)
@@ -592,8 +592,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)
@@ -601,52 +600,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
-       {
-         /* 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;
-             }
+  flags |= current_inferior ()->symfile_flags;
 
-         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;
-           }
+  try
+    {
+      /* 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;
+         }
 
-         so.symbols_loaded = true;
-       }
-      catch (const gdb_exception_error &e)
+      if (so.objfile == nullptr)
        {
-         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
index 564655c4a572d3a6f9004d4fee628a597f3797df..9e6c3f7346eebb88ba80fc32de3e60232aedfc73 100644 (file)
@@ -317,7 +317,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