1 /* BFD back-end for HP/UX core files.
2 Copyright 1993, 1994, 1996, 1998, 1999, 2001
3 Free Software Foundation, Inc.
4 Written by Stu Grossman, Cygnus Support.
5 Converted to back-end form by Ian Lance Taylor, Cygnus SUpport
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* This file can only be compiled on systems which use HP/UX style
30 #if defined (HOST_HPPAHPUX) || defined (HOST_HP300HPUX) || defined (HOST_HPPAMPEIX)
32 /* FIXME: sys/core.h doesn't exist for HPUX version 7. HPUX version
33 5, 6, and 7 core files seem to be standard trad-core.c type core
34 files; can we just use trad-core.c in addition to this file? */
37 #include <sys/utsname.h>
39 #endif /* HOST_HPPAHPUX */
43 /* Not a very swift place to put it, but that's where the BSD port
45 #include "/hpux/usr/include/sys/core.h"
47 #endif /* HOST_HPPABSD */
49 #include <sys/param.h>
53 # ifdef HAVE_SYS_NDIR_H
54 # include <sys/ndir.h>
56 # ifdef HAVE_SYS_DIR_H
64 #include <machine/reg.h>
65 #include <sys/user.h> /* After a.out.h */
68 /* Kludge: There's no explicit mechanism provided by sys/core.h to
69 conditionally know whether a proc_info has thread id fields.
70 However, CORE_ANON_SHMEM shows up first at 10.30, which is
71 happily also when meaningful thread id's show up in proc_info. */
72 #if defined(CORE_ANON_SHMEM)
73 #define PROC_INFO_HAS_THREAD_ID (1)
76 /* This type appears at HP-UX 10.30. Defining it if not defined
77 by sys/core.h allows us to build for older HP-UX's, and (since
78 it won't be encountered in core-dumps from older HP-UX's) is
80 #if !defined(CORE_ANON_SHMEM)
81 #define CORE_ANON_SHMEM 0x00000200 /* anonymous shared memory */
84 /* These are stored in the bfd's tdata */
86 /* .lwpid and .user_tid are only valid if PROC_INFO_HAS_THREAD_ID, else they
87 are set to 0. Also, until HP-UX implements MxN threads, .user_tid and
88 .lwpid are synonymous. */
89 struct hpux_core_struct
92 int lwpid
; /* Kernel thread ID. */
93 unsigned long user_tid
; /* User thread ID. */
94 char cmd
[MAXCOMLEN
+ 1];
97 #define core_hdr(bfd) ((bfd)->tdata.hpux_core_data)
98 #define core_signal(bfd) (core_hdr(bfd)->sig)
99 #define core_command(bfd) (core_hdr(bfd)->cmd)
100 #define core_kernel_thread_id(bfd) (core_hdr(bfd)->lwpid)
101 #define core_user_thread_id(bfd) (core_hdr(bfd)->user_tid)
103 static asection
*make_bfd_asection
104 PARAMS ((bfd
*, const char *, flagword
, bfd_size_type
, bfd_vma
,
106 static asymbol
*hpux_core_make_empty_symbol
PARAMS ((bfd
*));
107 static const bfd_target
*hpux_core_core_file_p
PARAMS ((bfd
*));
108 static char *hpux_core_core_file_failing_command
PARAMS ((bfd
*));
109 static int hpux_core_core_file_failing_signal
PARAMS ((bfd
*));
110 static boolean hpux_core_core_file_matches_executable_p
111 PARAMS ((bfd
*, bfd
*));
112 static void swap_abort
PARAMS ((void));
115 make_bfd_asection (abfd
, name
, flags
, _raw_size
, vma
, alignment_power
)
119 bfd_size_type _raw_size
;
121 unsigned int alignment_power
;
126 newname
= bfd_alloc (abfd
, (bfd_size_type
) strlen (name
) + 1);
130 strcpy (newname
, name
);
132 asect
= bfd_make_section_anyway (abfd
, newname
);
136 asect
->flags
= flags
;
137 asect
->_raw_size
= _raw_size
;
139 asect
->filepos
= bfd_tell (abfd
);
140 asect
->alignment_power
= alignment_power
;
146 hpux_core_make_empty_symbol (abfd
)
151 new = (asymbol
*) bfd_zalloc (abfd
, (bfd_size_type
) sizeof (asymbol
));
157 /* this function builds a bfd target if the file is a corefile.
158 It returns null or 0 if it finds out thaat it is not a core file.
159 The way it checks this is by looking for allowed 'type' field values.
160 These are declared in sys/core.h
161 There are some values which are 'reserved for future use'. In particular
162 CORE_NONE is actually defined as 0. This may be a catch-all for cases
163 in which the core file is generated by some non-hpux application.
164 (I am just guessing here!)
166 static const bfd_target
*
167 hpux_core_core_file_p (abfd
)
170 int good_sections
= 0;
171 int unknown_sections
= 0;
173 core_hdr (abfd
) = (struct hpux_core_struct
*)
174 bfd_zalloc (abfd
, (bfd_size_type
) sizeof (struct hpux_core_struct
));
175 if (!core_hdr (abfd
))
181 struct corehead core_header
;
183 val
= bfd_bread ((void *) &core_header
,
184 (bfd_size_type
) sizeof core_header
, abfd
);
187 switch (core_header
.type
)
191 /* Just skip this. */
192 bfd_seek (abfd
, (file_ptr
) core_header
.len
, SEEK_CUR
);
197 struct proc_exec proc_exec
;
198 if (bfd_bread ((void *) &proc_exec
, (bfd_size_type
) core_header
.len
,
199 abfd
) != core_header
.len
)
201 strncpy (core_command (abfd
), proc_exec
.cmd
, MAXCOMLEN
+ 1);
207 struct proc_info proc_info
;
208 char secname
[100]; /* Of arbitrary size, but plenty large. */
210 /* We need to read this section, 'cause we need to determine
211 whether the core-dumped app was threaded before we create
212 any .reg sections. */
213 if (bfd_bread (&proc_info
, (bfd_size_type
) core_header
.len
, abfd
)
217 /* However, we also want to create those sections with the
218 file positioned at the start of the record, it seems. */
219 if (bfd_seek (abfd
, (file_ptr
) -core_header
.len
, SEEK_CUR
) != 0)
222 #if defined(PROC_INFO_HAS_THREAD_ID)
223 core_kernel_thread_id (abfd
) = proc_info
.lwpid
;
224 core_user_thread_id (abfd
) = proc_info
.user_tid
;
226 core_kernel_thread_id (abfd
) = 0;
227 core_user_thread_id (abfd
) = 0;
229 /* If the program was unthreaded, then we'll just create a
232 If the program was threaded, then we'll create .reg/XXXXX
233 section for each thread, where XXXXX is a printable
234 representation of the kernel thread id. We'll also
235 create a .reg section for the thread that was running
236 and signalled at the time of the core-dump (i.e., this
237 is effectively an alias, needed to keep GDB happy.)
239 Note that we use `.reg/XXXXX' as opposed to '.regXXXXX'
240 because GDB expects that .reg2 will be the floating-
242 if (core_kernel_thread_id (abfd
) == 0)
244 if (!make_bfd_asection (abfd
, ".reg",
247 (int) &proc_info
- (int) & proc_info
.hw_regs
,
253 /* There are threads. Is this the one that caused the
254 core-dump? We'll claim it was the running thread. */
255 if (proc_info
.sig
!= -1)
257 if (!make_bfd_asection (abfd
, ".reg",
260 (int) &proc_info
- (int) & proc_info
.hw_regs
,
264 /* We always make one of these sections, for every thread. */
265 sprintf (secname
, ".reg/%d", core_kernel_thread_id (abfd
));
266 if (!make_bfd_asection (abfd
, secname
,
269 (int) &proc_info
- (int) & proc_info
.hw_regs
,
273 core_signal (abfd
) = proc_info
.sig
;
274 if (bfd_seek (abfd
, (file_ptr
) core_header
.len
, SEEK_CUR
) != 0)
285 case CORE_ANON_SHMEM
:
286 if (!make_bfd_asection (abfd
, ".data",
287 SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
,
288 core_header
.len
, core_header
.addr
, 2))
291 bfd_seek (abfd
, (file_ptr
) core_header
.len
, SEEK_CUR
);
296 /* Let's not punt if we encounter a section of unknown
297 type. Rather, let's make a note of it. If we later
298 see that there were also "good" sections, then we'll
299 declare that this a core file, but we'll also warn that
300 it may be incompatible with this gdb.
305 default: return 0; /*unrecognized core file type */
309 /* OK, we believe you. You're a core file (sure, sure). */
311 /* Were there sections of unknown type? If so, yet there were
312 at least some complete sections of known type, then, issue
313 a warning. Possibly the core file was generated on a version
314 of HP-UX that is incompatible with that for which this gdb was
317 if ((unknown_sections
> 0) && (good_sections
> 0))
318 (*_bfd_error_handler
)
319 ("%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",
326 hpux_core_core_file_failing_command (abfd
)
329 return core_command (abfd
);
334 hpux_core_core_file_failing_signal (abfd
)
337 return core_signal (abfd
);
342 hpux_core_core_file_matches_executable_p (core_bfd
, exec_bfd
)
343 bfd
*core_bfd ATTRIBUTE_UNUSED
;
344 bfd
*exec_bfd ATTRIBUTE_UNUSED
;
346 return true; /* FIXME, We have no way of telling at this point */
349 #define hpux_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
350 #define hpux_core_get_symtab _bfd_nosymbols_get_symtab
351 #define hpux_core_print_symbol _bfd_nosymbols_print_symbol
352 #define hpux_core_get_symbol_info _bfd_nosymbols_get_symbol_info
353 #define hpux_core_bfd_is_local_label_name \
354 _bfd_nosymbols_bfd_is_local_label_name
355 #define hpux_core_get_lineno _bfd_nosymbols_get_lineno
356 #define hpux_core_find_nearest_line _bfd_nosymbols_find_nearest_line
357 #define hpux_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
358 #define hpux_core_read_minisymbols _bfd_nosymbols_read_minisymbols
359 #define hpux_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
361 /* If somebody calls any byte-swapping routines, shoot them. */
365 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
367 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
368 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
369 #define NO_SIGNED_GET \
370 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
372 const bfd_target hpux_core_vec
=
375 bfd_target_unknown_flavour
,
376 BFD_ENDIAN_BIG
, /* target byte order */
377 BFD_ENDIAN_BIG
, /* target headers byte order */
378 (HAS_RELOC
| EXEC_P
| /* object flags */
379 HAS_LINENO
| HAS_DEBUG
|
380 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
381 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
382 0, /* symbol prefix */
383 ' ', /* ar_pad_char */
384 16, /* ar_max_namelen */
385 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 64 bit data */
386 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 32 bit data */
387 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 16 bit data */
388 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 64 bit hdrs */
389 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 32 bit hdrs */
390 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 16 bit hdrs */
392 { /* bfd_check_format */
393 _bfd_dummy_target
, /* unknown format */
394 _bfd_dummy_target
, /* object file */
395 _bfd_dummy_target
, /* archive */
396 hpux_core_core_file_p
/* a core file */
398 { /* bfd_set_format */
399 bfd_false
, bfd_false
,
402 { /* bfd_write_contents */
403 bfd_false
, bfd_false
,
407 BFD_JUMP_TABLE_GENERIC (_bfd_generic
),
408 BFD_JUMP_TABLE_COPY (_bfd_generic
),
409 BFD_JUMP_TABLE_CORE (hpux_core
),
410 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive
),
411 BFD_JUMP_TABLE_SYMBOLS (hpux_core
),
412 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs
),
413 BFD_JUMP_TABLE_WRITE (_bfd_generic
),
414 BFD_JUMP_TABLE_LINK (_bfd_nolink
),
415 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
419 (PTR
) 0 /* backend_data */