[6/7] Use bound_minimal_symbol more in lookup_minimal_symbol_by_pc_section

Message ID 20240217-dwarf-race-relocate-v1-6-d3d2d908c1e8@tromey.com
State New
Headers
Series Fix race in DWARF reader |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Testing failed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Testing failed

Commit Message

Tom Tromey Feb. 18, 2024, 1:10 a.m. UTC
  lookup_minimal_symbol_by_pc_section tracks the best symbol and
objfile.  This patch changes it to use a bound_minimal_symbol rather
than two separate variables.  This simplifies the code a little.
---
 gdb/minsyms.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)
  

Patch

diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 2c8bf2a9f0b..64f085a0314 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -968,9 +968,7 @@  lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
 				     lookup_msym_prefer prefer,
 				     bound_minimal_symbol *previous)
 {
-  struct minimal_symbol *best_symbol = NULL;
-  struct objfile *best_objfile = NULL;
-  struct bound_minimal_symbol result;
+  struct bound_minimal_symbol best = {};
 
   if (previous != nullptr)
     {
@@ -1036,18 +1034,13 @@  lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
       /* MINSYM now is the best one in this objfile's minimal symbol
 	 table.  See if it is the best one overall.  */
       if (minsym != nullptr
-	  && ((best_symbol == NULL) ||
-	      (best_symbol->unrelocated_address ()
-	       < minsym->unrelocated_address ())))
-	{
-	  best_symbol = minsym;
-	  best_objfile = objfile;
-	}
+	  && (best.minsym == nullptr
+	      || (best.minsym->unrelocated_address ()
+		  < minsym->unrelocated_address ())))
+	best = { minsym, objfile };
     }
 
-  result.minsym = best_symbol;
-  result.objfile = best_objfile;
-  return result;
+  return best;
 }
 
 /* See minsyms.h.  */