[4/7] gdb: add program_space parameter to lookup_minimal_symbol

Message ID 20240717035307.2299961-5-simon.marchi@polymtl.ca
State New
Headers
Series Some more passing down program space |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

Simon Marchi July 17, 2024, 3:52 a.m. UTC
  From what I can see, lookup_minimal_symbol doesn't have any dependencies
on the global current state other than the single reference to
current_program_space.  Add a program_space parameter and make that
current_program_space reference bubble up one level.

Change-Id: I759415e2f9c74c9627a2fe05bd44eb4147eee6fe
---
 gdb/ada-lang.c                      |  9 ++++++---
 gdb/ada-tasks.c                     |  7 ++++---
 gdb/aix-thread.c                    |  6 ++++--
 gdb/arc-linux-tdep.c                |  3 ++-
 gdb/arm-tdep.c                      |  5 +++--
 gdb/auxv.c                          |  3 ++-
 gdb/avr-tdep.c                      |  2 +-
 gdb/ax-gdb.c                        |  3 ++-
 gdb/breakpoint.c                    |  3 ++-
 gdb/bsd-uthread.c                   |  3 ++-
 gdb/c-exp.y                         |  4 ++--
 gdb/coff-pe-read.c                  |  6 ++++--
 gdb/coffread.c                      |  3 ++-
 gdb/compile/compile-c-symbols.c     |  6 ++++--
 gdb/compile/compile-cplus-symbols.c |  3 ++-
 gdb/compile/compile-object-load.c   |  3 ++-
 gdb/ctfread.c                       |  3 ++-
 gdb/d-exp.y                         |  2 +-
 gdb/d-lang.c                        |  3 ++-
 gdb/dbxread.c                       | 16 +++++++++------
 gdb/dwarf2/loc.c                    |  3 ++-
 gdb/elfread.c                       |  3 ++-
 gdb/eval.c                          |  3 ++-
 gdb/fbsd-tdep.c                     |  6 ++++--
 gdb/findvar.c                       |  3 ++-
 gdb/frame.c                         |  3 ++-
 gdb/frv-tdep.c                      |  3 ++-
 gdb/ft32-tdep.c                     |  3 ++-
 gdb/gcore.c                         |  5 +++--
 gdb/glibc-tdep.c                    |  8 +++++---
 gdb/gnu-v3-abi.c                    |  5 +++--
 gdb/go-exp.y                        |  2 +-
 gdb/go-lang.c                       |  3 ++-
 gdb/hppa-tdep.c                     |  3 ++-
 gdb/linux-fork.c                    | 12 ++++++++----
 gdb/linux-thread-db.c               |  6 ++++--
 gdb/m32c-tdep.c                     | 11 +++++++----
 gdb/m32r-tdep.c                     |  3 ++-
 gdb/m68hc11-tdep.c                  |  3 ++-
 gdb/machoread.c                     |  3 ++-
 gdb/minsyms.c                       | 11 +++++++----
 gdb/minsyms.h                       |  4 +++-
 gdb/mips-fbsd-tdep.c                |  3 ++-
 gdb/mips-linux-tdep.c               |  2 +-
 gdb/netbsd-tdep.c                   |  3 ++-
 gdb/objc-lang.c                     | 30 +++++++++++++++++++----------
 gdb/obsd-tdep.c                     |  3 ++-
 gdb/p-exp.y                         |  2 +-
 gdb/p-lang.c                        |  9 ++++++---
 gdb/parse.c                         |  6 ++++--
 gdb/ppc-sysv-tdep.c                 |  3 ++-
 gdb/printcmd.c                      |  6 ++++--
 gdb/proc-service.c                  |  3 ++-
 gdb/ravenscar-thread.c              | 15 +++++++++------
 gdb/remote.c                        |  3 ++-
 gdb/sol-thread.c                    |  3 ++-
 gdb/sol2-tdep.c                     |  3 ++-
 gdb/solib-dsbt.c                    |  2 +-
 gdb/solib-frv.c                     |  5 +++--
 gdb/solib-svr4.c                    |  7 ++++---
 gdb/symfile.c                       |  9 ++++++---
 gdb/tracepoint.c                    |  3 ++-
 gdb/tui/tui-disasm.c                |  2 +-
 gdb/valops.c                        |  3 ++-
 gdb/value.c                         |  5 +++--
 gdb/z80-tdep.c                      | 12 +++++++-----
 66 files changed, 218 insertions(+), 123 deletions(-)
  

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 8fddb17b89e5..0fb636492326 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -806,7 +806,8 @@  ada_main_name ()
      that string, then most probably the main procedure is not written
      in Ada.  */
   bound_minimal_symbol msym
-    = lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME);
+    = lookup_minimal_symbol (current_program_space,
+			     ADA_MAIN_PROGRAM_SYMBOL_NAME);
 
   if (msym.minsym != NULL)
     {
@@ -11703,7 +11704,8 @@  ada_has_this_exception_support (const struct exception_support_info *einfo)
 	 the catchpoint message, and is also used when trying to catch
 	 a specific exception).  We do not handle this case for now.  */
       bound_minimal_symbol msym
-	= lookup_minimal_symbol (einfo->catch_exception_sym);
+	= lookup_minimal_symbol (current_program_space,
+				 einfo->catch_exception_sym);
 
       if (msym.minsym && msym.minsym->type () != mst_solib_trampoline)
 	error (_("Your Ada runtime appears to be missing some debugging "
@@ -11723,7 +11725,8 @@  ada_has_this_exception_support (const struct exception_support_info *einfo)
   if (sym == NULL)
     {
       bound_minimal_symbol msym
-	= lookup_minimal_symbol (einfo->catch_handlers_sym);
+	= lookup_minimal_symbol (current_program_space,
+				 einfo->catch_handlers_sym);
 
       if (msym.minsym && msym.minsym->type () != mst_solib_trampoline)
 	error (_("Your Ada runtime appears to be missing some debugging "
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 43a63f863559..01ee2fb5686c 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -600,7 +600,7 @@  ada_get_tcb_types_info (void)
 
   /* Check for the CPU offset.  */
   bound_minimal_symbol first_id_sym
-    = lookup_minimal_symbol ("__gnat_gdb_cpu_first_id");
+    = lookup_minimal_symbol (current_program_space, "__gnat_gdb_cpu_first_id");
   unsigned int first_id = 0;
   if (first_id_sym.minsym != nullptr)
     {
@@ -920,7 +920,8 @@  ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
 
   /* Try array.  */
 
-  bound_minimal_symbol msym = lookup_minimal_symbol (KNOWN_TASKS_NAME);
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, KNOWN_TASKS_NAME);
   if (msym.minsym != NULL)
     {
       data->known_tasks_kind = ADA_TASKS_ARRAY;
@@ -967,7 +968,7 @@  ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
 
   /* Try list.  */
 
-  msym = lookup_minimal_symbol (KNOWN_TASKS_LIST);
+  msym = lookup_minimal_symbol (current_program_space, KNOWN_TASKS_LIST);
   if (msym.minsym != NULL)
     {
       data->known_tasks_kind = ADA_TASKS_LIST;
diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index 847c9006616f..9e6952b974f4 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -395,7 +395,8 @@  pdc_symbol_addrs (pthdb_user_t user_current_pid, pthdb_symbol_t *symbols, int co
 	symbols[i].addr = 0;
       else
 	{
-	  bound_minimal_symbol ms = lookup_minimal_symbol (name);
+	  bound_minimal_symbol ms
+	    = lookup_minimal_symbol (current_program_space, name);
 	  if (ms.minsym == NULL)
 	    {
 	      if (debug_aix_thread)
@@ -978,7 +979,8 @@  pd_enable (inferior *inf)
     return;
 
   /* Set a breakpoint on the returned stub function.  */
-  bound_minimal_symbol ms = lookup_minimal_symbol (stub_name);
+  bound_minimal_symbol ms
+    = lookup_minimal_symbol (current_program_space, stub_name);
   if (ms.minsym == NULL)
     return;
   data->pd_brk_addr = ms.value_address ();
diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c
index d71c5bf0185d..01c591fd4ff0 100644
--- a/gdb/arc-linux-tdep.c
+++ b/gdb/arc-linux-tdep.c
@@ -506,7 +506,8 @@  arc_linux_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
 
      So we look for the symbol `_dl_linux_resolver', and if we are there,
      gdb sets a breakpoint at the return address, and continues.  */
-  bound_minimal_symbol resolver = lookup_minimal_symbol ("_dl_linux_resolver");
+  bound_minimal_symbol resolver
+    = lookup_minimal_symbol (current_program_space, "_dl_linux_resolver");
 
   if (arc_debug)
     {
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index f3db28925059..d1269088d129 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -9388,7 +9388,8 @@  arm_skip_cmse_entry (CORE_ADDR pc, const char *name, struct objfile *objfile)
   char *target_name = (char *) alloca (target_len);
   xsnprintf (target_name, target_len, "%s%s", "__acle_se_", name);
 
-  bound_minimal_symbol minsym = lookup_minimal_symbol (target_name, objfile);
+  bound_minimal_symbol minsym
+    = lookup_minimal_symbol (current_program_space, target_name, objfile);
   if (minsym.minsym != nullptr)
     return minsym.value_address ();
 
@@ -9477,7 +9478,7 @@  arm_skip_stub (const frame_info_ptr &frame, CORE_ADDR pc)
       sec = find_pc_section (pc);
       objfile = (sec == NULL) ? NULL : sec->objfile;
       bound_minimal_symbol minsym
-	= lookup_minimal_symbol (target_name, objfile);
+	= lookup_minimal_symbol (current_program_space, target_name, objfile);
       if (minsym.minsym != NULL)
 	return minsym.value_address ();
       else
diff --git a/gdb/auxv.c b/gdb/auxv.c
index 8d259696ea3e..8bcd347632bf 100644
--- a/gdb/auxv.c
+++ b/gdb/auxv.c
@@ -90,7 +90,8 @@  ld_so_xfer_auxv (gdb_byte *readbuf,
   LONGEST retval;
   size_t block;
 
-  bound_minimal_symbol msym = lookup_minimal_symbol ("_dl_auxv");
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, "_dl_auxv");
   if (msym.minsym == NULL)
     return TARGET_XFER_E_IO;
 
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index dc1eb61be1c5..9c97d3cf1c70 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -623,7 +623,7 @@  avr_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
       pc_offset += 2;
 
       bound_minimal_symbol msymbol
-	= lookup_minimal_symbol ("__prologue_saves__");
+	= lookup_minimal_symbol (current_program_space, "__prologue_saves__");
       if (!msymbol.minsym)
 	break;
 
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index db4dcc2e1d12..3d619012b4fe 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -599,7 +599,8 @@  gen_var_ref (struct agent_expr *ax, struct axs_value *value, struct symbol *var)
     case LOC_UNRESOLVED:
       {
 	bound_minimal_symbol msym
-	  = lookup_minimal_symbol (var->linkage_name ());
+	  = lookup_minimal_symbol (current_program_space,
+				   var->linkage_name ());
 	if (!msym.minsym)
 	  error (_("Couldn't resolve symbol `%s'."), var->print_name ());
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index e5d54d78b9ef..cca17356b70d 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3754,7 +3754,8 @@  create_std_terminate_master_breakpoint (void)
 	  if (bp_objfile_data->terminate_msym.minsym == NULL)
 	    {
 	      bound_minimal_symbol m
-		= lookup_minimal_symbol (func_name, objfile);
+		= lookup_minimal_symbol (current_program_space, func_name,
+					 objfile);
 	      if (m.minsym == NULL || (m.minsym->type () != mst_text
 				       && m.minsym->type () != mst_file_text))
 		{
diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
index d5beba2e8114..eb1ed421abc3 100644
--- a/gdb/bsd-uthread.c
+++ b/gdb/bsd-uthread.c
@@ -157,7 +157,8 @@  static int bsd_uthread_active;
 static CORE_ADDR
 bsd_uthread_lookup_address (const char *name, struct objfile *objfile)
 {
-  bound_minimal_symbol sym = lookup_minimal_symbol (name, objfile);
+  bound_minimal_symbol sym
+    = lookup_minimal_symbol (current_program_space, name, objfile);
   if (sym.minsym)
     return sym.value_address ();
 
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index a06a00007bce..ca411dc0f5b0 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1210,7 +1210,7 @@  variable:	name_not_typename
 			      std::string arg = copy_name ($1.stoken);
 
 			      bound_minimal_symbol msymbol
-				= lookup_minimal_symbol (arg.c_str ());
+				= lookup_minimal_symbol (current_program_space, arg.c_str ());
 			      if (msymbol.minsym == NULL)
 				{
 				  if (!have_full_symbols (current_program_space)
@@ -3150,7 +3150,7 @@  classify_name (struct parser_state *par_state, const struct block *block,
   if (bsym.symbol == NULL
       && par_state->language ()->la_language == language_cplus
       && is_a_field_of_this.type == NULL
-      && lookup_minimal_symbol (copy.c_str ()).minsym == nullptr)
+      && lookup_minimal_symbol (current_program_space, copy.c_str ()).minsym == nullptr)
     return UNKNOWN_CPP_NAME;
 
   return NAME;
diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c
index 9cfa1a372976..ed5e533a3627 100644
--- a/gdb/coff-pe-read.c
+++ b/gdb/coff-pe-read.c
@@ -183,14 +183,16 @@  add_pe_forwarded_sym (minimal_symbol_reader &reader,
 						      forward_func_name);
 
   bound_minimal_symbol msymbol
-    = lookup_minimal_symbol (forward_qualified_name.c_str ());
+    = lookup_minimal_symbol (current_program_space,
+			     forward_qualified_name.c_str ());
   if (!msymbol.minsym)
     {
       int i;
 
       for (i = 0; i < forward_dll_name_len; i++)
 	forward_qualified_name[i] = tolower (forward_qualified_name[i]);
-      msymbol = lookup_minimal_symbol (forward_qualified_name.c_str ());
+      msymbol = lookup_minimal_symbol (current_program_space,
+				       forward_qualified_name.c_str ());
     }
 
   if (!msymbol.minsym)
diff --git a/gdb/coffread.c b/gdb/coffread.c
index be1e21e8364e..3e67ebdef077 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -579,7 +579,8 @@  coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms,
 		    name1 += 1;
 
 		  bound_minimal_symbol found
-		    = lookup_minimal_symbol (name1, objfile);
+		    = lookup_minimal_symbol (current_program_space, name1,
+					     objfile);
 
 		  /* If found, there are symbols named "_imp_foo" and "foo"
 		     respectively in OBJFILE.  Set the type of symbol "foo"
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index e2af722c8170..7a38d3a6d593 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -355,7 +355,8 @@  gcc_convert_symbol (void *datum,
 	}
       else if (request == GCC_C_ORACLE_SYMBOL)
 	{
-	  bound_minimal_symbol bmsym = lookup_minimal_symbol (identifier);
+	  bound_minimal_symbol bmsym
+	    = lookup_minimal_symbol (current_program_space, identifier);
 	  if (bmsym.minsym != NULL)
 	    {
 	      convert_symbol_bmsym (context, bmsym);
@@ -410,7 +411,8 @@  gcc_symbol_address (void *datum, struct gcc_c_context *gcc_context,
 	}
       else
 	{
-	  bound_minimal_symbol msym = lookup_minimal_symbol (identifier);
+	  bound_minimal_symbol msym
+	    = lookup_minimal_symbol (current_program_space, identifier);
 	  if (msym.minsym != NULL)
 	    {
 	      if (compile_debug)
diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c
index 7e251a6ef0a2..6c482e74be60 100644
--- a/gdb/compile/compile-cplus-symbols.c
+++ b/gdb/compile/compile-cplus-symbols.c
@@ -453,7 +453,8 @@  gcc_cplus_symbol_address (void *datum, struct gcc_cp_context *gcc_context,
 	}
       else
 	{
-	  bound_minimal_symbol msym = lookup_minimal_symbol (identifier);
+	  bound_minimal_symbol msym
+	    = lookup_minimal_symbol (current_program_space, identifier);
 	  if (msym.minsym != nullptr)
 	    {
 	      if (compile_debug)
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index cb690863107a..df48b1c54f5b 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -764,7 +764,8 @@  compile_object_load (const compile_file_names &file_names,
 	  continue;
 	}
 
-      bound_minimal_symbol bmsym = lookup_minimal_symbol (sym->name);
+      bound_minimal_symbol bmsym
+	= lookup_minimal_symbol (current_program_space, sym->name);
       switch (bmsym.minsym == NULL
 	      ? mst_unknown : bmsym.minsym->type ())
 	{
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index eb7cf3110e0d..9eb9537ef41c 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -323,7 +323,8 @@  get_bitsize (ctf_dict_t *fp, ctf_id_t tid, uint32_t kind)
 static void
 set_symbol_address (struct objfile *of, struct symbol *sym, const char *name)
 {
-  bound_minimal_symbol msym = lookup_minimal_symbol (name, of);
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, name, of);
   if (msym.minsym != NULL)
     {
       sym->set_value_address (msym.value_address ());
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index 9fc63afaa1c1..df89cb63a35d 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -464,7 +464,7 @@  PrimaryExpression:
 		    {
 		      /* Lookup foreign name in global static symbols.  */
 		      bound_minimal_symbol msymbol
-			= lookup_minimal_symbol (copy.c_str ());
+			= lookup_minimal_symbol (current_program_space, copy.c_str ());
 		      if (msymbol.minsym != NULL)
 			pstate->push_new<var_msym_value_operation> (msymbol);
 		      else if (!have_full_symbols (current_program_space)
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 11c5c03a3cdf..32d9cc86eef0 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -38,7 +38,8 @@  static const char D_MAIN[] = "D main";
 const char *
 d_main_name (void)
 {
-  bound_minimal_symbol msym = lookup_minimal_symbol (D_MAIN);
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, D_MAIN);
   if (msym.minsym != NULL)
     return D_MAIN;
 
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 4b2a7d229ff1..31eb51faa73e 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -907,7 +907,8 @@  find_stab_function (const char *namestring, const char *filename,
   strncpy (p, namestring, n);
   p[n] = 0;
 
-  bound_minimal_symbol msym = lookup_minimal_symbol (p, objfile, filename);
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, p, objfile, filename);
   if (msym.minsym == NULL)
     {
       /* Sun Fortran appends an underscore to the minimal symbol name,
@@ -915,21 +916,22 @@  find_stab_function (const char *namestring, const char *filename,
 	 was not found.  */
       p[n] = '_';
       p[n + 1] = 0;
-      msym = lookup_minimal_symbol (p, objfile, filename);
+      msym
+	= lookup_minimal_symbol (current_program_space, p, objfile, filename);
     }
 
   if (msym.minsym == NULL && filename != NULL)
     {
       /* Try again without the filename.  */
       p[n] = 0;
-      msym = lookup_minimal_symbol (p, objfile);
+      msym = lookup_minimal_symbol (current_program_space, p, objfile);
     }
   if (msym.minsym == NULL && filename != NULL)
     {
       /* And try again for Sun Fortran, but without the filename.  */
       p[n] = '_';
       p[n + 1] = 0;
-      msym = lookup_minimal_symbol (p, objfile);
+      msym = lookup_minimal_symbol (current_program_space, p, objfile);
     }
 
   return msym;
@@ -2044,7 +2046,8 @@  dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
       p[n] = 0;
 
       bound_minimal_symbol minsym
-	= lookup_minimal_symbol (p, objfile, pst->filename);
+	= lookup_minimal_symbol (current_program_space, p, objfile,
+				 pst->filename);
       if (minsym.minsym == NULL)
 	{
 	  /* Sun Fortran appends an underscore to the minimal symbol name,
@@ -2052,7 +2055,8 @@  dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
 	     was not found.  */
 	  p[n] = '_';
 	  p[n + 1] = 0;
-	  minsym = lookup_minimal_symbol (p, objfile, pst->filename);
+	  minsym = lookup_minimal_symbol (current_program_space, p, objfile,
+					  pst->filename);
 	}
 
       if (minsym.minsym)
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 06e57be891b0..80c86bb850f7 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -710,7 +710,8 @@  call_site_target::iterate_over_addresses (gdbarch *call_site_gdbarch,
 	physname = m_loc.physname;
 
 	/* Handle both the mangled and demangled PHYSNAME.  */
-	bound_minimal_symbol msym = lookup_minimal_symbol (physname);
+	bound_minimal_symbol msym
+	  = lookup_minimal_symbol (current_program_space, physname);
 	if (msym.minsym == NULL)
 	  {
 	    msym = lookup_minimal_symbol_by_pc (call_site->pc () - 1);
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 68b45efb2935..c71a14239605 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -844,7 +844,8 @@  elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
 	 gdb_byte *buf = (gdb_byte *) alloca (ptr_size);
 
 	 bound_minimal_symbol msym
-	   = lookup_minimal_symbol (name_got_plt, objfile);
+	   = lookup_minimal_symbol (current_program_space, name_got_plt,
+				    objfile);
 	 if (msym.minsym == NULL)
 	   return 0;
 	 if (msym.minsym->type () != mst_slot_got_plt)
diff --git a/gdb/eval.c b/gdb/eval.c
index 6e985c2a2a28..0c9c972f137a 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1957,7 +1957,8 @@  eval_op_objc_msgcall (struct type *expect_type, struct expression *exp,
   if (value_as_long (target) == 0)
     return value_from_longest (long_type, 0);
 
-  if (lookup_minimal_symbol ("objc_msg_lookup").minsym != nullptr)
+  if (lookup_minimal_symbol (current_program_space, "objc_msg_lookup").minsym
+      != nullptr)
     gnu_runtime = 1;
 
   /* Find the method dispatch (Apple runtime) or method lookup
diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
index e2a7a4045c90..0ab1afdfe25f 100644
--- a/gdb/fbsd-tdep.c
+++ b/gdb/fbsd-tdep.c
@@ -1943,7 +1943,8 @@  fbsd_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
 static LONGEST
 fbsd_read_integer_by_name (struct gdbarch *gdbarch, const char *name)
 {
-  bound_minimal_symbol ms = lookup_minimal_symbol (name);
+  bound_minimal_symbol ms
+    = lookup_minimal_symbol (current_program_space, name);
   if (ms.minsym == NULL)
     error (_("Unable to resolve symbol '%s'"), name);
 
@@ -2057,7 +2058,8 @@  fbsd_get_thread_local_address (struct gdbarch *gdbarch, CORE_ADDR dtv_addr,
 CORE_ADDR
 fbsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  bound_minimal_symbol msym = lookup_minimal_symbol ("_rtld_bind");
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, "_rtld_bind");
   if (msym.minsym != nullptr && msym.value_address () == pc)
     return frame_unwind_caller_pc (get_current_frame ());
 
diff --git a/gdb/findvar.c b/gdb/findvar.c
index c67315fb6849..f7760aa61ca9 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -449,7 +449,8 @@  language_defn::read_var_value (struct symbol *var,
 	  (var->arch (),
 	   [var, &bmsym] (objfile *objfile)
 	     {
-		bmsym = lookup_minimal_symbol (var->linkage_name (), objfile);
+		bmsym = lookup_minimal_symbol (current_program_space,
+					       var->linkage_name (), objfile);
 
 		/* Stop if a match is found.  */
 		return bmsym.minsym != nullptr;
diff --git a/gdb/frame.c b/gdb/frame.c
index 8c30979bb2f1..4d092d0e8c87 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2584,7 +2584,8 @@  inside_main_func (const frame_info_ptr &this_frame)
   CORE_ADDR sym_addr = 0;
   const char *name = main_name ();
   bound_minimal_symbol msymbol
-    = lookup_minimal_symbol (name, current_program_space->symfile_object_file);
+    = lookup_minimal_symbol (current_program_space, name,
+			     current_program_space->symfile_object_file);
 
   if (msymbol.minsym != nullptr)
     sym_addr = msymbol.value_address ();
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 80cc546cea78..6ae3f0d0f55e 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -1379,7 +1379,8 @@  frv_frame_this_id (const frame_info_ptr &this_frame,
   func = get_frame_func (this_frame);
 
   /* Check if the stack is empty.  */
-  bound_minimal_symbol msym_stack = lookup_minimal_symbol ("_stack");
+  bound_minimal_symbol msym_stack
+    = lookup_minimal_symbol (current_program_space, "_stack");
   if (msym_stack.minsym && info->base == msym_stack.value_address ())
     return;
 
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index 00dd76353890..15a585a356e2 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -195,7 +195,8 @@  ft32_analyze_prologue (CORE_ADDR start_addr, CORE_ADDR end_addr,
 
       snprintf (prolog_symbol, sizeof (prolog_symbol), "__prolog_$r%02d",
 		regnum);
-      bound_minimal_symbol msymbol = lookup_minimal_symbol (prolog_symbol);
+      bound_minimal_symbol msymbol
+	= lookup_minimal_symbol (current_program_space, prolog_symbol);
       if (msymbol.minsym)
 	prologs[regnum] = msymbol.value_address ();
       else
diff --git a/gdb/gcore.c b/gdb/gcore.c
index 0f04679a6bbc..969a8543ba29 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -269,13 +269,14 @@  call_target_sbrk (int sbrk_arg)
   struct value *sbrk_fn, *ret;
   bfd_vma tmp;
 
-  if (lookup_minimal_symbol ("sbrk").minsym != nullptr)
+  if (lookup_minimal_symbol (current_program_space, "sbrk").minsym != nullptr)
     {
       sbrk_fn = find_function_in_inferior ("sbrk", &sbrk_objf);
       if (sbrk_fn == NULL)
 	return (bfd_vma) 0;
     }
-  else if (lookup_minimal_symbol ("_sbrk").minsym != nullptr)
+  else if (lookup_minimal_symbol (current_program_space, "_sbrk").minsym
+	   != nullptr)
     {
       sbrk_fn = find_function_in_inferior ("_sbrk", &sbrk_objf);
       if (sbrk_fn == NULL)
diff --git a/gdb/glibc-tdep.c b/gdb/glibc-tdep.c
index 8f27133faea7..e3bf00c6a89f 100644
--- a/gdb/glibc-tdep.c
+++ b/gdb/glibc-tdep.c
@@ -53,17 +53,19 @@  glibc_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
      debugging programs that use shared libraries.  */
 
   bound_minimal_symbol resolver
-    = lookup_minimal_symbol ("_dl_runtime_resolve");
+    = lookup_minimal_symbol (current_program_space, "_dl_runtime_resolve");
 
   if (resolver.minsym)
     {
       /* The dynamic linker began using this name in early 2005.  */
       bound_minimal_symbol fixup
-	= lookup_minimal_symbol ("_dl_fixup", resolver.objfile);
+	= lookup_minimal_symbol (current_program_space, "_dl_fixup",
+				 resolver.objfile);
 
       /* This is the name used in older versions.  */
       if (! fixup.minsym)
-	fixup = lookup_minimal_symbol ("fixup", resolver.objfile);
+	fixup = lookup_minimal_symbol (current_program_space, "fixup",
+				       resolver.objfile);
 
       if (fixup.minsym && fixup.value_address () == pc)
 	return frame_unwind_caller_pc (get_current_frame ());
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 70cdde3d2752..aefbee542703 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -1160,7 +1160,8 @@  gnuv3_get_typeid (struct value *value)
   else
     {
       std::string sym_name = std::string ("typeinfo for ") + name;
-      bound_minimal_symbol minsym = lookup_minimal_symbol (sym_name.c_str ());
+      bound_minimal_symbol minsym
+	= lookup_minimal_symbol (current_program_space, sym_name.c_str ());
 
       if (minsym.minsym == NULL)
 	error (_("could not find typeinfo symbol for '%s'"), name);
@@ -1249,7 +1250,7 @@  gnuv3_skip_trampoline (const frame_info_ptr &frame, CORE_ADDR stop_pc)
 
   fn_name = strstr (thunk_name, " thunk to ") + strlen (" thunk to ");
   bound_minimal_symbol fn_sym
-    = lookup_minimal_symbol (fn_name, section->objfile);
+    = lookup_minimal_symbol (current_program_space, fn_name, section->objfile);
   if (fn_sym.minsym == NULL)
     return 0;
 
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index ce2b7e619671..8fd673750ea8 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -572,7 +572,7 @@  variable:	name_not_typename
 			      std::string arg = copy_name ($1.stoken);
 
 			      bound_minimal_symbol msymbol =
-				lookup_minimal_symbol (arg.c_str ());
+				lookup_minimal_symbol (current_program_space, arg.c_str ());
 			      if (msymbol.minsym != NULL)
 				pstate->push_new<var_msym_value_operation>
 				  (msymbol);
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index cf1f5a907a62..18d3fc1a008e 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -54,7 +54,8 @@  static const char GO_MAIN_MAIN[] = "main.main";
 const char *
 go_main_name (void)
 {
-  bound_minimal_symbol msym = lookup_minimal_symbol (GO_MAIN_MAIN);
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, GO_MAIN_MAIN);
   if (msym.minsym != NULL)
     return GO_MAIN_MAIN;
 
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index 0ce754a6ed66..ad93c2b20487 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -194,7 +194,8 @@  hppa_extract_17 (unsigned word)
 CORE_ADDR 
 hppa_symbol_address(const char *sym)
 {
-  bound_minimal_symbol minsym = lookup_minimal_symbol (sym);
+  bound_minimal_symbol minsym
+    = lookup_minimal_symbol (current_program_space, sym);
   if (minsym.minsym)
     return minsym.value_address ();
   else
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index d36511b70fe5..c457a90556d7 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -484,9 +484,12 @@  inferior_call_waitpid (ptid_t pptid, int pid)
   scoped_switch_fork_info switch_fork_info (pptid);
 
   /* Get the waitpid_fn.  */
-  if (lookup_minimal_symbol ("waitpid").minsym != nullptr)
+  if (lookup_minimal_symbol (current_program_space, "waitpid").minsym
+      != nullptr)
     waitpid_fn = find_function_in_inferior ("waitpid", &waitpid_objf);
-  if (!waitpid_fn && lookup_minimal_symbol ("_waitpid").minsym != nullptr)
+  if (!waitpid_fn
+      && (lookup_minimal_symbol (current_program_space, "_waitpid").minsym
+	  != nullptr))
     waitpid_fn = find_function_in_inferior ("_waitpid", &waitpid_objf);
   if (waitpid_fn != nullptr)
     {
@@ -700,10 +703,11 @@  checkpoint_command (const char *args, int from_tty)
   
   /* Make the inferior fork, record its (and gdb's) state.  */
 
-  if (lookup_minimal_symbol ("fork").minsym != nullptr)
+  if (lookup_minimal_symbol (current_program_space, "fork").minsym != nullptr)
     fork_fn = find_function_in_inferior ("fork", &fork_objf);
   if (!fork_fn)
-    if (lookup_minimal_symbol ("_fork").minsym != nullptr)
+    if (lookup_minimal_symbol (current_program_space, "_fork").minsym
+	!= nullptr)
       fork_fn = find_function_in_inferior ("fork", &fork_objf);
   if (!fork_fn)
     error (_("checkpoint: can't find fork function in inferior."));
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 6abaa20c594e..9d84187a9ad0 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -470,7 +470,8 @@  inferior_has_bug (const char *ver_symbol, int ver_major_min, int ver_minor_min)
   CORE_ADDR version_addr;
   int got, retval = 0;
 
-  bound_minimal_symbol version_msym = lookup_minimal_symbol (ver_symbol);
+  bound_minimal_symbol version_msym
+    = lookup_minimal_symbol (current_program_space, ver_symbol);
   if (version_msym.minsym == NULL)
     return 0;
 
@@ -809,7 +810,8 @@  static bool
 libpthread_objfile_p (objfile *obj)
 {
   return (libpthread_name_p (objfile_name (obj))
-	  && lookup_minimal_symbol ("pthread_create", obj).minsym != nullptr);
+	  && lookup_minimal_symbol (current_program_space,
+				    "pthread_create", obj).minsym != nullptr);
 }
 
 /* Attempt to initialize dlopen()ed libthread_db, described by INFO.
diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index 3531fbb899ba..28dfb2fb7c6b 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -2212,7 +2212,8 @@  m32c_return_value (struct gdbarch *gdbarch,
 	  /* Everything else is passed in mem0, using as many bytes as
 	     needed.  This is not what the Renesas tools do, but it's
 	     what GCC does at the moment.  */
-	  bound_minimal_symbol mem0 = lookup_minimal_symbol ("mem0");
+	  bound_minimal_symbol mem0
+	    = lookup_minimal_symbol (current_program_space, "mem0");
 
 	  if (! mem0.minsym)
 	    error (_("The return value is stored in memory at 'mem0', "
@@ -2243,7 +2244,8 @@  m32c_return_value (struct gdbarch *gdbarch,
 	  /* Everything else is passed in mem0, using as many bytes as
 	     needed.  This is not what the Renesas tools do, but it's
 	     what GCC does at the moment.  */
-	  bound_minimal_symbol mem0 = lookup_minimal_symbol ("mem0");
+	  bound_minimal_symbol mem0
+	    = lookup_minimal_symbol (current_program_space, "mem0");
 
 	  if (! mem0.minsym)
 	    error (_("The return value is stored in memory at 'mem0', "
@@ -2434,7 +2436,8 @@  m32c_m16c_address_to_pointer (struct gdbarch *gdbarch,
       strcat (tramp_name, ".plt");
 
       /* Try to find a linker symbol for the trampoline.  */
-      bound_minimal_symbol tramp_msym = lookup_minimal_symbol (tramp_name);
+      bound_minimal_symbol tramp_msym
+	= lookup_minimal_symbol (current_program_space, tramp_name);
 
       /* We've either got another copy of the name now, or don't need
 	 the name any more.  */
@@ -2518,7 +2521,7 @@  m32c_m16c_pointer_to_address (struct gdbarch *gdbarch,
 	      memcpy (func_name, ptr_msym_name, len - 4);
 	      func_name[len - 4] = '\0';
 	      bound_minimal_symbol func_msym
-		= lookup_minimal_symbol (func_name);
+		= lookup_minimal_symbol (current_program_space, func_name);
 
 	      /* If we do have such a symbol, return its value as the
 		 function's true address.  */
diff --git a/gdb/m32r-tdep.c b/gdb/m32r-tdep.c
index 4899c1556669..c6428f6db6f6 100644
--- a/gdb/m32r-tdep.c
+++ b/gdb/m32r-tdep.c
@@ -806,7 +806,8 @@  m32r_frame_this_id (const frame_info_ptr &this_frame,
   func = get_frame_func (this_frame);
 
   /* Check if the stack is empty.  */
-  bound_minimal_symbol msym_stack = lookup_minimal_symbol ("_stack");
+  bound_minimal_symbol msym_stack
+    = lookup_minimal_symbol (current_program_space, "_stack");
   if (msym_stack.minsym && info->base == msym_stack.value_address ())
     return;
 
diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
index 8075dbb0508a..12cd0efbbe73 100644
--- a/gdb/m68hc11-tdep.c
+++ b/gdb/m68hc11-tdep.c
@@ -210,7 +210,8 @@  static int soft_reg_initialized = 0;
 static void
 m68hc11_get_register_info (struct m68hc11_soft_reg *reg, const char *name)
 {
-  bound_minimal_symbol msymbol = lookup_minimal_symbol (name);
+  bound_minimal_symbol msymbol
+    = lookup_minimal_symbol (current_program_space, name);
   if (msymbol.minsym)
     {
       reg->addr = msymbol.value_address ();
diff --git a/gdb/machoread.c b/gdb/machoread.c
index 5840b663bbeb..ef6cf6606299 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -396,7 +396,8 @@  macho_resolve_oso_sym_with_minsym (struct objfile *main_objfile, asymbol *sym)
       && *name == bfd_get_symbol_leading_char (main_objfile->obfd.get ()))
     ++name;
 
-  bound_minimal_symbol msym = lookup_minimal_symbol (name, main_objfile);
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, name, main_objfile);
   if (msym.minsym == NULL)
     {
       warning (_("can't find symbol '%s' in minsymtab"), name);
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 31e8e7d2a194..ba9da1d81af5 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -359,7 +359,8 @@  lookup_minimal_symbol_demangled (const lookup_name_info &lookup_name,
    but the demangled names are all the same: S::S or S::~S.  */
 
 bound_minimal_symbol
-lookup_minimal_symbol (const char *name, objfile *objf, const char *sfile)
+lookup_minimal_symbol (program_space *pspace, const char *name, objfile *objf,
+		       const char *sfile)
 {
   found_minimal_symbols found;
 
@@ -375,7 +376,7 @@  lookup_minimal_symbol (const char *name, objfile *objf, const char *sfile)
 
   lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
 
-  for (objfile *objfile : current_program_space->objfiles ())
+  for (objfile *objfile : pspace->objfiles ())
     {
       if (found.external_symbol.minsym != NULL)
 	break;
@@ -383,7 +384,8 @@  lookup_minimal_symbol (const char *name, objfile *objf, const char *sfile)
       if (objf == NULL || objf == objfile
 	  || objf == objfile->separate_debug_objfile_backlink)
 	{
-	  symbol_lookup_debug_printf ("lookup_minimal_symbol (%s, %s, %s)",
+	  symbol_lookup_debug_printf ("lookup_minimal_symbol (%s, %s, %s, %s)",
+				      host_address_to_string (pspace),
 				      name, sfile != NULL ? sfile : "NULL",
 				      objfile_debug_name (objfile));
 
@@ -479,7 +481,8 @@  int
 find_minimal_symbol_address (const char *name, CORE_ADDR *addr,
 			     struct objfile *objfile)
 {
-  bound_minimal_symbol sym = lookup_minimal_symbol (name, objfile);
+  bound_minimal_symbol sym
+    = lookup_minimal_symbol (current_program_space, name, objfile);
   if (sym.minsym != NULL)
     *addr = sym.value_address ();
 
diff --git a/gdb/minsyms.h b/gdb/minsyms.h
index b05ca2bda740..0d9b9ad51cee 100644
--- a/gdb/minsyms.h
+++ b/gdb/minsyms.h
@@ -20,6 +20,7 @@ 
 #ifndef MINSYMS_H
 #define MINSYMS_H
 
+struct program_space;
 struct type;
 
 /* Several lookup functions return both a minimal symbol and the
@@ -205,7 +206,8 @@  unsigned int msymbol_hash_iw (const char *);
    symbols are still preferred).  Returns a bound minimal symbol that
    matches, or an empty bound minimal symbol if no match is found.  */
 
-bound_minimal_symbol lookup_minimal_symbol (const char *name,
+bound_minimal_symbol lookup_minimal_symbol (program_space *pspace,
+					    const char *name,
 					    objfile *obj = nullptr,
 					    const char *sfile = nullptr);
 
diff --git a/gdb/mips-fbsd-tdep.c b/gdb/mips-fbsd-tdep.c
index 22881e8a9c10..773607861aa9 100644
--- a/gdb/mips-fbsd-tdep.c
+++ b/gdb/mips-fbsd-tdep.c
@@ -468,7 +468,8 @@  static const struct tramp_frame mips64_fbsd_sigframe =
 static CORE_ADDR
 mips_fbsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  bound_minimal_symbol msym = lookup_minimal_symbol ("_mips_rtld_bind");
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, "_mips_rtld_bind");
   if (msym.minsym != nullptr && msym.value_address () == pc)
     return frame_unwind_caller_pc (get_current_frame ());
 
diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
index 4b3754c314a2..7d0d67c6c677 100644
--- a/gdb/mips-linux-tdep.c
+++ b/gdb/mips-linux-tdep.c
@@ -699,7 +699,7 @@  static CORE_ADDR
 mips_linux_skip_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
   bound_minimal_symbol resolver
-    = lookup_minimal_symbol ("__dl_runtime_resolve");
+    = lookup_minimal_symbol (current_program_space, "__dl_runtime_resolve");
 
   if (resolver.minsym && resolver.value_address () == pc)
     return frame_unwind_caller_pc (get_current_frame ());
diff --git a/gdb/netbsd-tdep.c b/gdb/netbsd-tdep.c
index 4d2c41294464..415a7432787e 100644
--- a/gdb/netbsd-tdep.c
+++ b/gdb/netbsd-tdep.c
@@ -348,7 +348,8 @@  nbsd_gdb_signal_to_target (struct gdbarch *gdbarch,
 static CORE_ADDR
 nbsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  bound_minimal_symbol msym = lookup_minimal_symbol ("_rtld_bind_start");
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, "_rtld_bind_start");
   if (msym.minsym && msym.value_address () == pc)
     return frame_unwind_caller_pc (get_current_frame ());
   else
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 3d50d1019c82..cf789791c6d1 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -120,9 +120,11 @@  lookup_objc_class (struct gdbarch *gdbarch, const char *classname)
       return 0;
     }
 
-  if (lookup_minimal_symbol ("objc_lookUpClass").minsym != nullptr)
+  if (lookup_minimal_symbol (current_program_space,
+			     "objc_lookUpClass").minsym != nullptr)
     function = find_function_in_inferior("objc_lookUpClass", NULL);
-  else if (lookup_minimal_symbol ("objc_lookup_class").minsym != nullptr)
+  else if (lookup_minimal_symbol (current_program_space,
+				  "objc_lookup_class").minsym != nullptr)
     function = find_function_in_inferior("objc_lookup_class", NULL);
   else
     {
@@ -149,9 +151,11 @@  lookup_child_selector (struct gdbarch *gdbarch, const char *selname)
       return 0;
     }
 
-  if (lookup_minimal_symbol ("sel_getUid").minsym != nullptr)
+  if (lookup_minimal_symbol (current_program_space, "sel_getUid").minsym
+      != nullptr)
     function = find_function_in_inferior("sel_getUid", NULL);
-  else if (lookup_minimal_symbol ("sel_get_any_uid").minsym != nullptr)
+  else if (lookup_minimal_symbol (current_program_space,
+				  "sel_get_any_uid").minsym != nullptr)
     function = find_function_in_inferior("sel_get_any_uid", NULL);
   else
     {
@@ -180,17 +184,20 @@  value_nsstring (struct gdbarch *gdbarch, const char *ptr, int len)
   stringValue[2] = value_string(ptr, len, char_type);
   stringValue[2] = value_coerce_array(stringValue[2]);
   /* _NSNewStringFromCString replaces "istr" after Lantern2A.  */
-  if (lookup_minimal_symbol ("_NSNewStringFromCString").minsym != nullptr)
+  if (lookup_minimal_symbol (current_program_space,
+			     "_NSNewStringFromCString").minsym != nullptr)
     {
       function = find_function_in_inferior("_NSNewStringFromCString", NULL);
       nsstringValue = call_function_by_hand(function, NULL, stringValue[2]);
     }
-  else if (lookup_minimal_symbol ("istr").minsym != nullptr)
+  else if (lookup_minimal_symbol (current_program_space,
+				  "istr").minsym != nullptr)
     {
       function = find_function_in_inferior("istr", NULL);
       nsstringValue = call_function_by_hand(function, NULL, stringValue[2]);
     }
-  else if (lookup_minimal_symbol ("+[NSString stringWithCString:]").minsym
+  else if (lookup_minimal_symbol (current_program_space,
+				  "+[NSString stringWithCString:]").minsym
 	   != nullptr)
     {
       function
@@ -1138,7 +1145,8 @@  find_imps (const char *method, std::vector<const char *> *symbol_names)
 	symbol_names->push_back (sym->natural_name ());
       else
 	{
-	  bound_minimal_symbol msym = lookup_minimal_symbol (selector);
+	  bound_minimal_symbol msym
+	    = lookup_minimal_symbol (current_program_space, selector);
 
 	  if (msym.minsym != NULL) 
 	    symbol_names->push_back (msym.minsym->natural_name ());
@@ -1241,10 +1249,12 @@  find_objc_msgsend (void)
   for (i = 0; i < nmethcalls; i++)
     {
       /* Try both with and without underscore.  */
-      bound_minimal_symbol func = lookup_minimal_symbol (methcalls[i].name);
+      bound_minimal_symbol func
+	= lookup_minimal_symbol (current_program_space, methcalls[i].name);
       if ((func.minsym == NULL) && (methcalls[i].name[0] == '_'))
 	{
-	  func = lookup_minimal_symbol (methcalls[i].name + 1);
+	  func = lookup_minimal_symbol (current_program_space,
+					methcalls[i].name + 1);
 	}
       if (func.minsym == NULL)
 	{ 
diff --git a/gdb/obsd-tdep.c b/gdb/obsd-tdep.c
index 755e612823e7..00de5c0c0952 100644
--- a/gdb/obsd-tdep.c
+++ b/gdb/obsd-tdep.c
@@ -27,7 +27,8 @@ 
 CORE_ADDR
 obsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  bound_minimal_symbol msym = lookup_minimal_symbol ("_dl_bind");
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, "_dl_bind");
   if (msym.minsym && msym.value_address () == pc)
     return frame_unwind_caller_pc (get_current_frame ());
   else
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index 7476176c9572..ad7cd58196f7 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -720,7 +720,7 @@  variable:	name_not_typename
 			      std::string arg = copy_name ($1.stoken);
 
 			      bound_minimal_symbol msymbol
-				= lookup_minimal_symbol (arg.c_str ());
+				= lookup_minimal_symbol (current_program_space, arg.c_str ());
 			      if (msymbol.minsym != NULL)
 				pstate->push_new<var_msym_value_operation>
 				  (msymbol);
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 70f28c980d94..4c5d4dd1eaf7 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -59,20 +59,23 @@  static const char GPC_MAIN_PROGRAM_NAME_2[] = "pascal_main_program";
 const char *
 pascal_main_name (void)
 {
-  bound_minimal_symbol msym = lookup_minimal_symbol (GPC_P_INITIALIZE);
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, GPC_P_INITIALIZE);
 
   /*  If '_p_initialize' was not found, the main program is likely not
      written in Pascal.  */
   if (msym.minsym == NULL)
     return NULL;
 
-  msym = lookup_minimal_symbol (GPC_MAIN_PROGRAM_NAME_1);
+  msym
+    = lookup_minimal_symbol (current_program_space, GPC_MAIN_PROGRAM_NAME_1);
   if (msym.minsym != NULL)
     {
       return GPC_MAIN_PROGRAM_NAME_1;
     }
 
-  msym = lookup_minimal_symbol (GPC_MAIN_PROGRAM_NAME_2);
+  msym
+    = lookup_minimal_symbol (current_program_space, GPC_MAIN_PROGRAM_NAME_2);
   if (msym.minsym != NULL)
     {
       return GPC_MAIN_PROGRAM_NAME_2;
diff --git a/gdb/parse.c b/gdb/parse.c
index d5bbc4dec58a..03763de74e7c 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -145,7 +145,8 @@  parser_state::push_symbol (const char *name, block_symbol sym)
     }
   else
     {
-      bound_minimal_symbol msymbol = lookup_minimal_symbol (name);
+      bound_minimal_symbol msymbol
+	= lookup_minimal_symbol (current_program_space, name);
       if (msymbol.minsym != NULL)
 	push_new<expr::var_msym_value_operation> (msymbol);
       else if (!have_full_symbols (current_program_space)
@@ -231,7 +232,8 @@  parser_state::push_dollar (struct stoken str)
       push_new<expr::var_value_operation> (sym);
       return;
     }
-  bound_minimal_symbol msym = lookup_minimal_symbol (copy.c_str ());
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, copy.c_str ());
   if (msym.minsym)
     {
       push_new<expr::var_msym_value_operation> (msym);
diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index cdba46c2a88a..f317c94ef598 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -1060,7 +1060,8 @@  convert_code_addr_to_desc_addr (CORE_ADDR code_addr, CORE_ADDR *desc_addr)
      - avoids problems when two object files (i.e., shared libraries)
      contain a minimal symbol with the same name.  */
   bound_minimal_symbol fn
-    = lookup_minimal_symbol (dot_fn.minsym->linkage_name () + 1,
+    = lookup_minimal_symbol (current_program_space,
+			     dot_fn.minsym->linkage_name () + 1,
 			     dot_fn_section->objfile);
   if (fn.minsym == NULL)
     return 0;
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index d2d5497913c6..f1aaa644042e 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1600,7 +1600,8 @@  info_address_command (const char *exp, int from_tty)
 	  return;
 	}
 
-      bound_minimal_symbol msymbol = lookup_minimal_symbol (exp);
+      bound_minimal_symbol msymbol
+	= lookup_minimal_symbol (current_program_space, exp);
 
       if (msymbol.minsym != NULL)
 	{
@@ -1753,7 +1754,8 @@  info_address_command (const char *exp, int from_tty)
     case LOC_UNRESOLVED:
       {
 	bound_minimal_symbol msym
-	  = lookup_minimal_symbol (sym->linkage_name ());
+	  = lookup_minimal_symbol (current_program_space,
+				   sym->linkage_name ());
 	if (msym.minsym == NULL)
 	  gdb_printf ("unresolved");
 	else
diff --git a/gdb/proc-service.c b/gdb/proc-service.c
index bf57efd6c1fa..ce2d69a0ce78 100644
--- a/gdb/proc-service.c
+++ b/gdb/proc-service.c
@@ -99,7 +99,8 @@  ps_pglobal_lookup (struct ps_prochandle *ph, const char *obj,
   set_current_program_space (inf->pspace);
 
   /* FIXME: kettenis/2000-09-03: What should we do with OBJ?  */
-  bound_minimal_symbol ms = lookup_minimal_symbol (name);
+  bound_minimal_symbol ms
+    = lookup_minimal_symbol (current_program_space, name);
   if (ms.minsym == NULL)
     return PS_NOSYM;
 
diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c
index 68c2978a92ed..47db72b2d690 100644
--- a/gdb/ravenscar-thread.c
+++ b/gdb/ravenscar-thread.c
@@ -329,13 +329,14 @@  ravenscar_thread_target::add_active_thread ()
 static bound_minimal_symbol
 get_running_thread_msymbol ()
 {
-  bound_minimal_symbol msym = lookup_minimal_symbol (running_thread_name);
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, running_thread_name);
   if (!msym.minsym)
     /* Older versions of the GNAT runtime were using a different
        (less ideal) name for the symbol where the active thread ID
        is stored.  If we couldn't find the symbol using the latest
        name, then try the old one.  */
-    msym = lookup_minimal_symbol ("running_thread");
+    msym = lookup_minimal_symbol (current_program_space, "running_thread");
 
   return msym;
 }
@@ -347,11 +348,12 @@  static bool
 has_ravenscar_runtime ()
 {
   bound_minimal_symbol msym_ravenscar_runtime_initializer
-    = lookup_minimal_symbol (ravenscar_runtime_initializer);
+    = lookup_minimal_symbol (current_program_space,
+			     ravenscar_runtime_initializer);
   bound_minimal_symbol msym_known_tasks
-    = lookup_minimal_symbol (known_tasks_name);
+    = lookup_minimal_symbol (current_program_space, known_tasks_name);
   bound_minimal_symbol msym_first_task
-    = lookup_minimal_symbol (first_task_name);
+    = lookup_minimal_symbol (current_program_space, first_task_name);
   bound_minimal_symbol msym_running_thread = get_running_thread_msymbol ();
 
   return (msym_ravenscar_runtime_initializer.minsym
@@ -639,7 +641,8 @@  ravenscar_thread_target::get_fpu_state (struct regcache *regcache,
     return NOTHING_SPECIAL;
 
   bound_minimal_symbol fpu_context
-    = lookup_minimal_symbol ("system__bb__cpu_primitives__current_fpu_context",
+    = lookup_minimal_symbol (current_program_space,
+			     "system__bb__cpu_primitives__current_fpu_context",
 			     nullptr, nullptr);
   /* If the symbol can't be found, just fall back.  */
   if (fpu_context.minsym == nullptr)
diff --git a/gdb/remote.c b/gdb/remote.c
index aba609d9eb6c..d81e5a093c7e 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -5518,7 +5518,8 @@  remote_target::remote_check_symbols ()
       end = hex2bin (tmp, reinterpret_cast <gdb_byte *> (msg.data ()),
 		     strlen (tmp) / 2);
       msg[end] = '\0';
-      bound_minimal_symbol sym = lookup_minimal_symbol (msg.data ());
+      bound_minimal_symbol sym
+	= lookup_minimal_symbol (current_program_space, msg.data ());
       if (sym.minsym == NULL)
 	xsnprintf (msg.data (), get_remote_packet_size (), "qSymbol::%s",
 		   &reply[8]);
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
index 25b6aa37ec0e..db86079b3fa6 100644
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -759,7 +759,8 @@  ps_err_e
 ps_pglobal_lookup (struct ps_prochandle *ph, const char *ld_object_name,
 		   const char *ld_symbol_name, psaddr_t *ld_symbol_addr)
 {
-  bound_minimal_symbol ms = lookup_minimal_symbol (ld_symbol_name);
+  bound_minimal_symbol ms
+    = lookup_minimal_symbol (current_program_space, ld_symbol_name);
   if (!ms.minsym)
     return PS_NOSYM;
 
diff --git a/gdb/sol2-tdep.c b/gdb/sol2-tdep.c
index 3081726a5e10..0beab74f49f6 100644
--- a/gdb/sol2-tdep.c
+++ b/gdb/sol2-tdep.c
@@ -63,7 +63,8 @@  sol2_sigtramp_p (const frame_info_ptr &this_frame)
 static CORE_ADDR
 sol2_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  bound_minimal_symbol msym = lookup_minimal_symbol ("elf_bndr");
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, "elf_bndr");
   if (msym.minsym && msym.value_address () == pc)
     return frame_unwind_caller_pc (get_current_frame ());
 
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 6ea9a1326db6..d61100463ccc 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -451,7 +451,7 @@  lm_base (void)
     return info->lm_base_cache;
 
   bound_minimal_symbol got_sym
-    = lookup_minimal_symbol ("_GLOBAL_OFFSET_TABLE_",
+    = lookup_minimal_symbol (current_program_space, "_GLOBAL_OFFSET_TABLE_",
 			     current_program_space->symfile_object_file);
 
   if (got_sym.minsym != 0)
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index c979135fafa8..bc8b67e3632e 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -280,7 +280,7 @@  lm_base (void)
     return lm_base_cache;
 
   bound_minimal_symbol got_sym
-    = lookup_minimal_symbol ("_GLOBAL_OFFSET_TABLE_",
+    = lookup_minimal_symbol (current_program_space, "_GLOBAL_OFFSET_TABLE_",
 			     current_program_space->symfile_object_file);
   if (got_sym.minsym == 0)
     {
@@ -840,7 +840,8 @@  main_got (void)
 {
   objfile *objf = current_program_space->symfile_object_file;
   bound_minimal_symbol got_sym
-    = lookup_minimal_symbol ("_GLOBAL_OFFSET_TABLE_", objf);
+    = lookup_minimal_symbol (current_program_space, "_GLOBAL_OFFSET_TABLE_",
+			     objf);
   if (got_sym.minsym == 0)
     return 0;
 
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 13a6ac0f83d1..5a8004d7210f 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -751,7 +751,7 @@  elf_locate_base (void)
   /* This may be a static executable.  Look for the symbol
      conventionally named _r_debug, as a last resort.  */
   bound_minimal_symbol msymbol
-    = lookup_minimal_symbol ("_r_debug",
+    = lookup_minimal_symbol (current_program_space, "_r_debug",
 			     current_program_space->symfile_object_file);
   if (msymbol.minsym != NULL)
     return msymbol.value_address ();
@@ -2481,7 +2481,8 @@  enable_break (struct svr4_info *info, int from_tty)
   objfile *objf = current_program_space->symfile_object_file;
   for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++)
     {
-      bound_minimal_symbol msymbol = lookup_minimal_symbol (*bkpt_namep, objf);
+      bound_minimal_symbol msymbol
+	= lookup_minimal_symbol (current_program_space, *bkpt_namep, objf);
       if ((msymbol.minsym != NULL)
 	  && (msymbol.value_address () != 0))
 	{
@@ -2501,7 +2502,7 @@  enable_break (struct svr4_info *info, int from_tty)
       for (bkpt_namep = bkpt_names; *bkpt_namep != NULL; bkpt_namep++)
 	{
 	  bound_minimal_symbol msymbol
-	    = lookup_minimal_symbol (*bkpt_namep, objf);
+	    = lookup_minimal_symbol (current_program_space, *bkpt_namep, objf);
 	  if ((msymbol.minsym != NULL)
 	      && (msymbol.value_address () != 0))
 	    {
diff --git a/gdb/symfile.c b/gdb/symfile.c
index c9f5e9dfab1f..49b98459a28a 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3433,7 +3433,8 @@  simple_read_overlay_table (void)
   enum bfd_endian byte_order;
 
   simple_free_overlay_table ();
-  bound_minimal_symbol novlys_msym = lookup_minimal_symbol ("_novlys");
+  bound_minimal_symbol novlys_msym
+    = lookup_minimal_symbol (current_program_space, "_novlys");
   if (! novlys_msym.minsym)
     {
       error (_("Error reading inferior's overlay table: "
@@ -3442,7 +3443,8 @@  simple_read_overlay_table (void)
       return 0;
     }
 
-  bound_minimal_symbol ovly_table_msym = lookup_minimal_symbol ("_ovly_table");
+  bound_minimal_symbol ovly_table_msym
+    = lookup_minimal_symbol (current_program_space, "_ovly_table");
   if (! ovly_table_msym.minsym)
     {
       error (_("Error reading inferior's overlay table: couldn't find "
@@ -3521,7 +3523,8 @@  simple_overlay_update (struct obj_section *osect)
       {
 	/* Does its cached location match what's currently in the
 	   symtab?  */
-	bound_minimal_symbol minsym = lookup_minimal_symbol ("_ovly_table");
+	bound_minimal_symbol minsym
+	  = lookup_minimal_symbol (current_program_space, "_ovly_table");
 
 	if (minsym.minsym == NULL)
 	  error (_("Error reading inferior's overlay table: couldn't "
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 2f2366bd83a6..a5a2e698a14d 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -2580,7 +2580,8 @@  info_scope_command (const char *args_in, int from_tty)
 		case LOC_UNRESOLVED:
 		  {
 		    bound_minimal_symbol msym
-		      = lookup_minimal_symbol (sym->linkage_name ());
+		      = lookup_minimal_symbol (current_program_space,
+					       sym->linkage_name ());
 		    if (msym.minsym == NULL)
 		      gdb_printf ("Unresolved Static");
 		    else
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index c37c20e90bda..cd828537a5a4 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -403,7 +403,7 @@  tui_get_begin_asm_address (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
       if (addr == 0)
 	{
 	  bound_minimal_symbol main_symbol
-	    = lookup_minimal_symbol (main_name ());
+	    = lookup_minimal_symbol (current_program_space, main_name ());
 	  if (main_symbol.minsym != nullptr)
 	    addr = main_symbol.value_address ();
 	}
diff --git a/gdb/valops.c b/gdb/valops.c
index cca610ae28d0..427fbb1ad613 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -129,7 +129,8 @@  find_function_in_inferior (const char *name, struct objfile **objf_p)
     }
   else
     {
-      bound_minimal_symbol msymbol = lookup_minimal_symbol (name);
+      bound_minimal_symbol msymbol
+	= lookup_minimal_symbol (current_program_space, name);
 
       if (msymbol.minsym != NULL)
 	{
diff --git a/gdb/value.c b/gdb/value.c
index 48bf1540144e..3106d867e1b0 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2933,7 +2933,8 @@  value_static_field (struct type *type, int fieldno)
 	{
 	  /* With some compilers, e.g. HP aCC, static data members are
 	     reported as non-debuggable symbols.  */
-	  bound_minimal_symbol msym = lookup_minimal_symbol (phys_name);
+	  bound_minimal_symbol msym
+	    = lookup_minimal_symbol (current_program_space, phys_name);
 	  struct type *field_type = type->field (fieldno).type ();
 
 	  if (!msym.minsym)
@@ -3121,7 +3122,7 @@  value_fn_field (struct value **arg1p, struct fn_field *f,
 		       nullptr).symbol;
   if (sym == nullptr)
     {
-      msym = lookup_minimal_symbol (physname);
+      msym = lookup_minimal_symbol (current_program_space, physname);
       if (msym.minsym == NULL)
 	return NULL;
     }
diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
index 6eea6346199f..c442b60623be 100644
--- a/gdb/z80-tdep.c
+++ b/gdb/z80-tdep.c
@@ -356,7 +356,8 @@  z80_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
   /* stage2: check for FP saving scheme */
   if (prologue[pos] == 0xcd) /* call nn */
     {
-      bound_minimal_symbol msymbol = lookup_minimal_symbol ("__sdcc_enter_ix");
+      bound_minimal_symbol msymbol
+	= lookup_minimal_symbol (current_program_space, "__sdcc_enter_ix");
       if (msymbol.minsym)
 	{
 	  value = msymbol.value_address ();
@@ -621,7 +622,7 @@  z80_frame_unwind_cache (const frame_info_ptr &this_frame,
 	      for (i = sizeof(names)/sizeof(*names)-1; i >= 0; --i)
 		{
 		  bound_minimal_symbol msymbol
-		    = lookup_minimal_symbol (names[i]);
+		    = lookup_minimal_symbol (current_program_space, names[i]);
 		  if (!msymbol.minsym)
 		    continue;
 		  if (addr == msymbol.value_address ())
@@ -718,7 +719,8 @@  z80_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
   static int addr = -1;
   if (addr == -1)
     {
-      bound_minimal_symbol bh = lookup_minimal_symbol ("_break_handler");
+      bound_minimal_symbol bh
+	= lookup_minimal_symbol (current_program_space, "_break_handler");
       if (bh.minsym)
 	addr = bh.value_address ();
       else
@@ -898,7 +900,7 @@  z80_read_overlay_region_table ()
 
   z80_free_overlay_region_table ();
   bound_minimal_symbol novly_regions_msym
-    = lookup_minimal_symbol ("_novly_regions");
+    = lookup_minimal_symbol (current_program_space, "_novly_regions");
   if (! novly_regions_msym.minsym)
     {
       error (_("Error reading inferior's overlay table: "
@@ -908,7 +910,7 @@  z80_read_overlay_region_table ()
     }
 
   bound_minimal_symbol ovly_region_table_msym
-    = lookup_minimal_symbol ("_ovly_region_table");
+    = lookup_minimal_symbol (current_program_space, "_ovly_region_table");
   if (! ovly_region_table_msym.minsym)
     {
       error (_("Error reading inferior's overlay table: couldn't find "