1999-04-16 03:35:26 +02:00
|
|
|
/* Native-dependent code for ptx 4.0
|
|
|
|
Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
This file is part of GDB.
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "inferior.h"
|
|
|
|
#include "gdbcore.h"
|
|
|
|
#include <sys/procfs.h>
|
|
|
|
#include <sys/ptrace.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2000-05-26 Michael Snyder <msnyder@seadog.cygnus.com>
* gregset.h: New file. Typedefs for gdb_gregset_t and
gdb_fpregset_t, prototypes for supply_gregset and friends.
* procfs.c: Include gregset.h. Delete local prototypes for
supply_gregset etc., and local typedef gdb_gregset_t etc.
* sol-thread.c: Include gregset.h, delete local prototypes,
add appropriate casts to gdb_gregset_t.
* uw-thread.c, lin-thread.c, core-sol2.c, core-regset.c,
sparc-tdep.c, ptx4-nat.c, ppc-linux-nat.c, mipsv4-nat.c,
m88k-nat.c, m68klinux-nat.c, m68k-tdep.c, irix5-nat.c,
irix4-nat.c, ia64-linux-nat.c, i386v4-nat.c, cxux-nat.c,
arm-linux-nat.c, alpha-nat.c: Include gregset.h.
* config/nm-linux.h: Define GDB_GREGSET_T, GDB_FPREGET_T.
* config/sparc/tm-sun4sol2.h: Ditto.
2000-05-27 01:22:41 +02:00
|
|
|
/* Prototypes for supply_gregset etc. */
|
|
|
|
#include "gregset.h"
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
/* Given a pointer to a general register set in /proc format (gregset_t *),
|
1999-07-07 22:19:36 +02:00
|
|
|
unpack the register contents and supply them as gdb's idea of the current
|
|
|
|
register values. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
supply_gregset (gregsetp)
|
|
|
|
gregset_t *gregsetp;
|
|
|
|
{
|
1999-07-07 22:19:36 +02:00
|
|
|
supply_register (EAX_REGNUM, (char *) &(*gregsetp)[EAX]);
|
|
|
|
supply_register (EDX_REGNUM, (char *) &(*gregsetp)[EDX]);
|
|
|
|
supply_register (ECX_REGNUM, (char *) &(*gregsetp)[ECX]);
|
|
|
|
supply_register (EBX_REGNUM, (char *) &(*gregsetp)[EBX]);
|
|
|
|
supply_register (ESI_REGNUM, (char *) &(*gregsetp)[ESI]);
|
|
|
|
supply_register (EDI_REGNUM, (char *) &(*gregsetp)[EDI]);
|
|
|
|
supply_register (ESP_REGNUM, (char *) &(*gregsetp)[UESP]);
|
|
|
|
supply_register (EBP_REGNUM, (char *) &(*gregsetp)[EBP]);
|
|
|
|
supply_register (EIP_REGNUM, (char *) &(*gregsetp)[EIP]);
|
|
|
|
supply_register (EFLAGS_REGNUM, (char *) &(*gregsetp)[EFL]);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fill_gregset (gregsetp, regno)
|
|
|
|
gregset_t *gregsetp;
|
|
|
|
int regno;
|
|
|
|
{
|
|
|
|
int regi;
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
for (regi = 0; regi < NUM_REGS; regi++)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
if ((regno == -1) || (regno == regi))
|
|
|
|
{
|
1999-07-07 22:19:36 +02:00
|
|
|
(*gregsetp)[regi] = *(greg_t *) & registers[REGISTER_BYTE (regi)];
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given a pointer to a floating point register set in /proc format
|
1999-07-07 22:19:36 +02:00
|
|
|
(fpregset_t *), unpack the register contents and supply them as gdb's
|
|
|
|
idea of the current floating point register values. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
void
|
1999-04-16 03:35:26 +02:00
|
|
|
supply_fpregset (fpregsetp)
|
|
|
|
fpregset_t *fpregsetp;
|
|
|
|
{
|
1999-07-07 22:19:36 +02:00
|
|
|
supply_fpu_registers ((struct fpusave *) &fpregsetp->fp_reg_set);
|
|
|
|
supply_fpa_registers ((struct fpasave *) &fpregsetp->f_wregs);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Given a pointer to a floating point register set in /proc format
|
1999-07-07 22:19:36 +02:00
|
|
|
(fpregset_t *), update the register specified by REGNO from gdb's idea
|
|
|
|
of the current floating point register set. If REGNO is -1, update
|
|
|
|
them all. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
fill_fpregset (fpregsetp, regno)
|
|
|
|
fpregset_t *fpregsetp;
|
|
|
|
int regno;
|
|
|
|
{
|
|
|
|
int regi;
|
|
|
|
char *to;
|
|
|
|
char *from;
|
|
|
|
|
|
|
|
/* FIXME: see m68k-tdep.c for an example, for the m68k. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This doesn't quite do the same thing as the procfs.c version, but give
|
|
|
|
* it the same name so we don't have to put an ifdef in solib.c.
|
|
|
|
*/
|
|
|
|
/* this could use elf_interpreter() from elfread.c */
|
|
|
|
int
|
1999-07-07 22:19:36 +02:00
|
|
|
proc_iterate_over_mappings (func)
|
|
|
|
int (*func) PARAMS ((int, CORE_ADDR));
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
1999-07-07 22:19:36 +02:00
|
|
|
vaddr_t curseg, memptr;
|
|
|
|
pt_vseg_t pv;
|
|
|
|
int rv, cmperr;
|
|
|
|
sec_ptr interp_sec;
|
|
|
|
char *interp_content;
|
|
|
|
int interp_fd, funcstat;
|
|
|
|
unsigned int size;
|
|
|
|
char buf1[NBPG], buf2[NBPG];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following is really vile. We can get the name of the
|
|
|
|
* shared library from the exec_bfd, and we can get a list of
|
|
|
|
* each virtual memory segment, but there is no simple way to
|
|
|
|
* find the mapped segment from the shared library (ala
|
|
|
|
* procfs's PIOCOPENMEM). As a pretty nasty kludge, we
|
|
|
|
* compare the virtual memory segment to the contents of the
|
|
|
|
* .interp file. If they match, we assume that we've got the
|
|
|
|
* right one.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: for attach, use XPT_OPENT to get the executable, in
|
|
|
|
* case we're attached without knowning the executable's
|
|
|
|
* filename.
|
|
|
|
*/
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
#ifdef VERBOSE_DEBUG
|
1999-07-07 22:19:36 +02:00
|
|
|
printf ("proc_iter\n");
|
1999-04-16 03:35:26 +02:00
|
|
|
#endif
|
1999-07-07 22:19:36 +02:00
|
|
|
interp_sec = bfd_get_section_by_name (exec_bfd, ".interp");
|
|
|
|
if (!interp_sec)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
size = bfd_section_size (exec_bfd, interp_sec);
|
|
|
|
interp_content = alloca (size);
|
|
|
|
if (0 == bfd_get_section_contents (exec_bfd, interp_sec,
|
|
|
|
interp_content, (file_ptr) 0, size))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
#ifdef VERBOSE_DEBUG
|
1999-07-07 22:19:36 +02:00
|
|
|
printf ("proc_iter: \"%s\"\n", interp_content);
|
1999-04-16 03:35:26 +02:00
|
|
|
#endif
|
1999-07-07 22:19:36 +02:00
|
|
|
interp_fd = open (interp_content, O_RDONLY, 0);
|
|
|
|
if (-1 == interp_fd)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
curseg = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
rv = ptrace (PT_NEXT_VSEG, inferior_pid, &pv, curseg);
|
1999-04-16 03:35:26 +02:00
|
|
|
#ifdef VERBOSE_DEBUG
|
1999-07-07 22:19:36 +02:00
|
|
|
printf ("PT_NEXT_VSEG: rv %d errno %d\n", rv, errno);
|
1999-04-16 03:35:26 +02:00
|
|
|
#endif
|
1999-07-07 22:19:36 +02:00
|
|
|
if (-1 == rv)
|
|
|
|
break;
|
|
|
|
if (0 == rv)
|
|
|
|
break;
|
1999-04-16 03:35:26 +02:00
|
|
|
#ifdef VERBOSE_DEBUG
|
1999-07-07 22:19:36 +02:00
|
|
|
printf ("pv.pv_start 0x%x pv_size 0x%x pv_prot 0x%x\n",
|
|
|
|
pv.pv_start, pv.pv_size, pv.pv_prot);
|
1999-04-16 03:35:26 +02:00
|
|
|
#endif
|
1999-07-07 22:19:36 +02:00
|
|
|
curseg = pv.pv_start + pv.pv_size;
|
|
|
|
|
|
|
|
rv = lseek (interp_fd, 0, SEEK_SET);
|
|
|
|
if (-1 == rv)
|
|
|
|
{
|
|
|
|
perror ("lseek");
|
|
|
|
close (interp_fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (memptr = pv.pv_start; memptr < pv.pv_start + pv.pv_size;
|
|
|
|
memptr += NBPG)
|
|
|
|
{
|
1999-04-16 03:35:26 +02:00
|
|
|
#ifdef VERBOSE_DEBUG
|
1999-07-07 22:19:36 +02:00
|
|
|
printf ("memptr 0x%x\n", memptr);
|
1999-04-16 03:35:26 +02:00
|
|
|
#endif
|
1999-07-07 22:19:36 +02:00
|
|
|
rv = read (interp_fd, buf1, NBPG);
|
|
|
|
if (-1 == rv)
|
|
|
|
{
|
|
|
|
perror ("read");
|
|
|
|
close (interp_fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rv = ptrace (PT_RDATA_PAGE, inferior_pid, buf2,
|
|
|
|
memptr);
|
|
|
|
if (-1 == rv)
|
|
|
|
{
|
|
|
|
perror ("ptrace");
|
|
|
|
close (interp_fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
cmperr = memcmp (buf1, buf2, NBPG);
|
|
|
|
if (cmperr)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (0 == cmperr)
|
|
|
|
{
|
|
|
|
/* this is it */
|
|
|
|
funcstat = (*func) (interp_fd, pv.pv_start);
|
|
|
|
break;
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
1999-07-07 22:19:36 +02:00
|
|
|
}
|
|
|
|
close (interp_fd);
|
|
|
|
return 0;
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|