and LD_LIBRARY_PATH. */
static char *solib_search_path = NULL;
+/*
+
+ GLOBAL FUNCTION
+
+ solib_open -- Find a shared library file and open it.
+
+ SYNOPSIS
+
+ int solib_open (char *in_patname, char **found_pathname);
+
+ DESCRIPTION
+
+ Global variable SOLIB_ABSOLUTE_PREFIX is used as a prefix directory
+ to search for shared libraries if they have an absolute path.
+
+ Global variable SOLIB_SEARCH_PATH is used as a prefix directory
+ (or set of directories, as in LD_LIBRARY_PATH) to search for all
+ shared libraries if not found in SOLIB_ABSOLUTE_PREFIX.
+
+ Search order:
+ * If path is absolute, look in SOLIB_ABSOLUTE_PREFIX.
+ * If path is absolute, look for it literally (unmodified).
+ * Look in SOLIB_SEARCH_PATH.
+ * Look in inferior's $PATH.
+ * Look in inferior's $LD_LIBRARY_PATH.
+
+ RETURNS
+
+ file handle for opened solib, or -1 for failure. */
+
+int
+solib_open (char *in_pathname, char **found_pathname)
+{
+ int found_file = -1;
+ char *temp_pathname = NULL;
+
+ if (ROOTED_P (in_pathname))
+ {
+ if (solib_absolute_prefix == NULL)
+ temp_pathname = in_pathname;
+ else
+ {
+ int prefix_len = strlen (solib_absolute_prefix);
+
+ /* Remove trailing slashes from absolute prefix. */
+ while (prefix_len > 0 && SLASH_P (solib_absolute_prefix[prefix_len - 1]))
+ prefix_len--;
+
+ /* Cat the prefixed pathname together. */
+ temp_pathname = alloca (prefix_len + strlen (in_pathname) + 1);
+ strncpy (temp_pathname, solib_absolute_prefix, prefix_len);
+ temp_pathname[prefix_len] = '\0';
+ strcat (temp_pathname, in_pathname);
+
+ }
+ /* Now see if we can open it. */
+ found_file = open (temp_pathname, O_RDONLY, 0);
+ }
+
+ /* If not found, next search the solib_search_path (if any). */
+ if (found_file < 0 && solib_search_path != NULL)
+ found_file = openp (solib_search_path,
+ 1, in_pathname, O_RDONLY, 0, &temp_pathname);
+
+ /* If not found, next search the inferior's $PATH environment variable. */
+ if (found_file < 0 && solib_search_path != NULL)
+ found_file = openp (get_in_environ (inferior_environ, "PATH"),
+ 1, in_pathname, O_RDONLY, 0, &temp_pathname);
+
+ /* If not found, next search the inferior's $LD_LIBRARY_PATH
+ environment variable. */
+ if (found_file < 0 && solib_search_path != NULL)
+ found_file = openp (get_in_environ (inferior_environ, "LD_LIBRARY_PATH"),
+ 1, in_pathname, O_RDONLY, 0, &temp_pathname);
+
+ /* Done. If not found, tough luck. Return found_file and
+ (optionally) found_pathname. */
+ if (found_pathname != NULL && temp_pathname != NULL)
+ *found_pathname = strsave (temp_pathname);
+ return found_file;
+}
+
+
/*
LOCAL FUNCTION
filename = tilde_expand (so->so_name);
- if (solib_absolute_prefix && ROOTED_P (filename))
- /* Prefix shared libraries with absolute filenames with
- SOLIB_ABSOLUTE_PREFIX. */
- {
- char *pfxed_fn;
- int pfx_len;
-
- pfx_len = strlen (solib_absolute_prefix);
-
- /* Remove trailing slashes. */
- while (pfx_len > 0 && SLASH_P (solib_absolute_prefix[pfx_len - 1]))
- pfx_len--;
-
- pfxed_fn = xmalloc (pfx_len + strlen (filename) + 1);
- strcpy (pfxed_fn, solib_absolute_prefix);
- strcat (pfxed_fn, filename);
- free (filename);
-
- filename = pfxed_fn;
- }
-
- old_chain = make_cleanup (free, filename);
+ old_chain = make_cleanup (xfree, filename);
+ scratch_chan = solib_open (filename, &scratch_pathname);
- scratch_chan = -1;
-
- if (solib_search_path)
- scratch_chan = openp (solib_search_path,
- 1, filename, O_RDONLY, 0, &scratch_pathname);
- if (scratch_chan < 0)
- scratch_chan = openp (get_in_environ (inferior_environ, "PATH"),
- 1, filename, O_RDONLY, 0, &scratch_pathname);
- if (scratch_chan < 0)
- {
- scratch_chan = openp (get_in_environ
- (inferior_environ, "LD_LIBRARY_PATH"),
- 1, filename, O_RDONLY, 0, &scratch_pathname);
- }
if (scratch_chan < 0)
{
perror_with_name (filename);
}
- /* Leave scratch_pathname allocated. abfd->name will point to it. */
+ /* Leave scratch_pathname allocated. abfd->name will point to it. */
abfd = bfd_fdopenr (scratch_pathname, gnutarget, scratch_chan);
if (!abfd)
{
error ("Could not open `%s' as an executable file: %s",
scratch_pathname, bfd_errmsg (bfd_get_error ()));
}
+
/* Leave bfd open, core_xfer_memory and "info files" need it. */
so->abfd = abfd;
abfd->cacheable = true;
- /* copy full path name into so_name, so that later symbol_file_add can find
- it */
+ /* copy full path name into so_name, so that later symbol_file_add
+ can find it */
if (strlen (scratch_pathname) >= SO_NAME_MAX_PATH_SIZE)
error ("Full path name length of shared library exceeds SO_NAME_MAX_PATH_SIZE in so_list structure.");
strcpy (so->so_name, scratch_pathname);
/* Relocate the section binding addresses as recorded in the shared
object's file by the base address to which the object was actually
mapped. */
- p->addr += TARGET_SO_LM_ADDR (so);
- p->endaddr += TARGET_SO_LM_ADDR (so);
- so->lmend = max (p->endaddr, so->lmend);
+ TARGET_SO_RELOCATE_SECTION_ADDRESSES (so, p);
if (STREQ (p->the_bfd_section->name, ".text"))
{
so->textsection = p;
char *bfd_filename = 0;
if (so->sections)
- free (so->sections);
+ xfree (so->sections);
if (so->abfd)
{
}
if (bfd_filename)
- free (bfd_filename);
+ xfree (bfd_filename);
TARGET_SO_FREE_SO (so);
- free (so);
+ xfree (so);
}
{
register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */
struct section_addr_info *sap;
- CORE_ADDR lowest_addr = 0;
- int lowest_index;
- asection *lowest_sect = NULL;
/* Have we already loaded this shared object? */
ALL_OBJFILES (so->objfile)
return 1;
}
- /* Find the shared object's text segment. */
- if (so->textsection)
- {
- lowest_addr = so->textsection->addr;
- lowest_sect = bfd_get_section_by_name (so->abfd, ".text");
- lowest_index = lowest_sect->index;
- }
- else if (so->abfd != NULL)
- {
- /* If we didn't find a mapped non zero sized .text section, set
- up lowest_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)
- {
- lowest_addr = bfd_section_vma (so->abfd, lowest_sect)
- + TARGET_SO_LM_ADDR (so);
- lowest_index = lowest_sect->index;
- }
- }
-
sap = build_section_addr_info_from_section_table (so->sections,
so->sections_end);
- sap->other[lowest_index].addr = lowest_addr;
-
so->objfile = symbol_file_add (so->so_name, so->from_tty,
sap, 0, OBJF_SHARED);
free_section_addr_info (sap);
addr_width = 16 + 4;
addr_fmt = "016l";
}
+ else
+ {
+ internal_error ("%s:%d: bfd_get_arch_size() returned unknown size %d",
+ __FILE__, __LINE__, arch_size);
+ }
update_solib_list (from_tty, 0);
}
printf_unfiltered ("%-*s", addr_width,
- local_hex_string_custom (
- (unsigned long) TARGET_SO_LM_ADDR (so),
- addr_fmt));
+ so->textsection != NULL
+ ? local_hex_string_custom (
+ (unsigned long) so->textsection->addr,
+ addr_fmt)
+ : "");
printf_unfiltered ("%-*s", addr_width,
- local_hex_string_custom ((unsigned long) so->lmend,
- addr_fmt));
+ so->textsection != NULL
+ ? local_hex_string_custom (
+ (unsigned long) so->textsection->endaddr,
+ addr_fmt)
+ : "");
printf_unfiltered ("%-12s", so->symbols_loaded ? "Yes" : "No");
printf_unfiltered ("%s\n", so->so_name);
}
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.
+ a shared library.
For example, this routine is called at one point to disable
breakpoints which are in shared libraries that are not currently
for (so = so_list_head; so; so = so->next)
{
- if (TARGET_SO_LM_ADDR (so) <= address && address < so->lmend)
- return (so->so_name);
+ struct section_table *p;
+
+ for (p = so->sections; p < so->sections_end; p++)
+ {
+ if (p->addr <= address && address < p->endaddr)
+ return (so->so_name);
+ }
}
return (0);