- /* Relocate the section binding addresses as recorded in the shared
- object's file by the offset to get the address to which the
- object was actually mapped. */
- p -> addr += offset;
- p -> endaddr += offset;
- so -> lmend = (CORE_ADDR) max (p -> endaddr, so -> lmend);
- if (STREQ (p -> the_bfd_section -> name, ".text"))
- {
- so -> textsection = p;
- }
- }
-
- /* Free the file names, close the file now. */
- do_cleanups (old_chain);
-}
-
-/*
-
-LOCAL FUNCTION
-
- locate_base -- locate the base address of dynamic linker structs
-
-SYNOPSIS
-
- CORE_ADDR locate_base (void)
-
-DESCRIPTION
-
- For both the SunOS and SVR4 shared library implementations, if the
- inferior executable has been linked dynamically, there is a single
- address somewhere in the inferior's data space which is the key to
- locating all of the dynamic linker's runtime structures. This
- address is the value of the symbol defined by the macro DEBUG_BASE.
- The job of this function is to find and return that address, or to
- return 0 if there is no such address (the executable is statically
- linked for example).
-
- For SunOS, the job is almost trivial, since the dynamic linker and
- all of it's structures are statically linked to the executable at
- link time. Thus the symbol for the address we are looking for has
- already been added to the minimal symbol table for the executable's
- objfile at the time the symbol file's symbols were read, and all we
- have to do is look it up there. Note that we explicitly do NOT want
- to find the copies in the shared library.
-
- The SVR4 version is much more complicated because the dynamic linker
- and it's structures are located in the shared C library, which gets
- run as the executable's "interpreter" by the kernel. We have to go
- to a lot more work to discover the address of DEBUG_BASE. Because
- of this complexity, we cache the value we find and return that value
- on subsequent invocations. Note there is no copy in the executable
- symbol tables.
-
- Irix 5 is basically like SunOS.
-
- Note that we can assume nothing about the process state at the time
- we need to find this address. We may be stopped on the first instruc-
- tion of the interpreter (C shared library), the first instruction of
- the executable itself, or somewhere else entirely (if we attached
- to the process for example).
-
- */
-
-static CORE_ADDR
-locate_base ()
-{
- struct minimal_symbol *msymbol;
- CORE_ADDR address = 0;
-
- msymbol = lookup_minimal_symbol (DEBUG_BASE, NULL, symfile_objfile);
- if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
- {
- address = SYMBOL_VALUE_ADDRESS (msymbol);
- }
- return (address);
-}
-
-/*
-
-LOCAL FUNCTION
-
- first_link_map_member -- locate first member in dynamic linker's map
-
-SYNOPSIS
-
- static struct link_map *first_link_map_member (void)
-
-DESCRIPTION
-
- Read in a copy of the first member in the inferior's dynamic
- link map from the inferior's dynamic linker structures, and return
- a pointer to the copy in our address space.
-*/
-
-static struct obj_list *
-first_link_map_member ()
-{
- struct obj_list *lm;
- struct obj_list s;
-
- read_memory (debug_base, (char *) &lm, sizeof (struct obj_list *));
-
- if (lm == NULL)
- return NULL;
-
- /* The first entry in the list is the object file we are debugging,
- so skip it. */
- read_memory ((CORE_ADDR) lm, (char *) &s, sizeof (struct obj_list));
-
- return s.next;
-}
-
-/*
-
-LOCAL FUNCTION
-
- find_solib -- step through list of shared objects
-
-SYNOPSIS
-
- struct so_list *find_solib (struct so_list *so_list_ptr)
-
-DESCRIPTION
-
- This module contains the routine which finds the names of any
- loaded "images" in the current process. The argument in must be
- NULL on the first call, and then the returned value must be passed
- in on subsequent calls. This provides the capability to "step" down
- the list of loaded objects. On the last object, a NULL value is
- returned.
- */
-
-static struct so_list *
-find_solib (so_list_ptr)
- struct so_list *so_list_ptr; /* Last lm or NULL for first one */
-{
- struct so_list *so_list_next = NULL;
- struct obj_list *lm = NULL;
- struct so_list *new;
-
- if (so_list_ptr == NULL)
- {
- /* We are setting up for a new scan through the loaded images. */
- if ((so_list_next = so_list_head) == NULL)
- {
- /* We have not already read in the dynamic linking structures
- from the inferior, lookup the address of the base structure. */
- debug_base = locate_base ();
- if (debug_base != 0)
- {
- /* Read the base structure in and find the address of 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. */
- if ((lm = so_list_ptr->ll.next) == NULL)
- {
- /* We have hit the end of the list, so check to see if any were
- added, but be quiet if we can't read from the target any more. */
- int status = target_read_memory ((CORE_ADDR) so_list_ptr -> lladdr,
- (char *) &(so_list_ptr -> ll),
- sizeof (struct obj_list));
- if (status == 0)
- {
- lm = so_list_ptr->ll.next;
- }
- else
- {
- lm = NULL;
- }
- }
- so_list_next = so_list_ptr -> next;
- }
- if ((so_list_next == NULL) && (lm != NULL))
- {
- int errcode;
- char *buffer;
-
- /* Get next link map structure from inferior image and build a local
- abbreviated load_map structure */
- new = (struct so_list *) xmalloc (sizeof (struct so_list));
- memset ((char *) new, 0, sizeof (struct so_list));
- new -> lladdr = lm;
- /* 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;
- read_memory ((CORE_ADDR) lm, (char *) &(new -> ll),
- sizeof (struct obj_list));
- read_memory ((CORE_ADDR) new->ll.data, (char *) &(new -> lm),
- sizeof (struct obj));
- target_read_string ((CORE_ADDR)new->lm.o_path, &buffer,
- INT_MAX, &errcode);
- if (errcode != 0)
- memory_error (errcode, (CORE_ADDR)new->lm.o_path);
- new->lm.o_path = buffer;
- solib_map_sections (new);
- }
- return (so_list_next);
-}
-
-/* A small stub to get us past the arg-passing pinhole of catch_errors. */
-
-static int
-symbol_add_stub (arg)
- char *arg;
-{
- register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */
-
- so -> objfile = symbol_file_add (so -> lm.o_path, so -> from_tty,
- (unsigned int) so -> textsection -> addr,
- 0, 0, 0);
- 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
-
-*/