/* Handle shared libraries for GDB, the GNU Debugger.
- Copyright (C) 1990-2013 Free Software Foundation, Inc.
+ Copyright (C) 1990-2014 Free Software Foundation, Inc.
This file is part of GDB.
#include <sys/types.h>
#include <fcntl.h>
-#include "gdb_string.h"
#include "symtab.h"
#include "bfd.h"
#include "symfile.h"
#include "objfiles.h"
-#include "exceptions.h"
#include "gdbcore.h"
#include "command.h"
#include "target.h"
{
int need_dir_separator;
- need_dir_separator = (!IS_DIR_SEPARATOR (in_pathname[0])
- && !HAS_TARGET_DRIVE_SPEC (fskind, in_pathname));
+ /* Concatenate the sysroot and the target reported filename. We
+ 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 |
+ | remote: | | c:/foo/bar.dll |
+ | remote: | | /foo/bar.dll |
+ | remote:some/dir | / | c:/foo/bar.dll |
+ | remote:some/dir | | /foo/bar.dll |
+
+ IOW, we don't need to add a separator if IN_PATHNAME already
+ has one, or when the the sysroot is exactly "remote:".
+ There's no need to check for drive spec explicitly, as we only
+ get here if IN_PATHNAME is considered an absolute path. */
+ need_dir_separator = !(IS_DIR_SEPARATOR (in_pathname[0])
+ || strcmp (REMOTE_SYSROOT_PREFIX, sysroot) == 0);
/* Cat the prefixed pathname together. */
temp_pathname = concat (sysroot,
/* If not found, search the solib_search_path (if any). */
if (found_file < 0 && solib_search_path != NULL)
- found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
+ found_file = openp (solib_search_path,
+ OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
in_pathname, O_RDONLY | O_BINARY, &temp_pathname);
/* If not found, next search the solib_search_path (if any) for the basename
only (ignoring the path). This is to allow reading solibs from a path
that differs from the opened path. */
if (found_file < 0 && solib_search_path != NULL)
- found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
+ found_file = openp (solib_search_path,
+ OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
target_lbasename (fskind, in_pathname),
O_RDONLY | O_BINARY, &temp_pathname);
if (found_file < 0 && gdb_sysroot_is_empty)
found_file = openp (get_in_environ (current_inferior ()->environment,
"PATH"),
- OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY,
- &temp_pathname);
+ OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, in_pathname,
+ O_RDONLY | O_BINARY, &temp_pathname);
/* If not found, next search the inferior's $LD_LIBRARY_PATH
environment variable. */
if (found_file < 0 && gdb_sysroot_is_empty)
found_file = openp (get_in_environ (current_inferior ()->environment,
"LD_LIBRARY_PATH"),
- OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY,
- &temp_pathname);
+ OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, in_pathname,
+ O_RDONLY | O_BINARY, &temp_pathname);
*fd = found_file;
return temp_pathname;
/* Leave bfd open, core_xfer_memory and "info files" need it. */
so->abfd = abfd;
+ /* Copy the full path name into so_name, allowing symbol_file_add
+ to find it later. This also affects the =library-loaded GDB/MI
+ event, and in particular the part of that notification providing
+ the library's host-side path. If we let the target dictate
+ that objfile's path, and the target is different from the host,
+ GDB/MI will not provide the correct host-side path. */
+ if (strlen (bfd_get_filename (abfd)) >= SO_NAME_MAX_PATH_SIZE)
+ error (_("Shared library file name is too long."));
+ strcpy (so->so_name, bfd_get_filename (abfd));
+
if (build_section_table (abfd, &so->sections, &so->sections_end))
{
error (_("Can't find the file sections in `%s': %s"),
int
solib_read_symbols (struct so_list *so, int flags)
{
- const int from_tty = flags & SYMFILE_VERBOSE;
-
if (so->symbols_loaded)
{
/* If needed, we've already warned in our caller. */
/* Have we already loaded this shared object? */
ALL_OBJFILES (so->objfile)
{
- if (filename_cmp (so->objfile->name, so->so_name) == 0
+ if (filename_cmp (objfile_name (so->objfile), so->so_name) == 0
&& so->objfile->addr_low == so->addr_low)
break;
}
sap = build_section_addr_info_from_section_table (so->sections,
so->sections_end);
- so->objfile = symbol_file_add_from_bfd (so->abfd,
+ so->objfile = symbol_file_add_from_bfd (so->abfd, so->so_name,
flags, sap, OBJF_SHARED,
NULL);
so->objfile->addr_low = so->addr_low;
" library symbols for %s:\n"),
so->so_name);
else
- {
- if (from_tty || info_verbose)
- printf_unfiltered (_("Loaded symbols for %s\n"), so->so_name);
- so->symbols_loaded = 1;
- }
+ so->symbols_loaded = 1;
return 1;
}
/* Some targets' section tables might be referring to
sections from so->abfd; remove them. */
- remove_target_sections (gdb, gdb->abfd);
+ remove_target_sections (gdb);
free_so (gdb);
gdb = *gdb_link;
FROM_TTY and TARGET are as described for update_solib_list, above. */
void
-solib_add (char *pattern, int from_tty,
+solib_add (const char *pattern, int from_tty,
struct target_ops *target, int readsyms)
{
struct so_list *gdb;
+ if (print_symbol_loading_p (from_tty, 0, 0))
+ {
+ if (pattern != NULL)
+ {
+ printf_unfiltered (_("Loading symbols for shared libraries: %s\n"),
+ pattern);
+ }
+ else
+ printf_unfiltered (_("Loading symbols for shared libraries.\n"));
+ }
+
current_program_space->solib_add_generation++;
if (pattern)
so_list_head = so->next;
observer_notify_solib_unloaded (so);
- if (so->abfd)
- remove_target_sections (so, so->abfd);
+ remove_target_sections (so);
free_so (so);
}
objfile_purge_solibs ();
}
+/* See solib.h. */
+
+void
+update_solib_breakpoints (void)
+{
+ const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+
+ if (ops->update_breakpoints != NULL)
+ ops->update_breakpoints ();
+}
+
+/* See solib.h. */
+
+void
+handle_solib_event (void)
+{
+ const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+
+ if (ops->handle_event != NULL)
+ ops->handle_event ();
+
+ clear_program_space_solib_cache (current_inferior ()->pspace);
+
+ /* Check for any newly added shared libraries if we're supposed to
+ be adding them automatically. Switch terminal for any messages
+ produced by breakpoint_re_set. */
+ target_terminal_ours_for_output ();
+ solib_add (NULL, 0, ¤t_target, auto_solib_add);
+ target_terminal_inferior ();
+}
+
/* Reload shared libraries, but avoid reloading the same symbol file
we already have loaded. */
struct so_list *so;
struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
+ if (print_symbol_loading_p (from_tty, 0, 0))
+ printf_unfiltered (_("Loading symbols for shared libraries.\n"));
+
for (so = so_list_head; so != NULL; so = so->next)
{
char *filename, *found_pathname = NULL;
if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED)
&& !solib_used (so))
free_objfile (so->objfile);
- remove_target_sections (so, so->abfd);
+ remove_target_sections (so);
clear_so (so);
}
the library-specific handler if it is installed for the current target. */
struct symbol *
-solib_global_lookup (const struct objfile *objfile,
+solib_global_lookup (struct objfile *objfile,
const char *name,
const domain_enum domain)
{
- const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+ const struct target_so_ops *ops = solib_ops (get_objfile_arch (objfile));
if (ops->lookup_lib_global_symbol != NULL)
return ops->lookup_lib_global_symbol (objfile, name, domain);
if (match_sym (sym, data))
{
+ struct gdbarch *gdbarch = target_gdbarch ();
+ 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. */
+ if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
+ && gdbarch_elf_make_msymbol_special_p (gdbarch))
+ {
+ struct minimal_symbol msym;
+
+ memset (&msym, 0, sizeof (msym));
+ SET_MSYMBOL_VALUE_ADDRESS (&msym, symaddr);
+ gdbarch_elf_make_msymbol_special (gdbarch, sym, &msym);
+ symaddr = MSYMBOL_VALUE_RAW_ADDRESS (&msym);
+ }
+
/* BFD symbols are section relative. */
- symaddr = sym->value + sym->section->vma;
+ symaddr += sym->section->vma;
break;
}
}
return symaddr;
}
+/* SO_LIST_HEAD may contain user-loaded object files that can be removed
+ out-of-band by the user. So upon notification of free_objfile remove
+ all references to any user-loaded file that is about to be freed. */
+
+static void
+remove_user_added_objfile (struct objfile *objfile)
+{
+ struct so_list *so;
+
+ if (objfile != 0 && objfile->flags & OBJF_USERLOADED)
+ {
+ for (so = so_list_head; so != NULL; so = so->next)
+ if (so->objfile == objfile)
+ so->objfile = NULL;
+ }
+}
+
extern initialize_file_ftype _initialize_solib; /* -Wmissing-prototypes */
void
{
solib_data = gdbarch_data_register_pre_init (solib_init);
+ observer_attach_free_objfile (remove_user_added_objfile);
+
add_com ("sharedlibrary", class_files, sharedlibrary_command,
_("Load shared object library symbols for files matching REGEXP."));
add_info ("sharedlibrary", info_sharedlibrary_command,