示例#1
0
/* Create inferior hook.  */
static void
spu_solib_create_inferior_hook (int from_tty)
{
  /* Handle SPE stand-alone executables.  */
  if (spu_standalone_p ())
    {
      /* After an SPE stand-alone executable was loaded, we'll receive
	 an additional trap due to the binfmt_misc handler.  Make sure
	 to skip that trap.  */
      spu_skip_standalone_loader ();

      /* If the user established breakpoints before starting the inferior, GDB
	 would attempt to insert those now.  This would fail because the SPU
	 context has not yet been created and the SPU executable has not yet
	 been loaded.  To prevent such failures, we disable all user-created
	 breakpoints now; they will be re-enabled in spu_current_sos once the
	 main SPU context has been detected.  */
      disable_breakpoints_before_startup ();

      /* A special case arises when re-starting an executable, because at
	 this point it still resides at the relocated address range that was
	 determined during its last execution.  We need to undo the relocation
	 so that that multi-architecture target recognizes the stand-alone
	 initialization special case.  */
      spu_relocate_main_executable (-1);
    }

  /* Call SVR4 hook -- this will re-insert the SVR4 solib breakpoints.  */
  svr4_so_ops.solib_create_inferior_hook (from_tty);

  /* If the inferior is statically linked against libspe, we need to install
     our own solib breakpoint right now.  Otherwise, it will be installed by
     the solib_loaded observer below as soon as libspe is loaded.  */
  spu_enable_break (NULL);
}
static void
spu_multiarch_solib_unloaded (struct so_list *so)
{
  if (!spu_standalone_p ())
    if (so->abfd && bfd_get_arch (so->abfd) == bfd_arch_spu)
      if (--spu_nr_solib == 0)
	spu_multiarch_deactivate ();
}
static void
spu_multiarch_inferior_created (struct target_ops *ops, int from_tty)
{
  if (spu_standalone_p ())
    spu_multiarch_activate ();
}
示例#4
0
/* Build a list of `struct so_list' objects describing the shared
   objects currently loaded in the inferior.  */
static struct so_list *
spu_current_sos (void)
{
  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
  struct so_list *head;
  struct so_list **link_ptr;

  gdb_byte buf[MAX_SPE_FD * 4];
  int i, size;

  /* First, retrieve the SVR4 shared library list.  */
  head = svr4_so_ops.current_sos ();

  /* Append our libraries to the end of the list.  */
  for (link_ptr = &head; *link_ptr; link_ptr = &(*link_ptr)->next)
    ;

  /* Determine list of SPU ids.  */
  size = target_read (&current_target, TARGET_OBJECT_SPU, NULL,
		      buf, 0, sizeof buf);

  /* Do not add stand-alone SPE executable context as shared library,
     but relocate main SPE executable objfile.  */
  if (spu_standalone_p ())
    {
      if (size == 4)
	{
	  int fd = extract_unsigned_integer (buf, 4, byte_order);

	  spu_relocate_main_executable (fd);

	  /* Re-enable breakpoints after main SPU context was established;
	     see also comments in spu_solib_create_inferior_hook.  */
	  enable_breakpoints_after_startup ();
	}

      return head;
    }

  /* Create an so_list entry for each SPU id.  */
  for (i = 0; i < size; i += 4)
    {
      int fd = extract_unsigned_integer (buf + i, 4, byte_order);
      struct so_list *newobj;

      unsigned long long addr;
      char annex[32], id[100];
      int len;

      /* Read object ID.  There's a race window where the inferior may have
	 already created the SPE context, but not installed the object-id
	 yet.  Skip such entries; we'll be back for them later.  */
      xsnprintf (annex, sizeof annex, "%d/object-id", fd);
      len = target_read (&current_target, TARGET_OBJECT_SPU, annex,
			 (gdb_byte *) id, 0, sizeof id);
      if (len <= 0 || len >= sizeof id)
	continue;
      id[len] = 0;
      if (sscanf (id, "0x%llx", &addr) != 1 || !addr)
	continue;

      /* Allocate so_list structure.  */
      newobj = XCNEW (struct so_list);

      /* Encode FD and object ID in path name.  Choose the name so as not
	 to conflict with any (normal) SVR4 library path name.  */
      xsnprintf (newobj->so_name, sizeof newobj->so_name, "@%s <%d>",
		 hex_string (addr), fd);
      strcpy (newobj->so_original_name, newobj->so_name);

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

  /* Append OpenCL sos.  */
  append_ocl_sos (link_ptr);

  return head;
}