- /* We are setting up for a new scan through the loaded images. */
- if ((so_list_next = so_list_head) == NULL)
- {
- /* Find the first link map list member. */
- lm = first_link_map_member ();
- }
- }
- else
- {
- /* We have been called before, and are in the process of walking
- the shared library list. Advance to the next shared object. */
- lm = next_link_map_member (so_list_ptr);
- so_list_next = so_list_ptr->next;
- }
- if ((so_list_next == NULL) && (lm != NULL))
- {
- new = (struct so_list *) xmalloc (sizeof (struct so_list));
- memset ((char *) new, 0, sizeof (struct so_list));
- /* Add the new node as the next node in the list, or as the root
- node if this is the first one. */
- if (so_list_ptr != NULL)
- {
- so_list_ptr->next = new;
- }
- else
- {
- so_list_head = new;
- }
- so_list_next = new;
- xfer_link_map_member (new, lm);
- }
- return (so_list_next);
-}
-
-/* A small stub to get us past the arg-passing pinhole of catch_errors. */
-
-static int
-symbol_add_stub (void *arg)
-{
- register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */
- CORE_ADDR text_addr = 0;
- struct section_addr_info section_addrs;
-
- memset (§ion_addrs, 0, sizeof (section_addrs));
- if (so->textsection)
- text_addr = so->textsection->addr;
- else if (so->abfd != NULL)
- {
- asection *lowest_sect;
-
- /* If we didn't find a mapped non zero sized .text section, set up
- text_addr so that the relocation in symbol_file_add does no harm. */
-
- lowest_sect = bfd_get_section_by_name (so->abfd, ".text");
- if (lowest_sect == NULL)
- bfd_map_over_sections (so->abfd, find_lowest_section,
- (PTR) &lowest_sect);
- if (lowest_sect)
- text_addr = bfd_section_vma (so->abfd, lowest_sect) + LM_OFFSET (so);
- }
-
-
- section_addrs.other[0].name = ".text";
- section_addrs.other[0].addr = text_addr;
- so->objfile = symbol_file_add (so->so_name, so->from_tty,
- §ion_addrs, 0, 0);
- /* must be non-zero */
- return (1);
-}
-
-/*
-
- GLOBAL FUNCTION
-
- solib_add -- add a shared library file to the symtab and section list
-
- SYNOPSIS
-
- void solib_add (char *arg_string, int from_tty,
- struct target_ops *target)
-
- DESCRIPTION
-
- */
-
-void
-solib_add (char *arg_string, int from_tty, struct target_ops *target)
-{
- register struct so_list *so = NULL; /* link map state variable */
-
- /* Last shared library that we read. */
- struct so_list *so_last = NULL;
-
- char *re_err;
- int count;
- int old;
-
- if ((re_err = re_comp (arg_string ? arg_string : ".")) != NULL)
- {
- error ("Invalid regexp: %s", re_err);
- }
-
- /* Add the shared library sections to the section table of the
- specified target, if any. */
- if (target)
- {
- /* Count how many new section_table entries there are. */
- so = NULL;
- count = 0;
- while ((so = find_solib (so)) != NULL)
- {
- if (so->so_name[0])
- {
- count += so->sections_end - so->sections;
- }
- }
-
- if (count)
- {
- old = target_resize_to_sections (target, count);
-
- /* Add these section table entries to the target's table. */
- while ((so = find_solib (so)) != NULL)
- {
- if (so->so_name[0])
- {
- count = so->sections_end - so->sections;
- memcpy ((char *) (target->to_sections + old),
- so->sections,
- (sizeof (struct section_table)) * count);
- old += count;
- }
- }
- }
- }
-
- /* Now add the symbol files. */
- while ((so = find_solib (so)) != NULL)
- {
- if (so->so_name[0] && re_exec (so->so_name))
- {
- so->from_tty = from_tty;
- if (so->symbols_loaded)
- {
- if (from_tty)
- {
- printf_unfiltered ("Symbols already loaded for %s\n", so->so_name);
- }
- }
- else if (catch_errors
- (symbol_add_stub, (char *) so,
- "Error while reading shared library symbols:\n",
- RETURN_MASK_ALL))
- {
- so_last = so;
- so->symbols_loaded = 1;
- }
- }
- }
-
- /* Getting new symbols may change our opinion about what is
- frameless. */
- if (so_last)
- reinit_frame_cache ();
-}
-
-/*
-
- LOCAL FUNCTION
-
- info_sharedlibrary_command -- code for "info sharedlibrary"
-
- SYNOPSIS
-
- static void info_sharedlibrary_command ()
-
- DESCRIPTION
-
- Walk through the shared library list and print information
- about each attached library.
- */
-
-static void
-info_sharedlibrary_command (char *ignore, int from_tty)
-{
- register struct so_list *so = NULL; /* link map state variable */
- int header_done = 0;
-
- if (exec_bfd == NULL)
- {
- printf_unfiltered ("No executable file.\n");
- return;
- }
- while ((so = find_solib (so)) != NULL)
- {
- if (so->so_name[0])
- {
- if (!header_done)
- {
- printf_unfiltered ("%-12s%-12s%-12s%s\n", "From", "To", "Syms Read",
- "Shared Object Library");
- header_done++;
- }
- printf_unfiltered ("%-12s",
- local_hex_string_custom ((unsigned long) LM_ADDR (so),
- "08l"));
- printf_unfiltered ("%-12s",
- local_hex_string_custom ((unsigned long) so->lmend,
- "08l"));
- printf_unfiltered ("%-12s", so->symbols_loaded ? "Yes" : "No");
- printf_unfiltered ("%s\n", so->so_name);
- }
- }
- if (so_list_head == NULL)
- {
- printf_unfiltered ("No shared libraries loaded at this time.\n");
- }
-}
-
-/*
-
- GLOBAL FUNCTION
-
- solib_address -- check to see if an address is in a shared lib
-
- SYNOPSIS
-
- char *solib_address (CORE_ADDR address)
-
- DESCRIPTION
-
- Provides a hook for other gdb routines to discover whether or
- not a particular address is within the mapped address space of
- a shared library. Any address between the base mapping address
- and the first address beyond the end of the last mapping, is
- considered to be within the shared library address space, for
- our purposes.
-
- For example, this routine is called at one point to disable
- breakpoints which are in shared libraries that are not currently
- mapped in.
- */
-
-char *
-solib_address (CORE_ADDR address)
-{
- register struct so_list *so = 0; /* link map state variable */
-
- while ((so = find_solib (so)) != NULL)
- {
- if (so->so_name[0])
- {
- if ((address >= (CORE_ADDR) LM_ADDR (so)) &&
- (address < (CORE_ADDR) so->lmend))
- return (so->so_name);
- }
- }
- return (0);
-}
-
-/* Called by free_all_symtabs */
-
-void
-clear_solib (void)
-{
- struct so_list *next;
- char *bfd_filename;
-
- disable_breakpoints_in_shlibs (1);
-
- while (so_list_head)
- {
- if (so_list_head->sections)
- {
- free ((PTR) so_list_head->sections);
- }
- if (so_list_head->abfd)
- {
- bfd_filename = bfd_get_filename (so_list_head->abfd);
- if (!bfd_close (so_list_head->abfd))
- warning ("cannot close \"%s\": %s",
- bfd_filename, bfd_errmsg (bfd_get_error ()));
- }
- else
- /* This happens for the executable on SVR4. */
- bfd_filename = NULL;
-
- next = so_list_head->next;
- if (bfd_filename)
- free ((PTR) bfd_filename);
- free (so_list_head->so_name);
- free ((PTR) so_list_head);
- so_list_head = next;
- }
- debug_base = 0;
-}
-
-/*
-
- LOCAL FUNCTION
-
- disable_break -- remove the "mapping changed" breakpoint
-
- SYNOPSIS
-
- static int disable_break ()
-
- DESCRIPTION
-
- Removes the breakpoint that gets hit when the dynamic linker
- completes a mapping change.
-
- */
-
-static int
-disable_break (void)
-{
- int status = 1;
-
-
- /* Note that breakpoint address and original contents are in our address
- space, so we just need to write the original contents back. */
-
- if (memory_remove_breakpoint (breakpoint_addr, shadow_contents) != 0)
- {
- status = 0;
- }
-
- /* For the SVR4 version, we always know the breakpoint address. For the
- SunOS version we don't know it until the above code is executed.
- Grumble if we are stopped anywhere besides the breakpoint address. */
-
- if (stop_pc != breakpoint_addr)
- {
- warning ("stopped at unknown breakpoint while handling shared libraries");
- }
-
- return (status);
-}
-
-/*
-
- LOCAL FUNCTION
-
- enable_break -- arrange for dynamic linker to hit breakpoint
-
- SYNOPSIS
-
- int enable_break (void)
-
- DESCRIPTION
-
- This functions inserts a breakpoint at the entry point of the
- main executable, where all shared libraries are mapped in.
- */
-
-static int
-enable_break (void)
-{
- if (symfile_objfile != NULL
- && target_insert_breakpoint (symfile_objfile->ei.entry_point,
- shadow_contents) == 0)
- {
- breakpoint_addr = symfile_objfile->ei.entry_point;
- return 1;
- }
-
- return 0;
-}
-
-/*
-
- GLOBAL FUNCTION
-
- solib_create_inferior_hook -- shared library startup support
-
- SYNOPSIS
-
- void solib_create_inferior_hook()
-
- DESCRIPTION
-
- When gdb starts up the inferior, it nurses it along (through the
- shell) until it is ready to execute it's first instruction. At this
- point, this function gets called via expansion of the macro
- SOLIB_CREATE_INFERIOR_HOOK.
-
- For SunOS executables, this first instruction is typically the
- one at "_start", or a similar text label, regardless of whether
- the executable is statically or dynamically linked. The runtime
- startup code takes care of dynamically linking in any shared
- libraries, once gdb allows the inferior to continue.
-
- For SVR4 executables, this first instruction is either the first
- instruction in the dynamic linker (for dynamically linked
- executables) or the instruction at "start" for statically linked
- executables. For dynamically linked executables, the system
- first exec's /lib/libc.so.N, which contains the dynamic linker,
- and starts it running. The dynamic linker maps in any needed
- shared libraries, maps in the actual user executable, and then
- jumps to "start" in the user executable.
-
- For both SunOS shared libraries, and SVR4 shared libraries, we
- can arrange to cooperate with the dynamic linker to discover the
- names of shared libraries that are dynamically linked, and the
- base addresses to which they are linked.
-
- This function is responsible for discovering those names and
- addresses, and saving sufficient information about them to allow
- their symbols to be read at a later time.
-
- FIXME
-
- Between enable_break() and disable_break(), this code does not
- properly handle hitting breakpoints which the user might have
- set in the startup code or in the dynamic linker itself. Proper
- handling will probably have to wait until the implementation is
- changed to use the "breakpoint handler function" method.
-
- Also, what if child has exit()ed? Must exit loop somehow.
- */
-
-void
-solib_create_inferior_hook (void)
-{
- if (!enable_break ())
- {
- warning ("shared library handler failed to enable breakpoint");