Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Functions | Variables
hpux-core.c File Reference
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include <sys/param.h>
#include <signal.h>
#include <sys/user.h>
#include <sys/file.h>

Go to the source code of this file.


struct  hpux_core_struct


#define CORE_ANON_SHMEM   0x00000200 /* anonymous shared memory */
#define core_hdr(bfd)   ((bfd)->tdata.hpux_core_data)
#define core_signal(bfd)   (core_hdr(bfd)->sig)
#define core_command(bfd)   (core_hdr(bfd)->cmd)
#define core_kernel_thread_id(bfd)   (core_hdr(bfd)->lwpid)
#define core_user_thread_id(bfd)   (core_hdr(bfd)->user_tid)
#define hpux_core_core_file_matches_executable_p   generic_core_file_matches_executable_p
#define NO_GET   ((bfd_vma (*) (const void *)) swap_abort)
#define NO_PUT   ((void (*) (bfd_vma, void *)) swap_abort)
#define NO_GETS   ((bfd_signed_vma (*) (const void *)) swap_abort)
#define NO_GET64   ((bfd_uint64_t (*) (const void *)) swap_abort)
#define NO_PUT64   ((void (*) (bfd_uint64_t, void *)) swap_abort)
#define NO_GETS64   ((bfd_int64_t (*) (const void *)) swap_abort)


static asectionmake_bfd_asection (bfd *, const char *, flagword, bfd_size_type, bfd_vma, unsigned int)
static const bfd_targethpux_core_core_file_p (bfd *)
static char * hpux_core_core_file_failing_command (bfd *)
static int hpux_core_core_file_failing_signal (bfd *)
static void swap_abort (void)
static int thread_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj ATTRIBUTE_UNUSED)


const bfd_target hpux_core_vec

Class Documentation

struct hpux_core_struct

Definition at line 91 of file hpux-core.c.

Class Members
char cmd
int lwpid
int sig
unsigned long user_tid

Define Documentation

#define CORE_ANON_SHMEM   0x00000200 /* anonymous shared memory */

Definition at line 83 of file hpux-core.c.

#define core_command (   bfd)    (core_hdr(bfd)->cmd)

Definition at line 101 of file hpux-core.c.

#define core_hdr (   bfd)    ((bfd)->tdata.hpux_core_data)

Definition at line 99 of file hpux-core.c.

#define core_kernel_thread_id (   bfd)    (core_hdr(bfd)->lwpid)

Definition at line 102 of file hpux-core.c.

#define core_signal (   bfd)    (core_hdr(bfd)->sig)

Definition at line 100 of file hpux-core.c.

#define core_user_thread_id (   bfd)    (core_hdr(bfd)->user_tid)

Definition at line 103 of file hpux-core.c.

Definition at line 104 of file hpux-core.c.

#define NO_GET   ((bfd_vma (*) (const void *)) swap_abort)

Definition at line 371 of file hpux-core.c.

#define NO_GET64   ((bfd_uint64_t (*) (const void *)) swap_abort)

Definition at line 374 of file hpux-core.c.

#define NO_GETS   ((bfd_signed_vma (*) (const void *)) swap_abort)

Definition at line 373 of file hpux-core.c.

#define NO_GETS64   ((bfd_int64_t (*) (const void *)) swap_abort)

Definition at line 376 of file hpux-core.c.

#define NO_PUT   ((void (*) (bfd_vma, void *)) swap_abort)

Definition at line 372 of file hpux-core.c.

#define NO_PUT64   ((void (*) (bfd_uint64_t, void *)) swap_abort)

Definition at line 375 of file hpux-core.c.

Function Documentation

static char * hpux_core_core_file_failing_command ( bfd abfd) [static]

Definition at line 352 of file hpux-core.c.

  return core_command (abfd);
static int hpux_core_core_file_failing_signal ( bfd abfd) [static]

Definition at line 358 of file hpux-core.c.

  return core_signal (abfd);
static const bfd_target * hpux_core_core_file_p ( bfd abfd) [static]

Definition at line 160 of file hpux-core.c.

  int  good_sections = 0;
  int  unknown_sections = 0;

  core_hdr (abfd) = (struct hpux_core_struct *)
    bfd_zalloc (abfd, (bfd_size_type) sizeof (struct hpux_core_struct));
  if (!core_hdr (abfd))
    return NULL;

  while (1)
      int val;
      struct corehead core_header;

      val = bfd_bread ((void *) &core_header,
                    (bfd_size_type) sizeof core_header, abfd);
      if (val <= 0)
      switch (core_header.type)
       case CORE_KERNEL:
       case CORE_FORMAT:
         /* Just skip this.  */
         bfd_seek (abfd, (file_ptr) core_header.len, SEEK_CUR);
       case CORE_EXEC:
           struct proc_exec proc_exec;
           if (bfd_bread ((void *) &proc_exec, (bfd_size_type) core_header.len,
                       abfd) != core_header.len)
           strncpy (core_command (abfd), proc_exec.cmd, MAXCOMLEN + 1);
       case CORE_PROC:
           struct proc_info proc_info;
           char  secname[100];  /* Of arbitrary size, but plenty large. */

            /* We need to read this section, 'cause we need to determine
               whether the core-dumped app was threaded before we create
               any .reg sections. */
           if (bfd_bread (&proc_info, (bfd_size_type) core_header.len, abfd)
              != core_header.len)

              /* However, we also want to create those sections with the
                 file positioned at the start of the record, it seems. */
            if (bfd_seek (abfd, -((file_ptr) core_header.len), SEEK_CUR) != 0)

            core_kernel_thread_id (abfd) = proc_info.lwpid;
            core_user_thread_id (abfd) = proc_info.user_tid;
            core_kernel_thread_id (abfd) = 0;
            core_user_thread_id (abfd) = 0;
            /* If the program was unthreaded, then we'll just create a
               .reg section.

               If the program was threaded, then we'll create .reg/XXXXX
               section for each thread, where XXXXX is a printable
               representation of the kernel thread id.  We'll also
               create a .reg section for the thread that was running
               and signalled at the time of the core-dump (i.e., this
               is effectively an alias, needed to keep GDB happy.)

               Note that we use `.reg/XXXXX' as opposed to '.regXXXXX'
               because GDB expects that .reg2 will be the floating-
               point registers. */
            if (core_kernel_thread_id (abfd) == 0)
                if (!make_bfd_asection (abfd, ".reg",
                                   (bfd_vma) offsetof (struct proc_info,
                goto fail;
                /* There are threads.  Is this the one that caused the
                   core-dump?  We'll claim it was the running thread. */
                if (proc_info.sig != -1)
                  if (!make_bfd_asection (abfd, ".reg",
                                       (bfd_vma)offsetof (struct proc_info,
                    goto fail;
                /* We always make one of these sections, for every thread. */
                sprintf (secname, ".reg/%d", core_kernel_thread_id (abfd));
                if (!make_bfd_asection (abfd, secname,
                                   (bfd_vma) offsetof (struct proc_info,
                goto fail;
           core_signal (abfd) = proc_info.sig;
            if (bfd_seek (abfd, (file_ptr) core_header.len, SEEK_CUR) != 0)

       case CORE_DATA:
       case CORE_STACK:
       case CORE_TEXT:
       case CORE_MMF:
       case CORE_SHM:
       case CORE_ANON_SHMEM:
         if (!make_bfd_asection (abfd, ".data",
                              SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
                              (bfd_vma) core_header.addr, 2))
           goto fail;

         bfd_seek (abfd, (file_ptr) core_header.len, SEEK_CUR);

       case CORE_NONE:
          /* Let's not punt if we encounter a section of unknown
             type.  Rather, let's make a note of it.  If we later
             see that there were also "good" sections, then we'll
             declare that this a core file, but we'll also warn that
             it may be incompatible with this gdb.

          goto fail; /*unrecognized core file type */

  /* OK, we believe you.  You're a core file (sure, sure).  */

  /* On HP/UX, we sometimes encounter core files where none of the threads
     was found to be the running thread (ie the signal was set to -1 for
     all threads).  This happens when the program was aborted externally
     via a TT_CORE ttrace system call.  In that case, we just pick one
     thread at random to be the active thread.  */
  if (core_kernel_thread_id (abfd) != 0
      && bfd_get_section_by_name (abfd, ".reg") == NULL)
      asection *asect = bfd_sections_find_if (abfd, thread_section_p, NULL);
      asection *reg_sect;

      if (asect != NULL)
          reg_sect = make_bfd_asection (abfd, ".reg", asect->flags,
                                        asect->size, asect->vma,
          if (reg_sect == NULL)
            goto fail;

          reg_sect->filepos = asect->filepos;

  /* Were there sections of unknown type?  If so, yet there were
     at least some complete sections of known type, then, issue
     a warning.  Possibly the core file was generated on a version
     of HP-UX that is incompatible with that for which this gdb was
  if ((unknown_sections > 0) && (good_sections > 0))
      ("%s appears to be a core file,\nbut contains unknown sections.  It may have been created on an incompatible\nversion of HP-UX.  As a result, some information may be unavailable.\n",

  return abfd->xvec;

  bfd_release (abfd, core_hdr (abfd));
  core_hdr (abfd) = NULL;
  bfd_section_list_clear (abfd);
  return NULL;

Here is the call graph for this function:

static asection * make_bfd_asection ( bfd abfd,
const char *  name,
flagword  flags,
bfd_size_type  size,
bfd_vma  vma,
unsigned int  alignment_power 
) [static]

Definition at line 114 of file hpux-core.c.

  asection *asect;
  char *newname;

  newname = bfd_alloc (abfd, (bfd_size_type) strlen (name) + 1);
  if (!newname)
    return NULL;

  strcpy (newname, name);

  asect = bfd_make_section_anyway_with_flags (abfd, newname, flags);
  if (!asect)
    return NULL;

  asect->size = size;
  asect->vma = vma;
  asect->filepos = bfd_tell (abfd);
  asect->alignment_power = alignment_power;

  return asect;

Here is the call graph for this function:

Here is the caller graph for this function:

static void swap_abort ( void  ) [static]

Definition at line 366 of file hpux-core.c.

  abort(); /* This way doesn't require any declaration for ANSI to fuck up */
static int thread_section_p ( bfd *abfd  ATTRIBUTE_UNUSED,
asection sect,
) [static]

Definition at line 143 of file hpux-core.c.

  return CONST_STRNEQ (sect->name, ".reg/");

Here is the caller graph for this function:

Variable Documentation

Definition at line 378 of file hpux-core.c.