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