From: Simon Marchi Date: Tue, 9 Dec 2025 19:32:06 +0000 (-0500) Subject: gdb/solib: use early return in solib_read_symbols X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c8a24a41f39519ca2ed0f28d023fa05666ac899;p=thirdparty%2Fbinutils-gdb.git gdb/solib: use early return in solib_read_symbols 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 --- diff --git a/gdb/solib.c b/gdb/solib.c index 782b844aa2f..158c58d9689 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -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 diff --git a/gdb/solib.h b/gdb/solib.h index 564655c4a57..9e6c3f7346e 100644 --- a/gdb/solib.h +++ b/gdb/solib.h @@ -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