#ifdef PTRACE_CORE
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include <sys/param.h>
#include <sys/dir.h>
#include <signal.h>
#include <sys/ptrace.h>
struct trad_core_struct
{
asection *data_section;
asection *stack_section;
asection *reg_section;
struct ptrace_user u;
};
#define core_upage(bfd) (&((bfd)->tdata.trad_core_data->u))
#define core_datasec(bfd) ((bfd)->tdata.trad_core_data->data_section)
#define core_stacksec(bfd) ((bfd)->tdata.trad_core_data->stack_section)
#define core_regsec(bfd) ((bfd)->tdata.trad_core_data->reg_section)
const bfd_target *ptrace_unix_core_file_p PARAMS ((bfd *abfd));
char * ptrace_unix_core_file_failing_command PARAMS ((bfd *abfd));
int ptrace_unix_core_file_failing_signal PARAMS ((bfd *abfd));
bfd_boolean ptrace_unix_core_file_matches_executable_p
PARAMS ((bfd *core_bfd, bfd *exec_bfd));
static void swap_abort PARAMS ((void));
const bfd_target *
ptrace_unix_core_file_p (abfd)
bfd *abfd;
{
int val;
struct ptrace_user u;
struct trad_core_struct *rawptr;
bfd_size_type amt;
val = bfd_bread ((void *)&u, (bfd_size_type) sizeof u, abfd);
if (val != sizeof u || u.pt_magic != _BCS_PTRACE_MAGIC
|| u.pt_rev != _BCS_PTRACE_REV)
{
bfd_set_error (bfd_error_wrong_format);
return 0;
}
amt = sizeof (struct trad_core_struct);
rawptr = (struct trad_core_struct *) bfd_zalloc (abfd, amt);
if (rawptr == NULL)
return 0;
abfd->tdata.trad_core_data = rawptr;
rawptr->u = u;
core_stacksec (abfd) = bfd_make_section_anyway (abfd, ".stack");
if (core_stacksec (abfd) == NULL)
goto fail;
core_datasec (abfd) = bfd_make_section_anyway (abfd, ".data");
if (core_datasec (abfd) == NULL)
goto fail;
core_regsec (abfd) = bfd_make_section_anyway (abfd, ".reg");
if (core_regsec (abfd) == NULL)
goto fail;
core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
core_regsec (abfd)->flags = SEC_HAS_CONTENTS;
core_datasec (abfd)->_raw_size = u.pt_dsize;
core_stacksec (abfd)->_raw_size = u.pt_ssize;
core_regsec (abfd)->_raw_size = sizeof (u);
core_datasec (abfd)->vma = u.pt_o_data_start;
core_stacksec (abfd)->vma = USRSTACK - u.pt_ssize;
core_regsec (abfd)->vma = 0 - sizeof (u);
core_datasec (abfd)->filepos = (int) u.pt_dataptr;
core_stacksec (abfd)->filepos = (int) (u.pt_dataptr + u.pt_dsize);
core_regsec (abfd)->filepos = 0;
core_stacksec (abfd)->alignment_power = 2;
core_datasec (abfd)->alignment_power = 2;
core_regsec (abfd)->alignment_power = 2;
return abfd->xvec;
fail:
bfd_release (abfd, abfd->tdata.any);
abfd->tdata.any = NULL;
bfd_section_list_clear (abfd);
return NULL;
}
char *
ptrace_unix_core_file_failing_command (abfd)
bfd *abfd;
{
char *com = abfd->tdata.trad_core_data->u.pt_comm;
if (*com)
return com;
else
return 0;
}
int
ptrace_unix_core_file_failing_signal (abfd)
bfd *abfd;
{
return abfd->tdata.trad_core_data->u.pt_sigframe.sig_num;
}
bfd_boolean
ptrace_unix_core_file_matches_executable_p (core_bfd, exec_bfd)
bfd *core_bfd, *exec_bfd;
{
return TRUE;
}
static void
swap_abort ()
{
abort ();
}
#define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
#define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
#define NO_SIGNED_GET \
((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
const bfd_target ptrace_core_vec =
{
"trad-core",
bfd_target_unknown_flavour,
BFD_ENDIAN_UNKNOWN,
BFD_ENDIAN_UNKNOWN,
(HAS_RELOC | EXEC_P |
HAS_LINENO | HAS_DEBUG |
HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),
0,
' ',
16,
NO_GET, NO_SIGNED_GET, NO_PUT,
NO_GET, NO_SIGNED_GET, NO_PUT,
NO_GET, NO_SIGNED_GET, NO_PUT,
NO_GET, NO_SIGNED_GET, NO_PUT,
NO_GET, NO_SIGNED_GET, NO_PUT,
NO_GET, NO_SIGNED_GET, NO_PUT,
{
_bfd_dummy_target,
_bfd_dummy_target,
_bfd_dummy_target,
ptrace_unix_core_file_p
},
{
bfd_false, bfd_false,
bfd_false, bfd_false
},
{
bfd_false, bfd_false,
bfd_false, bfd_false
},
BFD_JUMP_TABLE_GENERIC (_bfd_generic),
BFD_JUMP_TABLE_COPY (_bfd_generic),
BFD_JUMP_TABLE_CORE (ptrace_unix),
BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
BFD_JUMP_TABLE_WRITE (_bfd_generic),
BFD_JUMP_TABLE_LINK (_bfd_nolink),
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
NULL,
(PTR) 0
};
#endif