aboutsummaryrefslogtreecommitdiff
path: root/gdb/solib-svr4.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-04-28 17:16:13 -0400
committerSimon Marchi <simon.marchi@ericsson.com>2017-04-28 17:16:13 -0400
commitd0e449a1865c741c5e0c9d43a7d61a0621163aa7 (patch)
tree2a4b4eb8eb25727b56d26d2bd70aff6fe9bb8942 /gdb/solib-svr4.c
parent434a40239548115cf04a80410e4f570f35c361c1 (diff)
downloadgdb-d0e449a1865c741c5e0c9d43a7d61a0621163aa7.zip
gdb-d0e449a1865c741c5e0c9d43a7d61a0621163aa7.tar.gz
gdb-d0e449a1865c741c5e0c9d43a7d61a0621163aa7.tar.bz2
Make various lm_info implementations inherit from a base class
The lm_info structure is used to store target specific information about mapped libraries. It is currently defined as an opaque type in solist.h and a pointer to it is included in solist, the target-agnostic object representing a loaded shared library. Multiple targets define their own implementation of lm_info. In anticipation of using C++ stuff (e.g. vector) in the lm_info objects, we first need to avoid different definitions of classes with the same name (which violates the one definition rule). This patch does it by having a base class (lm_info_base) from which all the specific lm_info derive. Each implementation is renamed to something that makes sense (e.g. lm_info_aix for AIX). The next logical step would probably be to derive directly from so_list, it's not really obvious, so I'll keep that for another day. One special case is the Neutrino (nto) support. It uses SVR4-style libraries, but overrides some methods. To do that, it needed to have its own copy of SVR4's lm_info structure in nto-tdep.c, because it was just not possible to put it in solib-svr4.h and include that file. Over time, that copy got out of sync, which is still the case today. I can only assume that the lm_addr function in nto-tdep.c is broken right now. The first field of the old lm_info was a pointer (gdb_byte *), whereas in the new lm_info it's an address in the inferior (CORE_ADDR). Trying to use that field today probably results in a crash. With this refactor, it's now possible to put lm_info_svr4 in solib-svr4.h and just include it. I have adapted the code in nto-tdep.c to that it builds, but it's probably not correct. Since I don't have the knowledge nor setup to try this on Neutrino, somebody else would have to fix it. But I am confident that I am not making things worse than they already are. gdb/ChangeLog: * solist.h (struct lm_info): Remove. (struct lm_info_base): New class. (struct so_list) <lm_info>: Change type to lm_info_base *. * nto-tdep.c (struct lm_info): Remove. (lm_addr): Adjust. * solib-aix.c (struct lm_info): Rename to ... (struct lm_info_aix): ... this. Extend lm_info_base. (lm_info_p): Rename to ... (lm_info_aix_p): ... this, and adjust. (solib_aix_new_lm_info, solib_aix_xfree_lm_info, solib_aix_parse_libraries, library_list_start_library, solib_aix_free_library_list, solib_aix_parse_libraries, solib_aix_get_library_list, solib_aix_relocate_section_addresses, solib_aix_free_so, solib_aix_get_section_offsets, solib_aix_solib_create_inferior_hook, solib_aix_current_sos): Adjust. (struct solib_aix_inferior_data) <library_list>: Adjust. * solib-darwin.c (struct lm_info): Rename to ... (struct lm_info_darwin): ... this. Extend lm_info_base. (darwin_current_sos, darwin_relocate_section_addresses): Adjust. * solib-dsbt.c (struct lm_info): Rename to ... (struct lm_info_dsbt): ... this. Extend lm_info_base. (struct dsbt_info) <main_executable_lm_info): Adjust. (dsbt_current_sos, dsbt_relocate_main_executable, dsbt_free_so, dsbt_relocate_section_addresses): Adjust. * solib-frv.c (struct lm_info): Rename to ... (struct lm_info_frv): ... this. Extend lm_info_base. (main_executable_lm_info): Adjust. (frv_current_sos, frv_relocate_main_executable, frv_free_so, frv_relocate_section_addresses, frv_fdpic_find_global_pointer, find_canonical_descriptor_in_load_object, frv_fdpic_find_canonical_descriptor): Adjust. * solib-svr4.c (struct lm_info): Move to solib-svr4.h, renamed to lm_info_svr4. (lm_info_read, lm_addr_check, svr4_keep_data_in_core, svr4_clear_so, svr4_copy_library_list, library_list_start_library, svr4_default_sos, svr4_read_so_list, svr4_current_sos, svr4_fetch_objfile_link_map, solist_update_incremental): Adjust. * solib-svr4.h (struct lm_info_svr4): Move here from solib-svr4.c. * solib-target.c (struct lm_info): Rename to ... (struct lm_info_target): ... this. Extend lm_info_base. (lm_info_p): Rename to ... (lm_info_target_p): ... this. (solib_target_parse_libraries, library_list_start_segment, library_list_start_section, library_list_start_library, library_list_end_library, solib_target_free_library_list, solib_target_current_sos, solib_target_free_so, solib_target_relocate_section_addresses): Adjust. * windows-nat.c (struct lm_info): Rename to ... (struct lm_info_windows): ... this. Extend lm_info_base. (windows_make_so, handle_load_dll, handle_unload_dll, windows_xfer_shared_libraries): Adjust.
Diffstat (limited to 'gdb/solib-svr4.c')
-rw-r--r--gdb/solib-svr4.c111
1 files changed, 53 insertions, 58 deletions
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 4cb6127..6098d50 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -51,27 +51,6 @@ static int svr4_have_link_map_offsets (void);
static void svr4_relocate_main_executable (void);
static void svr4_free_library_list (void *p_list);
-/* Link map info to include in an allocated so_list entry. */
-
-struct lm_info
- {
- /* Amount by which addresses in the binary should be relocated to
- match the inferior. The direct inferior value is L_ADDR_INFERIOR.
- When prelinking is involved and the prelink base address changes,
- we may need a different offset - the recomputed offset is in L_ADDR.
- It is commonly the same value. It is cached as we want to warn about
- the difference and compute it only once. L_ADDR is valid
- iff L_ADDR_P. */
- CORE_ADDR l_addr, l_addr_inferior;
- unsigned int l_addr_p : 1;
-
- /* The target location of lm. */
- CORE_ADDR lm_addr;
-
- /* Values read in from inferior's fields of the same name. */
- CORE_ADDR l_ld, l_next, l_prev, l_name;
- };
-
/* On SVR4 systems, a list of symbols in the dynamic linker where
GDB can try to place a breakpoint to monitor shared library
events.
@@ -189,12 +168,12 @@ svr4_same (struct so_list *gdb, struct so_list *inferior)
return (svr4_same_1 (gdb->so_original_name, inferior->so_original_name));
}
-static struct lm_info *
+static lm_info_svr4 *
lm_info_read (CORE_ADDR lm_addr)
{
struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
gdb_byte *lm;
- struct lm_info *lm_info;
+ lm_info_svr4 *lm_info;
struct cleanup *back_to;
lm = (gdb_byte *) xmalloc (lmo->link_map_size);
@@ -210,7 +189,7 @@ lm_info_read (CORE_ADDR lm_addr)
{
struct type *ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
- lm_info = XCNEW (struct lm_info);
+ lm_info = XCNEW (lm_info_svr4);
lm_info->lm_addr = lm_addr;
lm_info->l_addr_inferior = extract_typed_address (&lm[lmo->l_addr_offset],
@@ -240,17 +219,19 @@ has_lm_dynamic_from_link_map (void)
static CORE_ADDR
lm_addr_check (const struct so_list *so, bfd *abfd)
{
- if (!so->lm_info->l_addr_p)
+ lm_info_svr4 *li = (lm_info_svr4 *) so->lm_info;
+
+ if (!li->l_addr_p)
{
struct bfd_section *dyninfo_sect;
CORE_ADDR l_addr, l_dynaddr, dynaddr;
- l_addr = so->lm_info->l_addr_inferior;
+ l_addr = li->l_addr_inferior;
if (! abfd || ! has_lm_dynamic_from_link_map ())
goto set_addr;
- l_dynaddr = so->lm_info->l_ld;
+ l_dynaddr = li->l_ld;
dyninfo_sect = bfd_get_section_by_name (abfd, ".dynamic");
if (dyninfo_sect == NULL)
@@ -333,11 +314,11 @@ lm_addr_check (const struct so_list *so, bfd *abfd)
}
set_addr:
- so->lm_info->l_addr = l_addr;
- so->lm_info->l_addr_p = 1;
+ li->l_addr = l_addr;
+ li->l_addr_p = 1;
}
- return so->lm_info->l_addr;
+ return li->l_addr;
}
/* Per pspace SVR4 specific data. */
@@ -994,9 +975,10 @@ svr4_keep_data_in_core (CORE_ADDR vaddr, unsigned long size)
newobj = XCNEW (struct so_list);
old_chain = make_cleanup (xfree, newobj);
- newobj->lm_info = lm_info_read (ldsomap);
+ lm_info_svr4 *li = lm_info_read (ldsomap);
+ newobj->lm_info = li;
make_cleanup (xfree, newobj->lm_info);
- name_lm = newobj->lm_info ? newobj->lm_info->l_name : 0;
+ name_lm = li != NULL ? li->l_name : 0;
do_cleanups (old_chain);
return (name_lm >= vaddr && name_lm < vaddr + size);
@@ -1106,8 +1088,10 @@ svr4_free_so (struct so_list *so)
static void
svr4_clear_so (struct so_list *so)
{
- if (so->lm_info != NULL)
- so->lm_info->l_addr_p = 0;
+ lm_info_svr4 *li = (lm_info_svr4 *) so->lm_info;
+
+ if (li != NULL)
+ li->l_addr_p = 0;
}
/* Free so_list built so far (called via cleanup). */
@@ -1141,8 +1125,8 @@ svr4_copy_library_list (struct so_list *src)
newobj = XNEW (struct so_list);
memcpy (newobj, src, sizeof (struct so_list));
- newobj->lm_info = XNEW (struct lm_info);
- memcpy (newobj->lm_info, src->lm_info, sizeof (struct lm_info));
+ newobj->lm_info = XNEW (lm_info_svr4);
+ memcpy (newobj->lm_info, src->lm_info, sizeof (lm_info_svr4));
newobj->next = NULL;
*link = newobj;
@@ -1178,10 +1162,11 @@ library_list_start_library (struct gdb_xml_parser *parser,
struct so_list *new_elem;
new_elem = XCNEW (struct so_list);
- new_elem->lm_info = XCNEW (struct lm_info);
- new_elem->lm_info->lm_addr = *lmp;
- new_elem->lm_info->l_addr_inferior = *l_addrp;
- new_elem->lm_info->l_ld = *l_ldp;
+ lm_info_svr4 *li = XCNEW (lm_info_svr4);
+ new_elem->lm_info = li;
+ li->lm_addr = *lmp;
+ li->l_addr_inferior = *l_addrp;
+ li->l_ld = *l_ldp;
strncpy (new_elem->so_name, name, sizeof (new_elem->so_name) - 1);
new_elem->so_name[sizeof (new_elem->so_name) - 1] = 0;
@@ -1332,12 +1317,12 @@ svr4_default_sos (void)
return NULL;
newobj = XCNEW (struct so_list);
-
- newobj->lm_info = XCNEW (struct lm_info);
+ lm_info_svr4 *li = XCNEW (lm_info_svr4);
+ newobj->lm_info = li;
/* Nothing will ever check the other fields if we set l_addr_p. */
- newobj->lm_info->l_addr = info->debug_loader_offset;
- newobj->lm_info->l_addr_p = 1;
+ li->l_addr = info->debug_loader_offset;
+ li->l_addr_p = 1;
strncpy (newobj->so_name, info->debug_loader_name, SO_NAME_MAX_PATH_SIZE - 1);
newobj->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
@@ -1371,20 +1356,21 @@ svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm,
newobj = XCNEW (struct so_list);
old_chain = make_cleanup_free_so (newobj);
- newobj->lm_info = lm_info_read (lm);
- if (newobj->lm_info == NULL)
+ lm_info_svr4 *li = lm_info_read (lm);
+ newobj->lm_info = li;
+ if (li == NULL)
{
do_cleanups (old_chain);
return 0;
}
- next_lm = newobj->lm_info->l_next;
+ next_lm = li->l_next;
- if (newobj->lm_info->l_prev != prev_lm)
+ if (li->l_prev != prev_lm)
{
warning (_("Corrupted shared library list: %s != %s"),
paddress (target_gdbarch (), prev_lm),
- paddress (target_gdbarch (), newobj->lm_info->l_prev));
+ paddress (target_gdbarch (), li->l_prev));
do_cleanups (old_chain);
return 0;
}
@@ -1394,26 +1380,26 @@ svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm,
SVR4, it has no name. For others (Solaris 2.3 for example), it
does have a name, so we can no longer use a missing name to
decide when to ignore it. */
- if (ignore_first && newobj->lm_info->l_prev == 0)
+ if (ignore_first && li->l_prev == 0)
{
struct svr4_info *info = get_svr4_info ();
- first_l_name = newobj->lm_info->l_name;
- info->main_lm_addr = newobj->lm_info->lm_addr;
+ first_l_name = li->l_name;
+ info->main_lm_addr = li->lm_addr;
do_cleanups (old_chain);
continue;
}
/* Extract this shared object's name. */
- target_read_string (newobj->lm_info->l_name, &buffer,
- SO_NAME_MAX_PATH_SIZE - 1, &errcode);
+ target_read_string (li->l_name, &buffer, SO_NAME_MAX_PATH_SIZE - 1,
+ &errcode);
if (errcode != 0)
{
/* If this entry's l_name address matches that of the
inferior executable, then this is not a normal shared
object, but (most likely) a vDSO. In this case, silently
skip it; otherwise emit a warning. */
- if (first_l_name == 0 || newobj->lm_info->l_name != first_l_name)
+ if (first_l_name == 0 || li->l_name != first_l_name)
warning (_("Can't read pathname for load map: %s."),
safe_strerror (errcode));
do_cleanups (old_chain);
@@ -1594,7 +1580,10 @@ svr4_current_sos (void)
[...]
[ 9] .dynamic DYNAMIC ffffffffff700580 000580 0000f0
*/
- if (address_in_mem_range (so->lm_info->l_ld, &vsyscall_range))
+
+ lm_info_svr4 *li = (lm_info_svr4 *) so->lm_info;
+
+ if (address_in_mem_range (li->l_ld, &vsyscall_range))
{
*sop = so->next;
free_so (so);
@@ -1628,7 +1617,11 @@ svr4_fetch_objfile_link_map (struct objfile *objfile)
of shared libraries. */
for (so = master_so_list (); so; so = so->next)
if (so->objfile == objfile)
- return so->lm_info->lm_addr;
+ {
+ lm_info_svr4 *li = (lm_info_svr4 *) so->lm_info;
+
+ return li->lm_addr;
+ }
/* Not found! */
return 0;
@@ -1860,7 +1853,9 @@ solist_update_incremental (struct svr4_info *info, CORE_ADDR lm)
/* Walk to the end of the list. */
for (tail = info->solib_list; tail->next != NULL; tail = tail->next)
/* Nothing. */;
- prev_lm = tail->lm_info->lm_addr;
+
+ lm_info_svr4 *li = (lm_info_svr4 *) tail->lm_info;
+ prev_lm = li->lm_addr;
/* Read the new objects. */
if (info->using_xfer)