home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / bfd / hpux-core.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  8KB  |  271 lines

  1. /* BFD back-end for HP/UX core files.
  2.    Copyright 1993, 1994 Free Software Foundation, Inc.
  3.    Written by Stu Grossman, Cygnus Support.
  4.    Converted to back-end form by Ian Lance Taylor, Cygnus SUpport
  5.  
  6. This file is part of BFD, the Binary File Descriptor library.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  21.  
  22. /* This file can only be compiled on systems which use HP/UX style
  23.    core files.  */
  24.  
  25. #include "bfd.h"
  26. #include "sysdep.h"
  27. #include "libbfd.h"
  28.  
  29. #if defined (HOST_HPPAHPUX) || defined (HOST_HP300HPUX)
  30.  
  31. /* FIXME: sys/core.h doesn't exist for HPUX version 7.  HPUX version
  32.    5, 6, and 7 core files seem to be standard trad-core.c type core
  33.    files; can we just use trad-core.c in addition to this file?  */
  34.  
  35. #include <sys/core.h>
  36. #include <sys/utsname.h>
  37.  
  38. #endif /* HOST_HPPAHPUX */
  39.  
  40. #ifdef HOST_HPPABSD
  41.  
  42. /* Not a very swift place to put it, but that's where the BSD port
  43.    puts them.  */
  44. #include "/hpux/usr/include/sys/core.h"
  45.  
  46. #endif /* HOST_HPPABSD */
  47.  
  48. #include <stdio.h>
  49. #include <sys/types.h>
  50. #include <sys/param.h>
  51. #include <sys/dir.h>
  52. #include <signal.h>
  53. #include <machine/reg.h>
  54. #include <sys/user.h>        /* After a.out.h  */
  55. #include <sys/file.h>
  56. #include <errno.h>
  57.  
  58. /* These are stored in the bfd's tdata */
  59.  
  60. struct hpux_core_struct 
  61. {
  62.   int sig;
  63.   char cmd[MAXCOMLEN + 1];
  64. };
  65.  
  66. #define core_hdr(bfd) ((bfd)->tdata.hpux_core_data)
  67. #define core_signal(bfd) (core_hdr(bfd)->sig)
  68. #define core_command(bfd) (core_hdr(bfd)->cmd)
  69.  
  70. static asection *
  71. make_bfd_asection (abfd, name, flags, _raw_size, vma, alignment_power)
  72.      bfd *abfd;
  73.      CONST char *name;
  74.      flagword flags;
  75.      bfd_size_type _raw_size;
  76.      bfd_vma vma;
  77.      unsigned int alignment_power;
  78. {
  79.   asection *asect;
  80.  
  81.   asect = bfd_make_section_anyway (abfd, name);
  82.   if (!asect)
  83.     return NULL;
  84.  
  85.   asect->flags = flags;
  86.   asect->_raw_size = _raw_size;
  87.   asect->vma = vma;
  88.   asect->filepos = bfd_tell (abfd);
  89.   asect->alignment_power = alignment_power;
  90.  
  91.   return asect;
  92. }
  93.  
  94. static asymbol *
  95. hpux_core_make_empty_symbol (abfd)
  96.      bfd *abfd;
  97. {
  98.   asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
  99.   if (new)
  100.     new->the_bfd = abfd;
  101.   return new;
  102. }
  103.  
  104. static const bfd_target *
  105. hpux_core_core_file_p (abfd)
  106.      bfd *abfd;
  107. {
  108.   core_hdr (abfd) = (struct hpux_core_struct *)
  109.     bfd_zalloc (abfd, sizeof (struct hpux_core_struct));
  110.   if (!core_hdr (abfd))
  111.     return NULL;
  112.  
  113.   while (1)
  114.     {
  115.       int val;
  116.       struct corehead core_header;
  117.  
  118.       val = bfd_read ((void *) &core_header, 1, sizeof core_header, abfd);
  119.       if (val <= 0)
  120.     break;
  121.       switch (core_header.type)
  122.     {
  123.     case CORE_KERNEL:
  124.     case CORE_FORMAT:
  125.       bfd_seek (abfd, core_header.len, SEEK_CUR);    /* Just skip this */
  126.       break;
  127.     case CORE_EXEC:
  128.       {
  129.         struct proc_exec proc_exec;
  130.         if (bfd_read ((void *) &proc_exec, 1, core_header.len, abfd)
  131.         != core_header.len)
  132.           break;
  133.         strncpy (core_command (abfd), proc_exec.cmd, MAXCOMLEN + 1);
  134.       }
  135.       break;
  136.     case CORE_PROC:
  137.       {
  138.         struct proc_info proc_info;
  139.         if (!make_bfd_asection (abfd, ".reg",
  140.                     SEC_HAS_CONTENTS,
  141.                     core_header.len,
  142.                 (int) &proc_info - (int) & proc_info.hw_regs,
  143.                     2))
  144.           return NULL;
  145.  
  146.         if (bfd_read (&proc_info, 1, core_header.len, abfd)
  147.         != core_header.len)
  148.           break;
  149.         core_signal (abfd) = proc_info.sig;
  150.       }
  151.       break;
  152.  
  153.     case CORE_DATA:
  154.     case CORE_STACK:
  155.     case CORE_TEXT:
  156.     case CORE_MMF:
  157.     case CORE_SHM:
  158.       if (!make_bfd_asection (abfd, ".data",
  159.                   SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
  160.                   core_header.len, core_header.addr, 2))
  161.         return NULL;
  162.  
  163.       bfd_seek (abfd, core_header.len, SEEK_CUR);
  164.       break;
  165.  
  166.     default:
  167.       /* Falling into here is an error and should prevent this
  168.          target from matching.  That way systems which use hpux
  169.          cores along with other formats can still work.  */
  170.       return 0;
  171.     }
  172.     }
  173.  
  174.   /* OK, we believe you.  You're a core file (sure, sure).  */
  175.  
  176.   return abfd->xvec;
  177. }
  178.  
  179. static char *
  180. hpux_core_core_file_failing_command (abfd)
  181.      bfd *abfd;
  182. {
  183.   return core_command (abfd);
  184. }
  185.  
  186. /* ARGSUSED */
  187. static int
  188. hpux_core_core_file_failing_signal (abfd)
  189.      bfd *abfd;
  190. {
  191.   return core_signal (abfd);
  192. }
  193.  
  194. /* ARGSUSED */
  195. static boolean
  196. hpux_core_core_file_matches_executable_p (core_bfd, exec_bfd)
  197.      bfd *core_bfd, *exec_bfd;
  198. {
  199.   return true;            /* FIXME, We have no way of telling at this point */
  200. }
  201.  
  202. #define hpux_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
  203. #define hpux_core_get_symtab _bfd_nosymbols_get_symtab
  204. #define hpux_core_print_symbol _bfd_nosymbols_print_symbol
  205. #define hpux_core_get_symbol_info _bfd_nosymbols_get_symbol_info
  206. #define hpux_core_bfd_is_local_label _bfd_nosymbols_bfd_is_local_label
  207. #define hpux_core_get_lineno _bfd_nosymbols_get_lineno
  208. #define hpux_core_find_nearest_line _bfd_nosymbols_find_nearest_line
  209. #define hpux_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
  210. #define hpux_core_read_minisymbols _bfd_nosymbols_read_minisymbols
  211. #define hpux_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
  212.  
  213. /* If somebody calls any byte-swapping routines, shoot them.  */
  214. void
  215. swap_abort()
  216. {
  217.   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
  218. }
  219. #define    NO_GET    ((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
  220. #define    NO_PUT    ((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
  221. #define    NO_SIGNED_GET \
  222.   ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
  223.  
  224. const bfd_target hpux_core_vec =
  225.   {
  226.     "hpux-core",
  227.     bfd_target_unknown_flavour,
  228.     BFD_ENDIAN_BIG,        /* target byte order */
  229.     BFD_ENDIAN_BIG,        /* target headers byte order */
  230.     (HAS_RELOC | EXEC_P |    /* object flags */
  231.      HAS_LINENO | HAS_DEBUG |
  232.      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
  233.     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  234.     0,                                               /* symbol prefix */
  235.     ' ',                           /* ar_pad_char */
  236.     16,                               /* ar_max_namelen */
  237.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 64 bit data */
  238.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 32 bit data */
  239.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 16 bit data */
  240.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 64 bit hdrs */
  241.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 32 bit hdrs */
  242.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 16 bit hdrs */
  243.  
  244.     {                /* bfd_check_format */
  245.      _bfd_dummy_target,        /* unknown format */
  246.      _bfd_dummy_target,        /* object file */
  247.      _bfd_dummy_target,        /* archive */
  248.      hpux_core_core_file_p    /* a core file */
  249.     },
  250.     {                /* bfd_set_format */
  251.      bfd_false, bfd_false,
  252.      bfd_false, bfd_false
  253.     },
  254.     {                /* bfd_write_contents */
  255.      bfd_false, bfd_false,
  256.      bfd_false, bfd_false
  257.     },
  258.     
  259.        BFD_JUMP_TABLE_GENERIC (_bfd_generic),
  260.        BFD_JUMP_TABLE_COPY (_bfd_generic),
  261.        BFD_JUMP_TABLE_CORE (hpux_core),
  262.        BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
  263.        BFD_JUMP_TABLE_SYMBOLS (hpux_core),
  264.        BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
  265.        BFD_JUMP_TABLE_WRITE (_bfd_generic),
  266.        BFD_JUMP_TABLE_LINK (_bfd_nolink),
  267.        BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  268.  
  269.     (PTR) 0            /* backend_data */
  270. };
  271.