Close gdbserver in mi_gdb_exit
[deliverable/binutils-gdb.git] / gdb / solib.c
index 2466235678e0b064a5e1190714126968b7fb5050..22355058b3e8d001d2cdcbb275b65a9b676bd43a 100644 (file)
@@ -1,6 +1,6 @@
 /* Handle shared libraries for GDB, the GNU Debugger.
 
-   Copyright (C) 1990-2015 Free Software Foundation, Inc.
+   Copyright (C) 1990-2016 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -65,7 +65,8 @@ solib_init (struct obstack *obstack)
 static const struct target_so_ops *
 solib_ops (struct gdbarch *gdbarch)
 {
-  const struct target_so_ops **ops = gdbarch_data (gdbarch, solib_data);
+  const struct target_so_ops **ops
+    = (const struct target_so_ops **) gdbarch_data (gdbarch, solib_data);
 
   return *ops;
 }
@@ -75,7 +76,8 @@ solib_ops (struct gdbarch *gdbarch)
 void
 set_solib_ops (struct gdbarch *gdbarch, const struct target_so_ops *new_ops)
 {
-  const struct target_so_ops **ops = gdbarch_data (gdbarch, solib_data);
+  const struct target_so_ops **ops
+    = (const struct target_so_ops **) gdbarch_data (gdbarch, solib_data);
 
   *ops = new_ops;
 }
@@ -114,8 +116,9 @@ show_solib_search_path (struct ui_file *file, int from_tty,
 
 /* Return the full pathname of a binary file (the main executable
    or a shared library file), or NULL if not found.  The returned
-   pathname is malloc'ed and must be freed by the caller.  *FD is
-   set to either -1 or an open file handle for the binary file.
+   pathname is malloc'ed and must be freed by the caller.  If FD
+   is non-NULL, *FD is set to either -1 or an open file handle for
+   the binary file.
 
    Global variable GDB_SYSROOT is used as a prefix directory
    to search for binary files if they have an absolute path.
@@ -157,32 +160,27 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
   const char *fskind = effective_target_file_system_kind ();
   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   char *sysroot = gdb_sysroot;
-
-  if (sysroot != NULL)
-    {
-      /* If the absolute prefix starts with "target:" but the
-        filesystem accessed by the target_fileio_* methods
-        is the local filesystem then we strip the "target:"
-        prefix now and work with the local filesystem.  This
-        ensures that the same search algorithm is used for
-        all local files regardless of whether a "target:"
-        prefix was used.  */
-      if (is_target_filename (sysroot) && target_filesystem_is_local ())
-       sysroot += strlen (TARGET_SYSROOT_PREFIX);
-
-      if (*sysroot == '\0')
-       sysroot = NULL;
-    }
-
-  if (sysroot != NULL)
+  int prefix_len, orig_prefix_len;
+
+  /* If the absolute prefix starts with "target:" but the filesystem
+     accessed by the target_fileio_* methods is the local filesystem
+     then we strip the "target:" prefix now and work with the local
+     filesystem.  This ensures that the same search algorithm is used
+     for all local files regardless of whether a "target:" prefix was
+     used.  */
+  if (is_target_filename (sysroot) && target_filesystem_is_local ())
+    sysroot += strlen (TARGET_SYSROOT_PREFIX);
+
+  /* Strip any trailing slashes from the absolute prefix.  */
+  prefix_len = orig_prefix_len = strlen (sysroot);
+
+  while (prefix_len > 0 && IS_DIR_SEPARATOR (sysroot[prefix_len - 1]))
+    prefix_len--;
+
+  if (prefix_len == 0)
+    sysroot = NULL;
+  else if (prefix_len != orig_prefix_len)
     {
-      int prefix_len = strlen (sysroot);
-
-      /* Remove trailing slashes from absolute prefix.  */
-      while (prefix_len > 0
-            && IS_DIR_SEPARATOR (sysroot[prefix_len - 1]))
-       prefix_len--;
-
       sysroot = savestring (sysroot, prefix_len);
       make_cleanup (xfree, sysroot);
     }
@@ -196,7 +194,7 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
       char *p;
 
       /* Avoid clobbering our input.  */
-      p = alloca (strlen (in_pathname) + 1);
+      p = (char *) alloca (strlen (in_pathname) + 1);
       strcpy (p, in_pathname);
       in_pathname = p;
 
@@ -254,7 +252,8 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
   /* Handle files to be accessed via the target.  */
   if (is_target_filename (temp_pathname))
     {
-      *fd = -1;
+      if (fd != NULL)
+       *fd = -1;
       do_cleanups (old_chain);
       return temp_pathname;
     }
@@ -367,14 +366,21 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
                        OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, in_pathname,
                        O_RDONLY | O_BINARY, &temp_pathname);
 
-  *fd = found_file;
+  if (fd == NULL)
+    {
+      if (found_file >= 0)
+       close (found_file);
+    }
+  else
+    *fd = found_file;
+
   return temp_pathname;
 }
 
 /* Return the full pathname of the main executable, or NULL if not
    found.  The returned pathname is malloc'ed and must be freed by
-   the caller.  *FD is set to either -1 or an open file handle for
-   the main executable.
+   the caller.  If FD is non-NULL, *FD is set to either -1 or an open
+   file handle for the main executable.
 
    The search algorithm used is described in solib_find_1's comment
    above.  */
@@ -392,7 +398,7 @@ exec_file_find (char *in_pathname, int *fd)
        {
          char *new_pathname;
 
-         new_pathname = alloca (strlen (in_pathname) + 5);
+         new_pathname = (char *) alloca (strlen (in_pathname) + 5);
          strcpy (new_pathname, in_pathname);
          strcat (new_pathname, ".exe");
 
@@ -405,8 +411,8 @@ exec_file_find (char *in_pathname, int *fd)
 
 /* Return the full pathname of a shared library file, or NULL if not
    found.  The returned pathname is malloc'ed and must be freed by
-   the caller.  *FD is set to either -1 or an open file handle for
-   the shared library.
+   the caller.  If FD is non-NULL, *FD is set to either -1 or an open
+   file handle for the shared library.
 
    The search algorithm used is described in solib_find_1's comment
    above.  */
@@ -430,8 +436,9 @@ solib_find (char *in_pathname, int *fd)
        {
          char *new_pathname;
 
-         new_pathname = alloca (p - in_pathname + 1
-                                + strlen (solib_symbols_extension) + 1);
+         new_pathname
+           = (char *) alloca (p - in_pathname + 1
+                              + strlen (solib_symbols_extension) + 1);
          memcpy (new_pathname, in_pathname, p - in_pathname + 1);
          strcpy (new_pathname + (p - in_pathname) + 1,
                  solib_symbols_extension);
@@ -689,16 +696,16 @@ solib_read_symbols (struct so_list *so, int flags)
                  && so->objfile->addr_low == so->addr_low)
                break;
            }
-         if (so->objfile != NULL)
-           break;
-
-         sap = build_section_addr_info_from_section_table (so->sections,
-                                                           so->sections_end);
-         so->objfile = symbol_file_add_from_bfd (so->abfd, so->so_name,
-                                                 flags, sap, OBJF_SHARED,
-                                                 NULL);
-         so->objfile->addr_low = so->addr_low;
-         free_section_addr_info (sap);
+         if (so->objfile == NULL)
+           {
+             sap = build_section_addr_info_from_section_table (so->sections,
+                                                               so->sections_end);
+             so->objfile = symbol_file_add_from_bfd (so->abfd, so->so_name,
+                                                     flags, sap, OBJF_SHARED,
+                                                     NULL);
+             so->objfile->addr_low = so->addr_low;
+             free_section_addr_info (sap);
+           }
 
          so->symbols_loaded = 1;
        }
@@ -1507,16 +1514,16 @@ show_auto_solib_add (struct ui_file *file, int from_tty,
 /* Handler for library-specific lookup of global symbol NAME in OBJFILE.  Call
    the library-specific handler if it is installed for the current target.  */
 
-struct symbol *
+struct block_symbol
 solib_global_lookup (struct objfile *objfile,
                     const char *name,
                     const domain_enum domain)
 {
-  const struct target_so_ops *ops = solib_ops (get_objfile_arch (objfile));
+  const struct target_so_ops *ops = solib_ops (target_gdbarch ());
 
   if (ops->lookup_lib_global_symbol != NULL)
     return ops->lookup_lib_global_symbol (objfile, name, domain);
-  return NULL;
+  return (struct block_symbol) {NULL, NULL};
 }
 
 /* Lookup the value for a specific symbol from dynamic symbol table.  Look
@@ -1526,8 +1533,9 @@ solib_global_lookup (struct objfile *objfile,
 
 CORE_ADDR
 gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
-                                  int (*match_sym) (asymbol *, void *),
-                                  void *data)
+                                  int (*match_sym) (const asymbol *,
+                                                    const void *),
+                                  const void *data)
 {
   long storage_needed = bfd_get_symtab_upper_bound (abfd);
   CORE_ADDR symaddr = 0;
@@ -1585,8 +1593,9 @@ gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
 
 static CORE_ADDR
 bfd_lookup_symbol_from_dyn_symtab (bfd *abfd,
-                                  int (*match_sym) (asymbol *, void *),
-                                  void *data)
+                                  int (*match_sym) (const asymbol *,
+                                                    const void *),
+                                  const void *data)
 {
   long storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
   CORE_ADDR symaddr = 0;
@@ -1623,8 +1632,8 @@ bfd_lookup_symbol_from_dyn_symtab (bfd *abfd,
 
 CORE_ADDR
 gdb_bfd_lookup_symbol (bfd *abfd,
-                      int (*match_sym) (asymbol *, void *),
-                      void *data)
+                      int (*match_sym) (const asymbol *, const void *),
+                      const void *data)
 {
   CORE_ADDR symaddr = gdb_bfd_lookup_symbol_from_symtab (abfd, match_sym, data);
 
@@ -1666,6 +1675,7 @@ _initialize_solib (void)
           _("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);
   add_com ("nosharedlibrary", class_files, no_shared_libraries,
           _("Unload all shared object library symbols."));
 
This page took 0.028394 seconds and 4 git commands to generate.