/* Handle SVR4 shared libraries for GDB, the GNU Debugger.
- Copyright (C) 1990-2018 Free Software Foundation, Inc.
+ Copyright (C) 1990-2019 Free Software Foundation, Inc.
This file is part of GDB.
static int svr4_have_link_map_offsets (void);
static void svr4_relocate_main_executable (void);
static void svr4_free_library_list (void *p_list);
+static void probes_table_remove_objfile_probes (struct objfile *objfile);
/* On SVR4 systems, a list of symbols in the dynamic linker where
GDB can try to place a breakpoint to monitor shared library
&& strcmp (inferior_so_name, "/lib/ld.so.1") == 0)
return 1;
- /* Similarly, we observed the same issue with sparc64, but with
+ /* Similarly, we observed the same issue with amd64 and sparcv9, but with
different locations. */
+ if (strcmp (gdb_so_name, "/usr/lib/amd64/ld.so.1") == 0
+ && strcmp (inferior_so_name, "/lib/amd64/ld.so.1") == 0)
+ return 1;
+
if (strcmp (gdb_so_name, "/usr/lib/sparcv9/ld.so.1") == 0
&& strcmp (inferior_so_name, "/lib/sparcv9/ld.so.1") == 0)
return 1;
struct type *ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
CORE_ADDR addr = 0;
- TRY
+ try
{
addr = read_memory_typed_address (info->debug_base + lmo->r_map_offset,
ptr_type);
}
- CATCH (ex, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &ex)
{
exception_print (gdb_stderr, ex);
}
- END_CATCH
return addr;
}
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
ULONGEST version = 0;
- TRY
+ try
{
/* Check version, and return zero if `struct r_debug' doesn't have
the r_ldsomap member. */
= read_memory_unsigned_integer (info->debug_base + lmo->r_version_offset,
lmo->r_version_size, byte_order);
}
- CATCH (ex, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &ex)
{
exception_print (gdb_stderr, ex);
}
- END_CATCH
if (version < 2 || lmo->r_ldsomap_offset == -1)
return 0;
CORE_ADDR main_lm;
};
+/* This module's 'free_objfile' observer. */
+
+static void
+svr4_free_objfile_observer (struct objfile *objfile)
+{
+ probes_table_remove_objfile_probes (objfile);
+}
+
/* Implementation for target_so_ops.free_so. */
static void
static int
svr4_parse_libraries (const char *document, struct svr4_library_list *list)
{
- struct cleanup *back_to = make_cleanup (svr4_free_library_list,
- &list->head);
+ auto cleanup = make_scope_exit ([&] ()
+ {
+ svr4_free_library_list (&list->head);
+ });
memset (list, 0, sizeof (*list));
list->tailp = &list->head;
svr4_library_list_elements, document, list) == 0)
{
/* Parsed successfully, keep the result. */
- discard_cleanups (back_to);
+ cleanup.release ();
return 1;
}
- do_cleanups (back_to);
return 0;
}
CORE_ADDR lm;
struct so_list *head = NULL;
struct so_list **link_ptr = &head;
- struct cleanup *back_to;
int ignore_first;
struct svr4_library_list library_list;
else
ignore_first = 1;
- back_to = make_cleanup (svr4_free_library_list, &head);
+ auto cleanup = make_scope_exit ([&] ()
+ {
+ svr4_free_library_list (&head);
+ });
/* Walk the inferior's link map list, and build our list of
`struct so_list' nodes. */
if (lm)
svr4_read_so_list (lm, 0, &link_ptr, 0);
- discard_cleanups (back_to);
+ cleanup.release ();
if (head == NULL)
return svr4_default_sos ();
if (objfile == symfile_objfile)
return info->main_lm_addr;
+ /* If OBJFILE is a separate debug object file, look for the
+ original object file. */
+ if (objfile->separate_debug_objfile_backlink != NULL)
+ objfile = objfile->separate_debug_objfile_backlink;
+
/* The other link map addresses may be found by examining the list
of shared libraries. */
for (so = master_so_list (); so; so = so->next)
/* The action. */
enum probe_action action;
+
+ /* The objfile where this probe was found. */
+ struct objfile *objfile;
};
/* Returns a hash code for the probe_and_action referenced by p. */
return pa1->address == pa2->address;
}
+/* Traversal function for probes_table_remove_objfile_probes. */
+
+static int
+probes_table_htab_remove_objfile_probes (void **slot, void *info)
+{
+ probe_and_action *pa = (probe_and_action *) *slot;
+ struct objfile *objfile = (struct objfile *) info;
+
+ if (pa->objfile == objfile)
+ htab_clear_slot (get_svr4_info ()->probes_table, slot);
+
+ return 1;
+}
+
+/* Remove all probes that belong to OBJFILE from the probes table. */
+
+static void
+probes_table_remove_objfile_probes (struct objfile *objfile)
+{
+ svr4_info *info = get_svr4_info ();
+ if (info->probes_table != nullptr)
+ htab_traverse_noresize (info->probes_table,
+ probes_table_htab_remove_objfile_probes, objfile);
+}
+
/* Register a solib event probe and its associated action in the
probes table. */
static void
-register_solib_event_probe (probe *prob, CORE_ADDR address,
+register_solib_event_probe (struct objfile *objfile,
+ probe *prob, CORE_ADDR address,
enum probe_action action)
{
struct svr4_info *info = get_svr4_info ();
equal_probe_and_action,
xfree, xcalloc, xfree);
- lookup.prob = prob;
lookup.address = address;
slot = htab_find_slot (info->probes_table, &lookup, INSERT);
gdb_assert (*slot == HTAB_EMPTY_ENTRY);
pa->prob = prob;
pa->address = address;
pa->action = action;
+ pa->objfile = objfile;
*slot = pa;
}
arg0: Lmid_t lmid (mandatory)
arg1: struct r_debug *debug_base (mandatory)
arg2: struct link_map *new (optional, for incremental updates) */
- TRY
+ try
{
probe_argc = pa->prob->get_argument_count (frame);
}
- CATCH (ex, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &ex)
{
exception_print (gdb_stderr, ex);
probe_argc = 0;
}
- END_CATCH
/* If get_argument_count throws an exception, probe_argc will be set
to zero. However, if pa->prob does not have arguments, then
ones set up for the probes-based interface are adequate. */
static void
-disable_probes_interface_cleanup (void *arg)
+disable_probes_interface ()
{
struct svr4_info *info = get_svr4_info ();
struct svr4_info *info = get_svr4_info ();
struct probe_and_action *pa;
enum probe_action action;
- struct cleanup *old_chain;
struct value *val = NULL;
CORE_ADDR pc, debug_base, lm = 0;
struct frame_info *frame = get_current_frame ();
/* If anything goes wrong we revert to the original linker
interface. */
- old_chain = make_cleanup (disable_probes_interface_cleanup, NULL);
+ auto cleanup = make_scope_exit (disable_probes_interface);
pc = regcache_read_pc (get_current_regcache ());
pa = solib_event_probe_at (info, pc);
if (pa == NULL)
- {
- do_cleanups (old_chain);
- return;
- }
+ return;
action = solib_event_probe_action (pa);
if (action == PROBES_INTERFACE_FAILED)
- {
- do_cleanups (old_chain);
- return;
- }
+ return;
if (action == DO_NOTHING)
{
- discard_cleanups (old_chain);
+ cleanup.release ();
return;
}
scoped_restore inhibit_updates
= inhibit_section_map_updates (current_program_space);
- TRY
+ try
{
val = pa->prob->evaluate_argument (1, frame);
}
- CATCH (ex, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &ex)
{
exception_print (gdb_stderr, ex);
val = NULL;
}
- END_CATCH
if (val == NULL)
- {
- do_cleanups (old_chain);
- return;
- }
+ return;
debug_base = value_as_address (val);
if (debug_base == 0)
- {
- do_cleanups (old_chain);
- return;
- }
+ return;
/* Always locate the debug struct, in case it moved. */
info->debug_base = 0;
if (locate_base (info) == 0)
- {
- do_cleanups (old_chain);
- return;
- }
+ return;
/* GDB does not currently support libraries loaded via dlmopen
into namespaces other than the initial one. We must ignore
if (action == UPDATE_OR_RELOAD)
{
- TRY
+ try
{
val = pa->prob->evaluate_argument (2, frame);
}
- CATCH (ex, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &ex)
{
exception_print (gdb_stderr, ex);
- do_cleanups (old_chain);
return;
}
- END_CATCH
if (val != NULL)
lm = value_as_address (val);
if (action == FULL_RELOAD)
{
if (!solist_update_full (info))
- {
- do_cleanups (old_chain);
- return;
- }
+ return;
}
- discard_cleanups (old_chain);
+ cleanup.release ();
}
/* Helper function for svr4_update_solib_event_breakpoints. */
CORE_ADDR address = p->get_relocated_address (objfile);
create_solib_event_breakpoint (gdbarch, address);
- register_solib_event_probe (p, address, action);
+ register_solib_event_probe (objfile, p, address, action);
}
}
mechanism to find the dynamic linker's base address. */
gdb_bfd_ref_ptr tmp_bfd;
- TRY
+ try
{
tmp_bfd = solib_bfd_open (interp_name);
}
- CATCH (ex, RETURN_MASK_ALL)
+ catch (const gdb_exception &ex)
{
}
- END_CATCH
if (tmp_bfd == NULL)
goto bkpt_at_symbol;
return 0;
}
-/* Read the ELF program headers from ABFD. Return the contents and
- set *PHDRS_SIZE to the size of the program headers. */
+/* Read the ELF program headers from ABFD. */
-static gdb_byte *
-read_program_headers_from_bfd (bfd *abfd, int *phdrs_size)
+static gdb::optional<gdb::byte_vector>
+read_program_headers_from_bfd (bfd *abfd)
{
- Elf_Internal_Ehdr *ehdr;
- gdb_byte *buf;
-
- ehdr = elf_elfheader (abfd);
-
- *phdrs_size = ehdr->e_phnum * ehdr->e_phentsize;
- if (*phdrs_size == 0)
- return NULL;
+ Elf_Internal_Ehdr *ehdr = elf_elfheader (abfd);
+ int phdrs_size = ehdr->e_phnum * ehdr->e_phentsize;
+ if (phdrs_size == 0)
+ return {};
- buf = (gdb_byte *) xmalloc (*phdrs_size);
+ gdb::byte_vector buf (phdrs_size);
if (bfd_seek (abfd, ehdr->e_phoff, SEEK_SET) != 0
- || bfd_bread (buf, *phdrs_size, abfd) != *phdrs_size)
- {
- xfree (buf);
- return NULL;
- }
+ || bfd_bread (buf.data (), phdrs_size, abfd) != phdrs_size)
+ return {};
return buf;
}
if (bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
{
- /* Be optimistic and clear OK only if GDB was able to verify the headers
+ /* Be optimistic and return 0 only if GDB was able to verify the headers
really do not match. */
- int phdrs2_size, ok = 1;
- gdb_byte *buf2;
int arch_size;
gdb::optional<gdb::byte_vector> phdrs_target
= read_program_header (-1, &arch_size, NULL);
- buf2 = read_program_headers_from_bfd (exec_bfd, &phdrs2_size);
- if (phdrs_target && buf2 != NULL)
+ gdb::optional<gdb::byte_vector> phdrs_binary
+ = read_program_headers_from_bfd (exec_bfd);
+ if (phdrs_target && phdrs_binary)
{
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
relocate BUF and BUF2 just by the EXEC_BFD vs. target memory
content offset for the verification purpose. */
- if (phdrs_target->size () != phdrs2_size
+ if (phdrs_target->size () != phdrs_binary->size ()
|| bfd_get_arch_size (exec_bfd) != arch_size)
- ok = 0;
+ return 0;
else if (arch_size == 32
&& phdrs_target->size () >= sizeof (Elf32_External_Phdr)
&& phdrs_target->size () % sizeof (Elf32_External_Phdr) == 0)
phdrp = &((Elf32_External_Phdr *) phdrs_target->data ())[i];
buf_vaddr_p = (gdb_byte *) &phdrp->p_vaddr;
buf_paddr_p = (gdb_byte *) &phdrp->p_paddr;
- phdr2p = &((Elf32_External_Phdr *) buf2)[i];
+ phdr2p = &((Elf32_External_Phdr *) phdrs_binary->data ())[i];
/* PT_GNU_STACK is an exception by being never relocated by
prelink as its addresses are always zero. */
continue;
}
- ok = 0;
- break;
+ return 0;
}
}
else if (arch_size == 64
phdrp = &((Elf64_External_Phdr *) phdrs_target->data ())[i];
buf_vaddr_p = (gdb_byte *) &phdrp->p_vaddr;
buf_paddr_p = (gdb_byte *) &phdrp->p_paddr;
- phdr2p = &((Elf64_External_Phdr *) buf2)[i];
+ phdr2p = &((Elf64_External_Phdr *) phdrs_binary->data ())[i];
/* PT_GNU_STACK is an exception by being never relocated by
prelink as its addresses are always zero. */
continue;
}
- ok = 0;
- break;
+ return 0;
}
}
else
- ok = 0;
+ return 0;
}
-
- xfree (buf2);
-
- if (!ok)
- return 0;
}
if (info_verbose)
}
if (abfd == NULL || scan_dyntag (DT_SYMBOLIC, abfd, NULL, NULL) != 1)
- return (struct block_symbol) {NULL, NULL};
+ return {};
return lookup_global_symbol_from_objfile (objfile, name, domain);
}
svr4_so_ops.keep_data_in_core = svr4_keep_data_in_core;
svr4_so_ops.update_breakpoints = svr4_update_solib_event_breakpoints;
svr4_so_ops.handle_event = svr4_handle_solib_event;
+
+ gdb::observers::free_objfile.attach (svr4_free_objfile_observer);
}