22 #include <sys/types.h>
38 #include "filenames.h"
42 #include "readline/readline.h"
91 #define so_list_head current_program_space->so_list
104 "shared library symbol files is %s.\n"),
109 #if (HAVE_DOS_BASED_FILE_SYSTEM)
110 # define DOS_BASED_FILE_SYSTEM 1
112 # define DOS_BASED_FILE_SYSTEM 0
157 char *temp_pathname = NULL;
161 int prefix_len, orig_prefix_len;
173 prefix_len = orig_prefix_len = strlen (sysroot);
175 while (prefix_len > 0 && IS_DIR_SEPARATOR (sysroot[prefix_len - 1]))
180 else if (prefix_len != orig_prefix_len)
195 p = alloca (strlen (in_pathname) + 1);
196 strcpy (p, in_pathname);
219 temp_pathname = xstrdup (in_pathname);
222 int need_dir_separator;
241 need_dir_separator = !(IS_DIR_SEPARATOR (in_pathname[0])
245 temp_pathname = concat (sysroot,
247 in_pathname, (
char *) NULL);
256 return temp_pathname;
262 xfree (temp_pathname);
273 int need_dir_separator = !IS_DIR_SEPARATOR (in_pathname[2]);
276 temp_pathname = concat (sysroot,
280 in_pathname + 2, (
char *) NULL);
286 xfree (temp_pathname);
294 temp_pathname = concat (sysroot,
295 need_dir_separator ? SLASH_STRING :
"",
296 in_pathname + 2, (
char *) NULL);
300 xfree (temp_pathname);
312 temp_pathname = NULL;
331 if (is_solib && found_file < 0 && solib_search_path != NULL)
332 found_file =
openp (solib_search_path,
334 in_pathname, O_RDONLY |
O_BINARY, &temp_pathname);
340 if (is_solib && found_file < 0 && solib_search_path != NULL)
341 found_file =
openp (solib_search_path,
344 O_RDONLY |
O_BINARY, &temp_pathname);
348 if (is_solib && found_file < 0 && ops->find_and_open_solib)
353 if (found_file < 0 && sysroot == NULL)
357 O_RDONLY |
O_BINARY, &temp_pathname);
361 if (is_solib && found_file < 0 && sysroot == NULL)
365 O_RDONLY |
O_BINARY, &temp_pathname);
375 return temp_pathname;
399 new_pathname = alloca (strlen (in_pathname) + 5);
400 strcpy (new_pathname, in_pathname);
401 strcat (new_pathname,
".exe");
421 const char *solib_symbols_extension
426 if (solib_symbols_extension != NULL)
428 char *p = in_pathname + strlen (in_pathname);
430 while (p > in_pathname && *p !=
'.')
437 new_pathname = alloca (p - in_pathname + 1
438 + strlen (solib_symbols_extension) + 1);
439 memcpy (new_pathname, in_pathname, p - in_pathname + 1);
440 strcpy (new_pathname + (p - in_pathname) + 1,
441 solib_symbols_extension);
443 in_pathname = new_pathname;
464 bfd_set_cacheable (abfd, 1);
469 error (
_(
"Could not open `%s' as an executable file: %s"),
470 pathname, bfd_errmsg (bfd_get_error ()));
483 char *found_pathname;
486 const struct bfd_arch_info *b;
489 found_pathname =
solib_find (pathname, &found_file);
490 if (found_pathname == NULL)
504 if (!bfd_check_format (abfd, bfd_object))
507 error (
_(
"`%s': not in executable format: %s"),
508 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
513 if (!b->compatible (b, bfd_get_arch_info (abfd)))
514 warning (
_(
"`%s': Shared library architecture %s is not compatible "
515 "with target architecture %s."), bfd_get_filename (abfd),
516 bfd_get_arch_info (abfd)->printable_name, b->printable_name);
542 filename = tilde_expand (so->
so_name);
560 error (
_(
"Shared library file name is too long."));
561 strcpy (so->
so_name, bfd_get_filename (abfd));
565 error (
_(
"Can't find the file sections in `%s': %s"),
566 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
569 for (p = so->
sections; p < so->sections_end; p++)
675 else if (so->
abfd == NULL)
712 " library symbols for %s:\n"),
778 "Error reading attached process's symbol file.\n",
811 struct so_list **i_link = &inferior;
819 if (ops->
same (gdb, i))
839 gdb_link = &gdb->
next;
853 *gdb_link = gdb->
next;
875 const char *not_found_filename = NULL;
880 *gdb_link = inferior;
883 for (i = inferior; i; i = i->
next)
895 if (not_found_filename == NULL)
903 _(
"Error while mapping shared "
904 "library sections:\n"));
921 warning (
_(
"Could not load shared library symbols for %s.\n"
922 "Do you need \"set solib-search-path\" "
923 "or \"set sysroot\"?"),
925 else if (not_found > 1)
927 Could not load shared library symbols for %d libraries, e.g. %s.\n\
928 Use the \"info sharedlibrary\" command to see the complete listing.\n\
929 Do you need \"set solib-search-path\" or \"set sysroot\"?"),
930 not_found, not_found_filename);
944 return (strstr (name,
"/libpthread") != NULL);
985 char *re_err =
re_comp (pattern);
988 error (
_(
"Invalid regexp: %s"), re_err);
998 int loaded_any_symbols = 0;
1003 if (! pattern || re_exec (gdb->
so_name))
1010 const int add_this_solib =
1025 loaded_any_symbols = 1;
1029 if (loaded_any_symbols)
1032 if (from_tty && pattern && ! any_matches)
1034 (
"No loaded shared libraries match the pattern `%s'.\n", pattern);
1036 if (loaded_any_symbols)
1058 int so_missing_debug_info = 0;
1061 struct cleanup *table_cleanup;
1067 char *re_err =
re_comp (pattern);
1070 error (
_(
"Invalid regexp: %s"), re_err);
1085 if (pattern && ! re_exec (so->
so_name))
1093 "SharedLibraryTable");
1100 "name",
"Shared Object Library");
1110 if (pattern && ! re_exec (so->
so_name))
1130 so_missing_debug_info = 1;
1150 _(
"No shared libraries matched.\n"));
1153 _(
"No shared libraries loaded at this time.\n"));
1157 if (so_missing_debug_info)
1159 _(
"(*): Shared library is missing "
1160 "debugging information.\n"));
1172 for (p = solib->
sections; p < solib->sections_end; p++)
1247 && bfd_get_flavour (
exec_bfd) != bfd_target_aout_flavour)
1358 char *filename, *found_pathname = NULL;
1369 found_pathname = xstrdup (bfd_get_filename (abfd));
1376 if ((found_pathname == NULL && was_loaded)
1377 || (found_pathname != NULL
1378 && filename_cmp (found_pathname, so->
so_name) != 0))
1389 if (found_pathname != NULL
1391 || filename_cmp (found_pathname, so->
so_name) != 0))
1403 _(
"Error while mapping "
1404 "shared library sections:\n"));
1479 const char *old_prefix =
"remote:";
1484 static int warning_issued = 0;
1486 gdb_assert (strlen (old_prefix) == strlen (new_prefix));
1487 memcpy (
gdb_sysroot, new_prefix, strlen (new_prefix));
1489 if (!warning_issued)
1491 warning (
_(
"\"%s\" is deprecated, use \"%s\" instead."),
1492 old_prefix, new_prefix);
1533 int (*match_sym) (asymbol *,
void *),
1536 long storage_needed = bfd_get_symtab_upper_bound (abfd);
1539 if (storage_needed > 0)
1543 asymbol **symbol_table = (asymbol **)
xmalloc (storage_needed);
1545 unsigned int number_of_symbols =
1546 bfd_canonicalize_symtab (abfd, symbol_table);
1548 for (i = 0; i < number_of_symbols; i++)
1550 asymbol *sym = *symbol_table++;
1552 if (match_sym (sym, data))
1555 symaddr = sym->value;
1563 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
1568 memset (&msym, 0,
sizeof (msym));
1575 symaddr += sym->section->vma;
1592 int (*match_sym) (asymbol *,
void *),
1595 long storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
1598 if (storage_needed > 0)
1601 asymbol **symbol_table = (asymbol **)
xmalloc (storage_needed);
1603 unsigned int number_of_symbols =
1604 bfd_canonicalize_dynamic_symtab (abfd, symbol_table);
1606 for (i = 0; i < number_of_symbols; i++)
1608 asymbol *sym = *symbol_table++;
1610 if (match_sym (sym, data))
1613 symaddr = sym->value + sym->section->vma;
1630 int (*match_sym) (asymbol *,
void *),
1670 _(
"Load shared object library symbols for files matching REGEXP."));
1672 _(
"Status of loaded shared object libraries."));
1675 _(
"Unload all shared object library symbols."));
1679 Set autoloading of shared library symbols."),
_(
"\
1680 Show autoloading of shared library symbols."),
_(
"\
1681 If \"on\", symbols from all shared object libraries will be loaded\n\
1682 automatically when the inferior begins execution, when the dynamic linker\n\
1683 informs gdb that a new library has been loaded, or when attaching to the\n\
1684 inferior. Otherwise, symbols must be loaded manually, using \
1692 Set an alternate system root."),
_(
"\
1693 Show the current system root."),
_(
"\
1694 The system root is used to load absolute shared library symbol files.\n\
1695 For other (relative) files, you can add directories using\n\
1696 `set solib-search-path'."),
1707 &solib_search_path,
_(
"\
1708 Set the search path for loading non-absolute shared library symbol files."),
1710 Show the search path for loading non-absolute shared library symbol files."),
1712 This takes precedence over the environment variables \
1713 PATH and LD_LIBRARY_PATH."),
struct gdbarch * target_gdbarch(void)
#define IS_TARGET_ABSOLUTE_PATH(kind, p)
struct symbol *(* lookup_lib_global_symbol)(struct objfile *objfile, const char *name, const domain_enum domain)
static void reload_shared_libraries(char *ignored, int from_tty, struct cmd_list_element *e)
int in_solib_dynsym_resolve_code(CORE_ADDR pc)
void handle_solib_event(void)
void remove_solib_event_breakpoints(void)
#define HAS_TARGET_DRIVE_SPEC(kind, p)
struct target_section * sections
struct observer * observer_attach_free_objfile(observer_free_objfile_ftype *f)
static const struct target_so_ops * solib_ops(struct gdbarch *gdbarch)
int ptid_equal(ptid_t ptid1, ptid_t ptid2)
void no_shared_libraries(char *ignored, int from_tty)
struct objfile * symbol_file_add_from_bfd(bfd *abfd, const char *name, int add_flags, struct section_addr_info *addrs, int flags, struct objfile *parent)
static int solib_used(const struct so_list *const known)
void set_solib_ops(struct gdbarch *gdbarch, const struct target_so_ops *new_ops)
void warning(const char *fmt,...)
int objfile_has_symbols(struct objfile *objfile)
#define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value)
int gdbarch_ptr_bit(struct gdbarch *gdbarch)
struct cleanup * make_cleanup_ui_out_table_begin_end(struct ui_out *ui_out, int nr_cols, int nr_rows, const char *tblid)
void(* update_breakpoints)(void)
int build_section_table(struct bfd *some_bfd, struct target_section **start, struct target_section **end)
void * gdbarch_data(struct gdbarch *gdbarch, struct gdbarch_data *data)
initialize_file_ftype _initialize_solib
enum domain_enum_tag domain_enum
#define IS_TARGET_DIR_SEPARATOR(kind, c)
void(* relocate_section_addresses)(struct so_list *so, struct target_section *)
void(* solib_create_inferior_hook)(int from_tty)
struct ui_out * interp_ui_out(struct interp *interp)
struct so_list *(* current_sos)(void)
int ui_out_is_mi_like_p(struct ui_out *uiout)
bfd *(* bfd_open)(char *pathname)
bfd * solib_bfd_fopen(char *pathname, int fd)
int catch_errors(catch_errors_ftype *func, void *func_args, char *errstring, return_mask mask)
#define VEC_safe_push(T, V, O)
struct gdbarch_data * gdbarch_data_register_pre_init(gdbarch_data_pre_init_ftype *pre_init)
#define SO_NAME_MAX_PATH_SIZE
struct bfd * gdb_bfd_open(const char *name, const char *target, int fd)
CORE_ADDR gdb_bfd_lookup_symbol_from_symtab(bfd *abfd, int(*match_sym)(asymbol *, void *), void *data)
int(* keep_data_in_core)(CORE_ADDR vaddr, unsigned long size)
void free_section_addr_info(struct section_addr_info *sap)
struct symbol * solib_global_lookup(struct objfile *objfile, const char *name, const domain_enum domain)
static int solib_map_sections(struct so_list *so)
void ui_out_text(struct ui_out *uiout, const char *string)
int(* open_symbol_file_object)(void *from_ttyp)
void gdbarch_elf_make_msymbol_special(struct gdbarch *gdbarch, asymbol *sym, struct minimal_symbol *msym)
struct target_section * sections_end
#define TARGET_SYSROOT_PREFIX
const char file_system_kind_dos_based[]
mach_port_t kern_return_t mach_port_t msgports mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
void null_cleanup(void *arg)
void(* clear_solib)(void)
char * solib_find(char *in_pathname, int *fd)
#define MSYMBOL_VALUE_RAW_ADDRESS(symbol)
struct so_list * master_so_list(void)
struct cmd_list_element * setlist
#define ALL_OBJFILES(obj)
int(* in_dynsym_resolve_code)(CORE_ADDR pc)
void breakpoint_re_set(void)
#define CATCH(EXCEPTION, MASK)
int solib_contains_address_p(const struct so_list *const solib, CORE_ADDR address)
#define OPF_TRY_CWD_FIRST
const char * target_lbasename(const char *kind, const char *name)
void ui_out_field_skip(struct ui_out *uiout, const char *fldname)
void free_objfile(struct objfile *objfile)
static void sharedlibrary_command(char *args, int from_tty)
struct target_ops current_target
void gdb_bfd_unref(struct bfd *abfd)
void initialize_file_ftype(void)
struct cleanup * make_cleanup_ui_out_tuple_begin_end(struct ui_out *uiout, const char *id)
CORE_ADDR gdb_bfd_lookup_symbol(bfd *abfd, int(*match_sym)(asymbol *, void *), void *data)
void observer_notify_solib_unloaded(struct so_list *solib)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
int openp(const char *, int, const char *, int, char **)
#define DOS_BASED_FILE_SYSTEM
void remove_target_sections(void *owner)
void target_terminal_inferior(void)
static char * solib_find_1(char *in_pathname, int *fd, int is_solib)
struct cmd_list_element * showlist
#define target_filesystem_is_local()
void ui_out_message(struct ui_out *uiout, int verbosity, const char *format,...)
char so_original_name[SO_NAME_MAX_PATH_SIZE]
int solib_read_symbols(struct so_list *so, int flags)
void free_so(struct so_list *so)
void solib_add(const char *pattern, int from_tty, struct target_ops *target, int readsyms)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
void clear_program_space_solib_cache(struct program_space *pspace)
void(* handle_event)(void)
char * solib_name_from_address(struct program_space *pspace, CORE_ADDR address)
static struct gdbarch_data * solib_data
char so_name[SO_NAME_MAX_PATH_SIZE]
void(* clear_so)(struct so_list *so)
struct cmd_list_element * add_info(const char *name, cmd_cfunc_ftype *fun, const char *doc)
int(* same)(struct so_list *gdb, struct so_list *inferior)
char * get_in_environ(const struct gdb_environ *e, const char *var)
void exception_fprintf(struct ui_file *file, struct gdb_exception e, const char *prefix,...)
static int startswith(const char *string, const char *pattern)
struct cmd_list_element * add_alias_cmd(const char *name, const char *oldname, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
void disable_breakpoints_in_shlibs(void)
static void update_solib_list(int from_tty, struct target_ops *target)
#define target_has_execution
static char * solib_search_path
void printf_unfiltered(const char *format,...)
unsigned solib_add_generation
struct bfd_section * the_bfd_section
const char * objfile_name(const struct objfile *objfile)
struct program_space * pspace
struct cleanup * make_cleanup_bfd_unref(bfd *abfd)
void(* special_symbol_handling)(void)
static void remove_user_added_objfile(struct objfile *objfile)
void objfile_purge_solibs(void)
const char * effective_target_file_system_kind(void)
static void show_solib_search_path(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
static CORE_ADDR bfd_lookup_symbol_from_dyn_symtab(bfd *abfd, int(*match_sym)(asymbol *, void *), void *data)
struct ui_file * gdb_stderr
void(* free_so)(struct so_list *so)
void add_target_sections(void *owner, struct target_section *sections, struct target_section *sections_end)
static void info_sharedlibrary_command(char *pattern, int from_tty)
void solib_create_inferior_hook(int from_tty)
int libpthread_name_p(const char *name)
#define OPF_RETURN_REALPATH
int print_symbol_loading_p(int from_tty, int exec, int full)
const char * gdbarch_solib_symbols_extension(struct gdbarch *gdbarch)
struct section_addr_info * build_section_addr_info_from_section_table(const struct target_section *start, const struct target_section *end)
int gdbarch_elf_make_msymbol_special_p(struct gdbarch *gdbarch)
char * exec_file_find(char *in_pathname, int *fd)
void ui_out_table_header(struct ui_out *uiout, int width, enum ui_align alignment, const char *col_name, const char *colhdr)
struct target_so_ops * current_target_so_ops
int gdb_open_cloexec(const char *filename, int flags, unsigned long mode)
struct inferior * current_inferior(void)
struct cmd_list_element * add_info_alias(const char *name, const char *oldname, int abbrev_flag)
EXTERN_C char * re_comp(const char *)
struct program_space * current_program_space
void ui_out_field_core_addr(struct ui_out *uiout, const char *fldname, struct gdbarch *gdbarch, CORE_ADDR address)
char * savestring(const char *ptr, size_t len)
static void * solib_init(struct obstack *obstack)
int(* find_and_open_solib)(char *soname, unsigned o_flags, char **temp_pathname)
struct interp * top_level_interpreter(void)
static void gdb_sysroot_changed(char *ignored, int from_tty, struct cmd_list_element *e)
void update_solib_breakpoints(void)
void observer_notify_solib_loaded(struct so_list *solib)
const struct bfd_arch_info * gdbarch_bfd_arch_info(struct gdbarch *gdbarch)
void target_terminal_ours_for_output(void)
void ui_out_field_string(struct ui_out *uiout, const char *fldname, const char *string)
#define OBSTACK_ZALLOC(OBSTACK, TYPE)
void ui_out_table_body(struct ui_out *uiout)
void reinit_frame_cache(void)
struct ui_out * current_uiout
static void reload_shared_libraries_1(int from_tty)
static void show_auto_solib_add(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static int libpthread_solib_p(struct so_list *so)
int is_target_filename(const char *name)
void error(const char *fmt,...)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc)
void add_setshow_optional_filename_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
bfd * solib_bfd_open(char *pathname)
int solib_keep_data_in_core(CORE_ADDR vaddr, unsigned long size)
void do_cleanups(struct cleanup *old_chain)
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static void clear_so(struct so_list *so)
__extension__ enum domain_enum_tag domain
int gdb_bfd_has_target_filename(struct bfd *abfd)