/* 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.
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;
}
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;
}
/* 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.
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);
}
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;
/* 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;
}
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. */
{
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");
/* 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. */
{
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);
&& 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;
}
/* 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
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;
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;
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);
_("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."));