This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [commit/AIX] Fix error when loading core file


Joel Brobecker wrote:

> I think the problem started when we introduced post_create_inferior.
> This causes us to call the SOLIB_CREATE_INFERIOR_HOOK, which in our
> case is defined as a call to xcoff_relocate_symtab. I haven't really
> checked with older versions of GDB because rebuilding GDB on AIX is
> mighty slow, but it very much looks like this function was not called
> in the case of core files before. This function is assuming a live process,
> not a core file. So what I did was do an early return when debugging
> a core file.

Yes, if you look at the SOLIB_ADD definition:

#define SOLIB_ADD(a, b, c, d)   \
  if (PIDGET (inferior_ptid))   \
    /* Attach to process.  */  \
    xcoff_relocate_symtab (PIDGET (inferior_ptid)); \
  else          \
    /* Core file.  */ \
    xcoff_relocate_core (c);

it is clear that the _symtab version is intended to be called only
in the case of live process.

It looks like something changed to get SOLIB_CREATE_INFERIOR_HOOK
now invoked as well ...


> What this made me realize, however, is that we should really be
> converting the AIX port to using the target_so_ops. I'll try to do
> that soon. In the meantime, the attached patch should be good enough.

Yes, I noticed that as well.  I had already started to do that, but
got side-tracked by other stuff in the meantime.  One problem is that
the ldinfo ptrace call that is required to get at the list of loaded
shared libraries is really a native-only call.

I'd thought of defining a TARGET_OBJECT_LDINFO xfer_partial object
that reflects the contents of the ldinfo, and use this in the
implementation of a (platform-independent) solib-aix.c file.
The rs6000 native target and the core file support would need to
be extended to supply that object.

Once rs6000 uses a proper target_so_ops shared library handling, 
all the special stuff ("vmap", DEPRECECATED_IBM6000_TARGET,
xcoffsolib.c) should go away ...


I'll try to get back to doing this, but it'll be some time.  If
you want to work at it earlier, that would certainly be welcome.
Attached below is the current version of my new solib-aix.c file
-- note that this is work in progress that doesn't even compile
at this point, but if any of it is helpful, feel free to use it
as a base for your work.

Bye,
Ulrich


/* Handle AIX shared libraries for GDB, the GNU Debugger.

   Copyright (C) 2007 Free Software Foundation, Inc.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.  */

#include "defs.h"

#include "symtab.h"
#include "bfd.h"
#include "symfile.h"
#include "objfiles.h"
#include "gdbcore.h"
#include "target.h"
#include "inferior.h"

#include "gdb_assert.h"

#include "solist.h"
#include "solib.h"

#include "bfd-target.h"
#include "exec.h"


/* The LDINFO data structure has the following layout:

                     32-bit     64-bit
    ldinfo_next       0 4        0 4
    ldinfo_fd         4 4        8 4
    ldinfo_textorg    8 4       16 8
    ldinfo_textsize  12 4       24 8
    ldinfo_dataorg   16 4       32 8
    ldinfo_datasize  20 4       40 8
    ldinfo_filename  24 -       48 -

   The following helper macros allow to access that structure
   without referring to AIX header files.  */

#define ldinfo_next(ldinfo, wordsize) \
 ((unsigned int) extract_unsigned_integer ((ldinfo), 4))

#define ldinfo_fd(ldinfo, wordsize) \
 ((int) extract_signed_integer ((ldinfo) + (wordsize), 4))

#define ldinfo_textorg(ldinfo, wordsize) \
 ((CORE_ADDR) extract_unsigned_integer ((ldinfo) + 2 * (wordsize), (wordsize)))

#define ldinfo_textsize(ldinfo, wordsize) \
 ((CORE_ADDR) extract_unsigned_integer ((ldinfo) + 3 * (wordsize), (wordsize)))

#define ldinfo_dataorg(ldinfo, wordsize) \
 ((CORE_ADDR) extract_unsigned_integer ((ldinfo) + 4 * (wordsize), (wordsize)))

#define ldinfo_datasize(ldinfo, wordsize) \
 ((CORE_ADDR) extract_unsigned_integer ((ldinfo) + 5 * (wordsize), (wordsize)))

#define ldinfo_filename(ldinfo, wordsize) \
 ((ldinfo) + 6 * (wordsize))

#define ldinfo_membername(ldinfo, wordsize) \
 (ldinfo_filename ((ldinfo), (wordsize)) \
  + strlen (ldinfo_filename ((ldinfo), (wordsize))) + 1)


struct lm_info
  {
    CORE_ADDR textorg;
    CORE_ADDR textsize;
    CORE_ADDR dataorg;
    CORE_ADDR datasize;
  };


/* Build a list of `struct so_list' objects describing the shared
   objects currently loaded in the inferior.  */
static struct so_list *
aix_current_sos (void)
{
  int wordsize = TARGET_PTR_BIT / 8;

  struct so_list *head = NULL;
  struct so_list **link_ptr = &head;

  gdb_byte *buf, *ldinfo;
  LONGEST len;

  /* Retrieve the LDINFO list from the target.  */
  len = target_read_alloc (ops, TARGET_OBJECT_LDINFO, NULL, &buf);
  if (len <= 0)
    return;

  /* Walk the LDINFO list, skipping the first entry (which is always the
     main executable), and allocate a so_list element for each entry.  */
  for (ldinfo = buf + ldinfo_next (buf, wordsize);
       ldinfo_next (ldinfo, wordsize);
       ldinfo += ldinfo_next (ldinfo, wordsize))
    {
      gdb_byte *filename = ldinfo_filename (ldinfo, wordsize);
      gdb_byte *membername = ldinfo_membername (ldinfo, wordsize);

      struct so_list *new = XZALLOC (struct so_list);
      new->lm_info = XZALLOC (struct lm_info);

      new->lm_info->textorg = ldinfo_textorg (ldinfo, wordsize);
      new->lm_info->textsize = ldinfo_textsize (ldinfo, wordsize);
      new->lm_info->dataorg = ldinfo_dataorg (ldinfo, wordsize);
      new->lm_info->datasize = ldinfo_datasize (ldinfo, wordsize);

      if (*membername)
	xsnprintf (new->so_name, SO_NAME_MAX_PATH_SIZE,
		   "%s (%s)", filename, membername);
      else
	xsnprintf (new->so_name, SO_NAME_MAX_PATH_SIZE, "%s", filename);

      strcpy (new->so_original_name, new->so_name);

      *link_ptr = new;
      link_ptr = &new->next;
    }

  xfree (buf);
  return head;
}

/* Clean up so_list entry.  */
static void
aix_free_so (struct so_list *so)
{
  xfree (so->lm_info->lm);
  xfree (so->lm_info);
}


/* Relocate section addresses.  */
static void
aix_relocate_section_addresses (struct so_list *so,
				struct section_table *sec)
{
  if (strcmp (sec->the_bfd_section->name, ".text") == 0)
    {
      sec->addr += so->lm_info->textorg;
      sec->endaddr += so->lm_info->textorg;
    }
  if (strcmp (sec->the_bfd_section->name, ".data") == 0)
    {
      sec->addr += so->lm_info->dataorg;
      sec->endaddr += so->lm_info->dataorg;
    }
  if (strcmp (sec->the_bfd_section->name, ".bss") == 0)
    {
      sec->addr += so->lm_info->dataorg;
      sec->endaddr += so->lm_info->dataorg;
    }
}


/* If no open symbol file, attempt to locate and open the main symbol
   file.  On SVR4 systems, this is the first link map entry.  If its
   name is here, we can open it.  Useful when attaching to a process
   without first loading its symbol file.  */
static int
aix_open_symbol_file_object (void *from_ttyp)
{
  /* FIXME: We could implement this.  */
  return 0;
}


/* Return 1 if PC lies in the dynamic symbol resolution code of the
   SVR4 run time loader.  */
static int
aix_in_dynsym_resolve_code (CORE_ADDR pc)
{
  /* FIXME: This is probably wrong.  */
  return in_plt_section (pc, NULL);
}


/* Additional shared library symbol handling.  Nothing to do.  */
static void
aix_special_symbol_handling (void)
{
}


/* Shared library startup.  */
static void
aix_solib_create_inferior_hook (void)
{
  gdb_byte *buf;
  LONGEST len;

  /* Retrieve the LDINFO list from the target.  */
  len = target_read_alloc (ops, TARGET_OBJECT_LDINFO, NULL, &ldinfo);
  if (len <= 0)
    return;

  /* Relocate main executable.  */
  if (ldinfo_next (ldinfo, wordsize))
    {
      CORE_ADDR textorg = ldinfo_textorg (ldinfo, wordsize);
      CORE_ADDR dataorg = ldinfo_textorg (ldinfo, wordsize);

      struct cleanup *old_chain;
      struct section_offsets *new_offsets;
      int i;

      new_offsets = xcalloc (symfile_objfile->num_sections,
			     sizeof (struct section_offsets));
      old_chain = make_cleanup (xfree, new_offsets);

      for (i = 0; i < objfile->num_sections; ++i)
	new_offsets->offsets[i] = ANOFFSET (objfile->section_offsets, i);

      new_offsets->offsets[SECT_OFF_TEXT (objfile)] += textorg;
      new_offsets->offsets[SECT_OFF_DATA (objfile)] += dataorg;
      new_offsets->offsets[SECT_OFF_BSS (objfile)] += dataorg;

      objfile_relocate (symfile_objfile, new_offsets);
      do_cleanups (old_chain);
    }

  xfree (ldinfo);
}

 
/* Shared library cleanup.  */
static void
aix_clear_solib (void)
{
}


static struct target_so_ops aix_so_ops;

extern initialize_file_ftype _initialize_aix_solib; /* -Wmissing-prototypes */

void
_initialize_aix_solib (void)
{
  aix_so_ops.relocate_section_addresses = aix_relocate_section_addresses;
  aix_so_ops.free_so = aix_free_so;
  aix_so_ops.clear_solib = aix_clear_solib;
  aix_so_ops.solib_create_inferior_hook = aix_solib_create_inferior_hook;
  aix_so_ops.special_symbol_handling = aix_special_symbol_handling;
  aix_so_ops.current_sos = aix_current_sos;
  aix_so_ops.open_symbol_file_object = aix_open_symbol_file_object;
  aix_so_ops.in_dynsym_resolve_code = aix_in_dynsym_resolve_code;

  /* FIXME: Don't do this here.  *_gdbarch_init() should set so_ops. */
  current_target_so_ops = &aix_so_ops;
}


-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]