/* 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.
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:".
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
}
/* 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;
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. */
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)
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))
{
{
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."));
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,