gdb/testsuite: gdb.base/args.exp: add KFAIL for native-extended-gdbserver
[binutils-gdb.git] / gdb / solib.c
index 906e1788c49b02db261c17b5d39244dce8074dc8..317f7eb485e25cdb41bfa6306ec7d3c476418129 100644 (file)
@@ -1,6 +1,6 @@
 /* Handle shared libraries for GDB, the GNU Debugger.
 
-   Copyright (C) 1990-2020 Free Software Foundation, Inc.
+   Copyright (C) 1990-2021 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -224,14 +224,14 @@ solib_find_1 (const char *in_pathname, int *fd, bool is_solib)
         may need to glue them with a directory separator.  Cases to
         consider:
 
-        | sysroot         | separator | in_pathname    |
-        |-----------------+-----------+----------------|
-        | /some/dir       | /         | c:/foo/bar.dll |
-        | /some/dir       |           | /foo/bar.dll   |
-        | target:         |           | c:/foo/bar.dll |
-        | target:         |           | /foo/bar.dll   |
-        | target:some/dir | /         | c:/foo/bar.dll |
-        | target:some/dir |           | /foo/bar.dll   |
+       | sysroot         | separator | in_pathname    |
+       |-----------------+-----------+----------------|
+       | /some/dir       | /         | c:/foo/bar.dll |
+       | /some/dir       |           | /foo/bar.dll   |
+       | target:         |           | c:/foo/bar.dll |
+       | target:         |           | /foo/bar.dll   |
+       | target:some/dir | /         | c:/foo/bar.dll |
+       | target:some/dir |           | /foo/bar.dll   |
 
        IOW, we don't need to add a separator if IN_PATHNAME already
        has one, or when the sysroot is exactly "target:".
@@ -554,17 +554,13 @@ solib_map_sections (struct so_list *so)
 
   if (so->sections == nullptr)
     so->sections = new target_section_table;
-  if (build_section_table (so->abfd, so->sections))
-    {
-      error (_("Can't find the file sections in `%s': %s"),
-            bfd_get_filename (so->abfd), bfd_errmsg (bfd_get_error ()));
-    }
+  *so->sections = build_section_table (so->abfd);
 
-  for (target_section &p : so->sections->sections)
+  for (target_section &p : *so->sections)
     {
       /* Relocate the section binding addresses as recorded in the shared
-         object's file by the base address to which the object was actually
-         mapped.  */
+        object's file by the base address to which the object was actually
+        mapped.  */
       ops->relocate_section_addresses (so, &p);
 
       /* If the target didn't provide information about the address
@@ -582,7 +578,7 @@ solib_map_sections (struct so_list *so)
      section tables.  Do this immediately after mapping the object so
      that later nodes in the list can query this object, as is needed
      in solib-osf.c.  */
-  add_target_sections (so, *so->sections);
+  current_program_space->add_target_sections (so, *so->sections);
 
   return 1;
 }
@@ -733,7 +729,8 @@ update_solib_list (int from_tty)
       /* If we are attaching to a running process for which we
         have not opened a symbol file, we may be able to get its
         symbols now!  */
-      if (inf->attach_flag && symfile_objfile == NULL)
+      if (inf->attach_flag
+         && current_program_space->symfile_object_file == NULL)
        {
          try
            {
@@ -799,8 +796,8 @@ update_solib_list (int from_tty)
        }
 
       /* If the shared object appears on the inferior's list too, then
-         it's still loaded, so we don't need to do anything.  Delete
-         it from the inferior's list, and leave it on GDB's list.  */
+        it's still loaded, so we don't need to do anything.  Delete
+        it from the inferior's list, and leave it on GDB's list.  */
       if (i)
        {
          *i_link = i->next;
@@ -827,7 +824,7 @@ update_solib_list (int from_tty)
 
          /* Some targets' section tables might be referring to
             sections from so->abfd; remove them.  */
-         remove_target_sections (gdb);
+         current_program_space->remove_target_sections (gdb);
 
          free_so (gdb);
          gdb = *gdb_link;
@@ -903,12 +900,17 @@ Do you need \"set solib-search-path\" or \"set sysroot\"?"),
 
    Uses a fairly simplistic heuristic approach where we check
    the file name against "/libpthread".  This can lead to false
-   positives, but this should be good enough in practice.  */
+   positives, but this should be good enough in practice.
+
+   As of glibc-2.34, functions formerly residing in libpthread have
+   been moved to libc, so "/libc." needs to be checked too.  (Matching
+   the "." will avoid matching libraries such as libcrypt.) */
 
 bool
 libpthread_name_p (const char *name)
 {
-  return (strstr (name, "/libpthread") != NULL);
+  return (strstr (name, "/libpthread") != NULL
+          || strstr (name, "/libc.") != NULL );
 }
 
 /* Return non-zero if SO is the libpthread shared library.  */
@@ -963,18 +965,18 @@ solib_add (const char *pattern, int from_tty, int readsyms)
     symfile_add_flags add_flags = SYMFILE_DEFER_BP_RESET;
 
     if (from_tty)
-        add_flags |= SYMFILE_VERBOSE;
+       add_flags |= SYMFILE_VERBOSE;
 
     for (struct so_list *gdb : current_program_space->solibs ())
       if (! pattern || re_exec (gdb->so_name))
        {
-          /* Normally, we would read the symbols from that library
-             only if READSYMS is set.  However, we're making a small
-             exception for the pthread library, because we sometimes
-             need the library symbols to be loaded in order to provide
-             thread support (x86-linux for instance).  */
-          const int add_this_solib =
-            (readsyms || libpthread_solib_p (gdb));
+         /* Normally, we would read the symbols from that library
+            only if READSYMS is set.  However, we're making a small
+            exception for the pthread library, because we sometimes
+            need the library symbols to be loaded in order to provide
+            thread support (x86-linux for instance).  */
+         const int add_this_solib =
+           (readsyms || libpthread_solib_p (gdb));
 
          any_matches = true;
          if (add_this_solib)
@@ -1117,7 +1119,10 @@ bool
 solib_contains_address_p (const struct so_list *const solib,
                          CORE_ADDR address)
 {
-  for (target_section &p : solib->sections->sections)
+  if (solib->sections == nullptr)
+    return false;
+
+  for (target_section &p : *solib->sections)
     if (p.addr <= address && address < p.endaddr)
       return true;
 
@@ -1175,7 +1180,7 @@ clear_solib (void)
 
       current_program_space->so_list = so->next;
       gdb::observers::solib_unloaded.notify (so);
-      remove_target_sections (so);
+      current_program_space->remove_target_sections (so);
       free_so (so);
     }
 
@@ -1252,7 +1257,7 @@ handle_solib_event (void)
   if (ops->handle_event != NULL)
     ops->handle_event ();
 
-  clear_program_space_solib_cache (current_inferior ()->pspace);
+  current_inferior ()->pspace->clear_solib_cache ();
 
   /* Check for any newly added shared libraries if we're supposed to
      be adding them automatically.  Switch terminal for any messages
@@ -1295,7 +1300,7 @@ reload_shared_libraries_1 (int from_tty)
          if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED)
              && !solib_used (so))
            so->objfile->unlink ();
-         remove_target_sections (so);
+         current_program_space->remove_target_sections (so);
          clear_so (so);
        }
 
@@ -1451,11 +1456,11 @@ gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
              symaddr = sym->value;
 
              /* Some ELF targets fiddle with addresses of symbols they
-                consider special.  They use minimal symbols to do that
-                and this is needed for correct breakpoint placement,
-                but we do not have full data here to build a complete
-                minimal symbol, so just set the address and let the
-                targets cope with that.  */
+                consider special.  They use minimal symbols to do that
+                and this is needed for correct breakpoint placement,
+                but we do not have full data here to build a complete
+                minimal symbol, so just set the address and let the
+                targets cope with that.  */
              if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
                  && gdbarch_elf_make_msymbol_special_p (gdbarch))
                {
@@ -1556,13 +1561,19 @@ _initialize_solib ()
 {
   solib_data = gdbarch_data_register_pre_init (solib_init);
 
-  gdb::observers::free_objfile.attach (remove_user_added_objfile);
+  gdb::observers::free_objfile.attach (remove_user_added_objfile,
+                                      "solib");
+  gdb::observers::inferior_execd.attach ([] (inferior *inf)
+    {
+      solib_create_inferior_hook (0);
+    }, "solib");
 
   add_com ("sharedlibrary", class_files, sharedlibrary_command,
           _("Load shared object library symbols for files matching REGEXP."));
-  add_info ("sharedlibrary", info_sharedlibrary_command,
-           _("Status of loaded shared object libraries."));
-  add_info_alias ("dll", "sharedlibrary", 1);
+  cmd_list_element *info_sharedlibrary_cmd
+    = add_info ("sharedlibrary", info_sharedlibrary_command,
+               _("Status of loaded shared object libraries."));
+  add_info_alias ("dll", info_sharedlibrary_cmd, 1);
   add_com ("nosharedlibrary", class_files, no_shared_libraries,
           _("Unload all shared object library symbols."));
 
@@ -1579,20 +1590,21 @@ inferior.  Otherwise, symbols must be loaded manually, using \
                           show_auto_solib_add,
                           &setlist, &showlist);
 
-  add_setshow_optional_filename_cmd ("sysroot", class_support,
-                                    &gdb_sysroot, _("\
+  set_show_commands sysroot_cmds
+    = add_setshow_optional_filename_cmd ("sysroot", class_support,
+                                        &gdb_sysroot, _("\
 Set an alternate system root."), _("\
 Show the current system root."), _("\
 The system root is used to load absolute shared library symbol files.\n\
 For other (relative) files, you can add directories using\n\
 `set solib-search-path'."),
-                                    gdb_sysroot_changed,
-                                    NULL,
-                                    &setlist, &showlist);
+                                        gdb_sysroot_changed,
+                                        NULL,
+                                        &setlist, &showlist);
 
-  add_alias_cmd ("solib-absolute-prefix", "sysroot", class_support, 0,
+  add_alias_cmd ("solib-absolute-prefix", sysroot_cmds.set, class_support, 0,
                 &setlist);
-  add_alias_cmd ("solib-absolute-prefix", "sysroot", class_support, 0,
+  add_alias_cmd ("solib-absolute-prefix", sysroot_cmds.show, class_support, 0,
                 &showlist);
 
   add_setshow_optional_filename_cmd ("solib-search-path", class_support,