From d0e449a1865c741c5e0c9d43a7d61a0621163aa7 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 28 Apr 2017 17:16:13 -0400 Subject: 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) : 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) : 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) filename = xstrdup (info->filename); if (info->member_name != NULL) result->member_name = xstrdup (info->member_name); @@ -79,7 +79,7 @@ solib_aix_new_lm_info (struct lm_info *info) /* Free the memory allocated for the given lm_info. */ static void -solib_aix_xfree_lm_info (struct lm_info *info) +solib_aix_xfree_lm_info (lm_info_aix *info) { xfree (info->filename); xfree (info->member_name); @@ -98,7 +98,7 @@ struct solib_aix_inferior_data the same principles applied to shared libraries also apply to the main executable. So it's simpler to keep it as part of this list. */ - VEC (lm_info_p) *library_list; + VEC (lm_info_aix_p) *library_list; }; /* Key to our per-inferior data. */ @@ -127,7 +127,7 @@ get_solib_aix_inferior_data (struct inferior *inf) /* Dummy implementation if XML support is not compiled in. */ -static VEC (lm_info_p) * +static VEC (lm_info_aix_p) * solib_aix_parse_libraries (const char *library) { static int have_warned; @@ -161,8 +161,8 @@ library_list_start_library (struct gdb_xml_parser *parser, void *user_data, VEC (gdb_xml_value_s) *attributes) { - VEC (lm_info_p) **list = (VEC (lm_info_p) **) user_data; - struct lm_info *item = XCNEW (struct lm_info); + VEC (lm_info_aix_p) **list = (VEC (lm_info_aix_p) **) user_data; + lm_info_aix *item = XCNEW (lm_info_aix); struct gdb_xml_value *attr; attr = xml_find_attribute (attributes, "name"); @@ -184,7 +184,7 @@ library_list_start_library (struct gdb_xml_parser *parser, attr = xml_find_attribute (attributes, "data_size"); item->data_size = * (ULONGEST *) attr->value; - VEC_safe_push (lm_info_p, *list, item); + VEC_safe_push (lm_info_aix_p, *list, item); } /* Handle the start of a element. */ @@ -207,16 +207,16 @@ library_list_start_list (struct gdb_xml_parser *parser, static void solib_aix_free_library_list (void *p) { - VEC (lm_info_p) **result = (VEC (lm_info_p) **) p; - struct lm_info *info; + VEC (lm_info_aix_p) **result = (VEC (lm_info_aix_p) **) p; + lm_info_aix *info; int ix; if (solib_aix_debug) fprintf_unfiltered (gdb_stdlog, "DEBUG: solib_aix_free_library_list\n"); - for (ix = 0; VEC_iterate (lm_info_p, *result, ix, info); ix++) + for (ix = 0; VEC_iterate (lm_info_aix_p, *result, ix, info); ix++) solib_aix_xfree_lm_info (info); - VEC_free (lm_info_p, *result); + VEC_free (lm_info_aix_p, *result); *result = NULL; } @@ -256,14 +256,14 @@ static const struct gdb_xml_element library_list_elements[] = }; /* Parse LIBRARY, a string containing the loader info in XML format, - and return an lm_info_p vector. + and return an lm_info_aix_p vector. Return NULL if the parsing failed. */ -static VEC (lm_info_p) * +static VEC (lm_info_aix_p) * solib_aix_parse_libraries (const char *library) { - VEC (lm_info_p) *result = NULL; + VEC (lm_info_aix_p) *result = NULL; struct cleanup *back_to = make_cleanup (solib_aix_free_library_list, &result); @@ -291,7 +291,7 @@ solib_aix_parse_libraries (const char *library) is not NULL, then print a warning including WARNING_MSG and a description of the error. */ -static VEC (lm_info_p) * +static VEC (lm_info_aix_p) * solib_aix_get_library_list (struct inferior *inf, const char *warning_msg) { struct solib_aix_inferior_data *data; @@ -394,7 +394,7 @@ solib_aix_relocate_section_addresses (struct so_list *so, struct bfd_section *bfd_sect = sec->the_bfd_section; bfd *abfd = bfd_sect->owner; const char *section_name = bfd_section_name (abfd, bfd_sect); - struct lm_info *info = so->lm_info; + lm_info_aix *info = (lm_info_aix *) so->lm_info; if (strcmp (section_name, ".text") == 0) { @@ -446,7 +446,7 @@ solib_aix_free_so (struct so_list *so) if (solib_aix_debug) fprintf_unfiltered (gdb_stdlog, "DEBUG: solib_aix_free_so (%s)\n", so->so_name); - solib_aix_xfree_lm_info (so->lm_info); + solib_aix_xfree_lm_info ((lm_info_aix *) so->lm_info); } /* Implement the "clear_solib" target_so_ops method. */ @@ -465,7 +465,7 @@ solib_aix_clear_solib (void) static struct section_offsets * solib_aix_get_section_offsets (struct objfile *objfile, - struct lm_info *info) + lm_info_aix *info) { struct section_offsets *offsets; bfd *abfd = objfile->obfd; @@ -519,8 +519,8 @@ static void solib_aix_solib_create_inferior_hook (int from_tty) { const char *warning_msg = "unable to relocate main executable"; - VEC (lm_info_p) *library_list; - struct lm_info *exec_info; + VEC (lm_info_aix_p) *library_list; + lm_info_aix *exec_info; /* We need to relocate the main executable... */ @@ -529,13 +529,13 @@ solib_aix_solib_create_inferior_hook (int from_tty) if (library_list == NULL) return; /* Warning already printed. */ - if (VEC_length (lm_info_p, library_list) < 1) + if (VEC_length (lm_info_aix_p, library_list) < 1) { warning (_("unable to relocate main executable (no info from loader)")); return; } - exec_info = VEC_index (lm_info_p, library_list, 0); + exec_info = VEC_index (lm_info_aix_p, library_list, 0); if (symfile_objfile != NULL) { @@ -554,8 +554,8 @@ static struct so_list * solib_aix_current_sos (void) { struct so_list *start = NULL, *last = NULL; - VEC (lm_info_p) *library_list; - struct lm_info *info; + VEC (lm_info_aix_p) *library_list; + lm_info_aix *info; int ix; library_list = solib_aix_get_library_list (current_inferior (), NULL); @@ -565,7 +565,7 @@ solib_aix_current_sos (void) /* Build a struct so_list for each entry on the list. We skip the first entry, since this is the entry corresponding to the main executable, not a shared library. */ - for (ix = 1; VEC_iterate (lm_info_p, library_list, ix, info); ix++) + for (ix = 1; VEC_iterate (lm_info_aix_p, library_list, ix, info); ix++) { struct so_list *new_solib = XCNEW (struct so_list); char *so_name; -- cgit v1.1