linux-nat.c: fix a few lin_lwp_attach_lwp issues
[deliverable/binutils-gdb.git] / gdb / solib-aix.c
index 8c17a6f1b889b6f4c2505aecc7ae5a43aeb0564b..99258f6065ab1e165eb4df4708fa28239eddb26b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2013 Free Software Foundation, Inc.
+/* Copyright (C) 2013-2015 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -115,7 +115,7 @@ get_solib_aix_inferior_data (struct inferior *inf)
   data = inferior_data (inf, solib_aix_inferior_data_handle);
   if (data == NULL)
     {
-      data = XZALLOC (struct solib_aix_inferior_data);
+      data = XCNEW (struct solib_aix_inferior_data);
       set_inferior_data (inf, solib_aix_inferior_data_handle, data);
     }
 
@@ -141,6 +141,13 @@ solib_aix_parse_libraries (const char *library)
   return NULL;
 }
 
+/* Dummy implementation if XML support is not compiled in.  */
+
+static void
+solib_aix_free_library_list (void *p)
+{
+}
+
 #else /* HAVE_LIBEXPAT */
 
 #include "xml-support.h"
@@ -154,7 +161,7 @@ library_list_start_library (struct gdb_xml_parser *parser,
                            VEC (gdb_xml_value_s) *attributes)
 {
   VEC (lm_info_p) **list = user_data;
-  struct lm_info *item = XZALLOC (struct lm_info);
+  struct lm_info *item = XCNEW (struct lm_info);
   struct gdb_xml_value *attr;
 
   attr = xml_find_attribute (attributes, "name");
@@ -179,7 +186,7 @@ library_list_start_library (struct gdb_xml_parser *parser,
   VEC_safe_push (lm_info_p, *list, item);
 }
 
-/* Handle the start of a <library-list> element.  */
+/* Handle the start of a <library-list-aix> element.  */
 
 static void
 library_list_start_list (struct gdb_xml_parser *parser,
@@ -213,7 +220,7 @@ solib_aix_free_library_list (void *p)
 }
 
 /* The allowed elements and attributes for an AIX library list
-   described in XML format.  The root element is a <library-list>.  */
+   described in XML format.  The root element is a <library-list-aix>.  */
 
 static const struct gdb_xml_attribute library_attributes[] =
 {
@@ -242,7 +249,7 @@ static const struct gdb_xml_attribute library_list_attributes[] =
 
 static const struct gdb_xml_element library_list_elements[] =
 {
-  { "library-list", library_list_attributes, library_list_children,
+  { "library-list-aix", library_list_attributes, library_list_children,
     GDB_XML_EF_NONE, library_list_start_list, NULL },
   { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
 };
@@ -296,11 +303,11 @@ solib_aix_get_library_list (struct inferior *inf, const char *warning_msg)
     return data->library_list;
 
   library_document = target_read_stralloc (&current_target,
-                                           TARGET_OBJECT_AIX_LIBRARIES,
+                                           TARGET_OBJECT_LIBRARIES_AIX,
                                            NULL);
   if (library_document == NULL && warning_msg != NULL)
     {
-      warning (_("%s (failed to read TARGET_OBJECT_AIX_LIBRARIES)"),
+      warning (_("%s (failed to read TARGET_OBJECT_LIBRARIES_AIX)"),
               warning_msg);
       return NULL;
     }
@@ -308,7 +315,7 @@ solib_aix_get_library_list (struct inferior *inf, const char *warning_msg)
 
   if (solib_aix_debug)
     fprintf_unfiltered (gdb_stdlog,
-                       "DEBUG: TARGET_OBJECT_AIX_LIBRARIES = \n%s\n",
+                       "DEBUG: TARGET_OBJECT_LIBRARIES_AIX = \n%s\n",
                        library_document);
 
   data->library_list = solib_aix_parse_libraries (library_document);
@@ -383,8 +390,8 @@ static void
 solib_aix_relocate_section_addresses (struct so_list *so,
                                      struct target_section *sec)
 {
-  bfd *abfd = sec->bfd;
   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;
 
@@ -404,23 +411,27 @@ solib_aix_relocate_section_addresses (struct so_list *so,
     }
   else if (strcmp (section_name, ".bss") == 0)
     {
-      sec->addr = bfd_section_vma (abfd, bfd_sect) + info->data_addr;
+      /* The information provided by the loader does not include
+        the address of the .bss section, but we know that it gets
+        relocated by the same offset as the .data section.  So,
+        compute the relocation offset for the .data section, and
+        apply it to the .bss section as well.  If the .data section
+        is not defined (which seems highly unlikely), do our best
+        by assuming no relocation.  */
+      struct bfd_section *data_sect
+       = bfd_get_section_by_name (abfd, ".data");
+      CORE_ADDR data_offset = 0;
+
+      if (data_sect != NULL)
+       data_offset = info->data_addr - bfd_section_vma (abfd, data_sect);
+
+      sec->addr = bfd_section_vma (abfd, bfd_sect) + data_offset;
       sec->addr += solib_aix_bss_data_overlap (abfd);
       sec->endaddr = sec->addr + bfd_section_size (abfd, bfd_sect);
     }
   else
     {
       /* All other sections should not be relocated.  */
-      /* FIXME: GDB complains that the .loader section sometimes
-        overlaps with other sections (Eg: the .data section).
-        As far as I can tell, the loader section had the LOAD flag
-        set, but not the RELOC.  So it should not be relocated.
-        There seems to be a problem there, and maybe it has to do
-        with setting sec->addr to 0 (when the vma is indeed 0).
-        But even if there wasn't, the problem then becomes the fact
-        that many shared objects inside shared libraries have
-        a .loader section whose vma is 0, thus also triggering
-        an overlap warning.  */
       sec->addr = bfd_section_vma (abfd, bfd_sect);
       sec->endaddr = sec->addr + bfd_section_size (abfd, bfd_sect);
     }
@@ -459,7 +470,7 @@ solib_aix_get_section_offsets (struct objfile *objfile,
   bfd *abfd = objfile->obfd;
   int i;
 
-  offsets = XCALLOC (objfile->num_sections, struct section_offsets);
+  offsets = XCNEWVEC (struct section_offsets, objfile->num_sections);
 
   /* .text */
 
@@ -564,7 +575,7 @@ solib_aix_current_sos (void)
      to the main executable, not a shared library.  */
   for (ix = 1; VEC_iterate (lm_info_p, library_list, ix, info); ix++)
     {
-      struct so_list *new_solib = XZALLOC (struct so_list);
+      struct so_list *new_solib = XCNEW (struct so_list);
       char *so_name;
 
       if (info->member_name == NULL)
@@ -636,7 +647,7 @@ solib_aix_bfd_open (char *pathname)
   int filename_len;
   char *member_name;
   bfd *archive_bfd, *object_bfd;
-  struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
+  struct cleanup *cleanup;
 
   if (pathname[path_len - 1] != ')')
     return solib_bfd_open (pathname);
@@ -654,7 +665,7 @@ solib_aix_bfd_open (char *pathname)
   filename_len = sep - pathname;
 
   filename = xstrprintf ("%.*s", filename_len, pathname);
-  make_cleanup (xfree, filename);
+  cleanup = make_cleanup (xfree, filename);
   member_name = xstrprintf ("%.*s", path_len - filename_len - 2, sep + 1);
   make_cleanup (xfree, member_name);
 
@@ -713,6 +724,13 @@ solib_aix_bfd_open (char *pathname)
       return NULL;
     }
 
+  /* Override the returned bfd's name with our synthetic name in order
+     to allow commands listing all shared libraries to display that
+     synthetic name.  Otherwise, we would only be displaying the name
+     of the archive member object.  */
+  xfree (bfd_get_filename (object_bfd));
+  object_bfd->filename = xstrdup (pathname);
+
   gdb_bfd_unref (archive_bfd);
   do_cleanups (cleanup);
   return object_bfd;
@@ -754,7 +772,7 @@ solib_aix_get_toc_value (CORE_ADDR pc)
   if (data_osect == NULL)
     error (_("unable to find TOC entry for pc %s "
             "(%s has no data section)"),
-          core_addr_to_string (pc), pc_osect->objfile->name);
+          core_addr_to_string (pc), objfile_name (pc_osect->objfile));
 
   result = (obj_section_addr (data_osect)
            + xcoff_get_toc_offset (pc_osect->objfile));
This page took 0.026836 seconds and 4 git commands to generate.