/* Functions specific to running gdb native on a SPARC running SunOS4.
- Copyright 1989, 1992, 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001
- Free Software Foundation, Inc.
+
+ Copyright 1989, 1992, 1993, 1994, 1996, 1997, 1998, 1999, 2000,
+ 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of GDB.
#include "gdbcore.h"
#include "regcache.h"
+#include "sparc-tdep.h"
+
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <signal.h>
#include <sys/ptrace.h>
-#include <sys/wait.h>
+#include "gdb_wait.h"
#ifdef __linux__
#include <asm/reg.h>
#else
struct regs inferior_registers;
struct fp_status inferior_fp_registers;
int i;
+ int fetch_pid;
+
+ /* NOTE: cagney/2002-12-03: This code assumes that the currently
+ selected light weight processes' registers can be written
+ directly into the selected thread's register cache. This works
+ fine when given an 1:1 LWP:thread model (such as found on
+ GNU/Linux) but will, likely, have problems when used on an N:1
+ (userland threads) or N:M (userland multiple LWP) model. In the
+ case of the latter two, the LWP's registers do not necessarily
+ belong to the selected thread (the LWP could be in the middle of
+ executing the thread switch code).
+
+ These functions should instead be paramaterized with an explicit
+ object (struct regcache, struct thread_info?) into which the LWPs
+ registers can be written. */
+
+ fetch_pid = TIDGET (inferior_ptid);
+ if (fetch_pid == 0)
+ fetch_pid = PIDGET (inferior_ptid);
/* We should never be called with deferred stores, because a prerequisite
for writing regs is to have fetched them all (PREPARE_TO_STORE), sigh. */
to the stack pointer. */
if (regno < O7_REGNUM /* including -1 */
|| regno >= Y_REGNUM
- || (!register_valid[SP_REGNUM] && regno < I7_REGNUM))
+ || (!deprecated_register_valid[SP_REGNUM] && regno < I7_REGNUM))
{
- if (0 != ptrace (PTRACE_GETREGS, PIDGET (inferior_ptid),
+ if (0 != ptrace (PTRACE_GETREGS, fetch_pid,
(PTRACE_ARG3_TYPE) & inferior_registers, 0))
perror ("ptrace_getregs");
- registers[REGISTER_BYTE (0)] = 0;
- memcpy (®isters[REGISTER_BYTE (1)], &inferior_registers.r_g1,
- 15 * REGISTER_RAW_SIZE (G0_REGNUM));
- *(int *) ®isters[REGISTER_BYTE (PS_REGNUM)] = inferior_registers.r_ps;
- *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)] = inferior_registers.r_pc;
- *(int *) ®isters[REGISTER_BYTE (NPC_REGNUM)] = inferior_registers.r_npc;
- *(int *) ®isters[REGISTER_BYTE (Y_REGNUM)] = inferior_registers.r_y;
+ deprecated_registers[DEPRECATED_REGISTER_BYTE (0)] = 0;
+ memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (1)],
+ &inferior_registers.r_g1, 15 * DEPRECATED_REGISTER_RAW_SIZE (G0_REGNUM));
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (PS_REGNUM)]
+ = inferior_registers.r_ps;
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (PC_REGNUM)]
+ = inferior_registers.r_pc;
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (DEPRECATED_NPC_REGNUM)]
+ = inferior_registers.r_npc;
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (Y_REGNUM)] = inferior_registers.r_y;
for (i = G0_REGNUM; i <= O7_REGNUM; i++)
- register_valid[i] = 1;
- register_valid[Y_REGNUM] = 1;
- register_valid[PS_REGNUM] = 1;
- register_valid[PC_REGNUM] = 1;
- register_valid[NPC_REGNUM] = 1;
+ deprecated_register_valid[i] = 1;
+ deprecated_register_valid[Y_REGNUM] = 1;
+ deprecated_register_valid[PS_REGNUM] = 1;
+ deprecated_register_valid[PC_REGNUM] = 1;
+ deprecated_register_valid[DEPRECATED_NPC_REGNUM] = 1;
/* If we don't set these valid, read_register_bytes() rereads
all the regs every time it is called! FIXME. */
- register_valid[WIM_REGNUM] = 1; /* Not true yet, FIXME */
- register_valid[TBR_REGNUM] = 1; /* Not true yet, FIXME */
- register_valid[CPS_REGNUM] = 1; /* Not true yet, FIXME */
+ deprecated_register_valid[WIM_REGNUM] = 1; /* Not true yet, FIXME */
+ deprecated_register_valid[TBR_REGNUM] = 1; /* Not true yet, FIXME */
+ deprecated_register_valid[CPS_REGNUM] = 1; /* Not true yet, FIXME */
}
/* Floating point registers */
regno == FPS_REGNUM ||
(regno >= FP0_REGNUM && regno <= FP0_REGNUM + 31))
{
- if (0 != ptrace (PTRACE_GETFPREGS, PIDGET (inferior_ptid),
+ if (0 != ptrace (PTRACE_GETFPREGS, fetch_pid,
(PTRACE_ARG3_TYPE) & inferior_fp_registers,
0))
perror ("ptrace_getfpregs");
- memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], &inferior_fp_registers,
- sizeof inferior_fp_registers.fpu_fr);
- memcpy (®isters[REGISTER_BYTE (FPS_REGNUM)],
- &inferior_fp_registers.Fpu_fsr,
- sizeof (FPU_FSR_TYPE));
+ memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM)],
+ &inferior_fp_registers, sizeof inferior_fp_registers.fpu_fr);
+ memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (FPS_REGNUM)],
+ &inferior_fp_registers.Fpu_fsr, sizeof (FPU_FSR_TYPE));
for (i = FP0_REGNUM; i <= FP0_REGNUM + 31; i++)
- register_valid[i] = 1;
- register_valid[FPS_REGNUM] = 1;
+ deprecated_register_valid[i] = 1;
+ deprecated_register_valid[FPS_REGNUM] = 1;
}
/* These regs are saved on the stack by the kernel. Only read them
all (16 ptrace calls!) if we really need them. */
if (regno == -1)
{
- CORE_ADDR sp = *(unsigned int *) & registers[REGISTER_BYTE (SP_REGNUM)];
- target_read_memory (sp, ®isters[REGISTER_BYTE (L0_REGNUM)],
- 16 * REGISTER_RAW_SIZE (L0_REGNUM));
+ CORE_ADDR sp = *(unsigned int *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (SP_REGNUM)];
+ target_read_memory (sp, &deprecated_registers[DEPRECATED_REGISTER_BYTE (L0_REGNUM)],
+ 16 * DEPRECATED_REGISTER_RAW_SIZE (L0_REGNUM));
for (i = L0_REGNUM; i <= I7_REGNUM; i++)
- register_valid[i] = 1;
+ deprecated_register_valid[i] = 1;
}
else if (regno >= L0_REGNUM && regno <= I7_REGNUM)
{
- CORE_ADDR sp = *(unsigned int *) & registers[REGISTER_BYTE (SP_REGNUM)];
- i = REGISTER_BYTE (regno);
- if (register_valid[regno])
+ CORE_ADDR sp = *(unsigned int *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (SP_REGNUM)];
+ i = DEPRECATED_REGISTER_BYTE (regno);
+ if (deprecated_register_valid[regno])
printf_unfiltered ("register %d valid and read\n", regno);
- target_read_memory (sp + i - REGISTER_BYTE (L0_REGNUM),
- ®isters[i], REGISTER_RAW_SIZE (regno));
- register_valid[regno] = 1;
+ target_read_memory (sp + i - DEPRECATED_REGISTER_BYTE (L0_REGNUM),
+ &deprecated_registers[i], DEPRECATED_REGISTER_RAW_SIZE (regno));
+ deprecated_register_valid[regno] = 1;
}
}
struct regs inferior_registers;
struct fp_status inferior_fp_registers;
int wanna_store = INT_REGS + STACK_REGS + FP_REGS;
+ int store_pid;
+
+ /* NOTE: cagney/2002-12-02: See comment in fetch_inferior_registers
+ about threaded assumptions. */
+ store_pid = TIDGET (inferior_ptid);
+ if (store_pid == 0)
+ store_pid = PIDGET (inferior_ptid);
/* First decide which pieces of machine-state we need to modify.
Default for regno == -1 case is all pieces. */
if (wanna_store & STACK_REGS)
{
- CORE_ADDR sp = *(unsigned int *) & registers[REGISTER_BYTE (SP_REGNUM)];
+ CORE_ADDR sp = *(unsigned int *) & deprecated_registers[DEPRECATED_REGISTER_BYTE (SP_REGNUM)];
if (regno < 0 || regno == SP_REGNUM)
{
- if (!register_valid[L0_REGNUM + 5])
+ if (!deprecated_register_valid[L0_REGNUM + 5])
internal_error (__FILE__, __LINE__, "failed internal consistency check");
target_write_memory (sp,
- ®isters[REGISTER_BYTE (L0_REGNUM)],
- 16 * REGISTER_RAW_SIZE (L0_REGNUM));
+ &deprecated_registers[DEPRECATED_REGISTER_BYTE (L0_REGNUM)],
+ 16 * DEPRECATED_REGISTER_RAW_SIZE (L0_REGNUM));
}
else
{
- if (!register_valid[regno])
+ if (!deprecated_register_valid[regno])
internal_error (__FILE__, __LINE__, "failed internal consistency check");
- target_write_memory (sp + REGISTER_BYTE (regno) - REGISTER_BYTE (L0_REGNUM),
- ®isters[REGISTER_BYTE (regno)],
- REGISTER_RAW_SIZE (regno));
+ target_write_memory (sp + DEPRECATED_REGISTER_BYTE (regno) - DEPRECATED_REGISTER_BYTE (L0_REGNUM),
+ &deprecated_registers[DEPRECATED_REGISTER_BYTE (regno)],
+ DEPRECATED_REGISTER_RAW_SIZE (regno));
}
}
if (wanna_store & INT_REGS)
{
- if (!register_valid[G1_REGNUM])
+ if (!deprecated_register_valid[G1_REGNUM])
internal_error (__FILE__, __LINE__, "failed internal consistency check");
- memcpy (&inferior_registers.r_g1, ®isters[REGISTER_BYTE (G1_REGNUM)],
- 15 * REGISTER_RAW_SIZE (G1_REGNUM));
+ memcpy (&inferior_registers.r_g1,
+ &deprecated_registers[DEPRECATED_REGISTER_BYTE (G1_REGNUM)],
+ 15 * DEPRECATED_REGISTER_RAW_SIZE (G1_REGNUM));
inferior_registers.r_ps =
- *(int *) ®isters[REGISTER_BYTE (PS_REGNUM)];
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (PS_REGNUM)];
inferior_registers.r_pc =
- *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)];
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (PC_REGNUM)];
inferior_registers.r_npc =
- *(int *) ®isters[REGISTER_BYTE (NPC_REGNUM)];
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (DEPRECATED_NPC_REGNUM)];
inferior_registers.r_y =
- *(int *) ®isters[REGISTER_BYTE (Y_REGNUM)];
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (Y_REGNUM)];
- if (0 != ptrace (PTRACE_SETREGS, PIDGET (inferior_ptid),
+ if (0 != ptrace (PTRACE_SETREGS, store_pid,
(PTRACE_ARG3_TYPE) & inferior_registers, 0))
perror ("ptrace_setregs");
}
if (wanna_store & FP_REGS)
{
- if (!register_valid[FP0_REGNUM + 9])
+ if (!deprecated_register_valid[FP0_REGNUM + 9])
internal_error (__FILE__, __LINE__, "failed internal consistency check");
- memcpy (&inferior_fp_registers, ®isters[REGISTER_BYTE (FP0_REGNUM)],
+ memcpy (&inferior_fp_registers,
+ &deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM)],
sizeof inferior_fp_registers.fpu_fr);
memcpy (&inferior_fp_registers.Fpu_fsr,
- ®isters[REGISTER_BYTE (FPS_REGNUM)], sizeof (FPU_FSR_TYPE));
+ &deprecated_registers[DEPRECATED_REGISTER_BYTE (FPS_REGNUM)],
+ sizeof (FPU_FSR_TYPE));
if (0 !=
- ptrace (PTRACE_SETFPREGS, PIDGET (inferior_ptid),
+ ptrace (PTRACE_SETFPREGS, store_pid,
(PTRACE_ARG3_TYPE) & inferior_fp_registers, 0))
perror ("ptrace_setfpregs");
}
#define gregs ((struct regs *)core_reg_sect)
/* G0 *always* holds 0. */
- *(int *) ®isters[REGISTER_BYTE (0)] = 0;
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (0)] = 0;
/* The globals and output registers. */
- memcpy (®isters[REGISTER_BYTE (G1_REGNUM)], &gregs->r_g1,
- 15 * REGISTER_RAW_SIZE (G1_REGNUM));
- *(int *) ®isters[REGISTER_BYTE (PS_REGNUM)] = gregs->r_ps;
- *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)] = gregs->r_pc;
- *(int *) ®isters[REGISTER_BYTE (NPC_REGNUM)] = gregs->r_npc;
- *(int *) ®isters[REGISTER_BYTE (Y_REGNUM)] = gregs->r_y;
+ memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (G1_REGNUM)], &gregs->r_g1,
+ 15 * DEPRECATED_REGISTER_RAW_SIZE (G1_REGNUM));
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (PS_REGNUM)] = gregs->r_ps;
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (PC_REGNUM)] = gregs->r_pc;
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (DEPRECATED_NPC_REGNUM)] = gregs->r_npc;
+ *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (Y_REGNUM)] = gregs->r_y;
/* My best guess at where to get the locals and input
registers is exactly where they usually are, right above
{
int sp;
- sp = *(int *) ®isters[REGISTER_BYTE (SP_REGNUM)];
- if (0 != target_read_memory (sp, ®isters[REGISTER_BYTE (L0_REGNUM)],
- 16 * REGISTER_RAW_SIZE (L0_REGNUM)))
+ sp = *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (SP_REGNUM)];
+ if (0 != target_read_memory (sp,
+ &deprecated_registers[DEPRECATED_REGISTER_BYTE (L0_REGNUM)],
+ 16 * DEPRECATED_REGISTER_RAW_SIZE (L0_REGNUM)))
{
/* fprintf_unfiltered so user can still use gdb */
fprintf_unfiltered (gdb_stderr,
#define fpuregs ((struct fpu *) core_reg_sect)
if (core_reg_size >= sizeof (struct fpu))
{
- memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], fpuregs->fpu_regs,
- sizeof (fpuregs->fpu_regs));
- memcpy (®isters[REGISTER_BYTE (FPS_REGNUM)], &fpuregs->fpu_fsr,
- sizeof (FPU_FSR_TYPE));
+ memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (FP0_REGNUM)],
+ fpuregs->fpu_regs, sizeof (fpuregs->fpu_regs));
+ memcpy (&deprecated_registers[DEPRECATED_REGISTER_BYTE (FPS_REGNUM)],
+ &fpuregs->fpu_fsr, sizeof (FPU_FSR_TYPE));
}
else
fprintf_unfiltered (gdb_stderr, "Couldn't read float regs from core file\n");