summaryrefslogtreecommitdiff
path: root/gdb/loongarch-linux-nat.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/loongarch-linux-nat.c')
-rw-r--r--gdb/loongarch-linux-nat.c57
1 files changed, 24 insertions, 33 deletions
diff --git a/gdb/loongarch-linux-nat.c b/gdb/loongarch-linux-nat.c
index edc3d697d7..c341e7199e 100644
--- a/gdb/loongarch-linux-nat.c
+++ b/gdb/loongarch-linux-nat.c
@@ -40,23 +40,21 @@ public:
protected:
/* Override linux_nat_trad_target methods. */
- CORE_ADDR register_u_offset (struct gdbarch *gdbarch, int regno,
- int store_p) override;
+ CORE_ADDR register_u_offset (struct gdbarch *gdbarch, int regnum,
+ int store_p) override;
};
/* Fill GDB's register array with the general-purpose, pc and badv
register values from the current thread. */
static void
-fetch_gregs_from_thread (struct regcache *regcache, int regno, pid_t tid)
+fetch_gregs_from_thread (struct regcache *regcache, int regnum, pid_t tid)
{
- loongarch_gdbarch_tdep *tdep
- = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
- auto regs = tdep->regs;
elf_gregset_t regset;
- if (regno == -1 || (regs.r <= regno && regno < regs.r + 32)
- || regs.pc == regno || regs.badv == regno)
+ if (regnum == -1 || (regnum >= 0 && regnum < 32)
+ || regnum == LOONGARCH_PC_REGNUM
+ || regnum == LOONGARCH_BADV_REGNUM)
{
struct iovec iov;
@@ -66,7 +64,7 @@ fetch_gregs_from_thread (struct regcache *regcache, int regno, pid_t tid)
if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, (long) &iov) < 0)
perror_with_name (_("Couldn't get NT_PRSTATUS registers"));
else
- loongarch_gregset.supply_regset (nullptr, regcache, regno,
+ loongarch_gregset.supply_regset (nullptr, regcache, regnum,
&regset, sizeof (regset));
}
}
@@ -75,15 +73,13 @@ fetch_gregs_from_thread (struct regcache *regcache, int regno, pid_t tid)
register values in the GDB's register array. */
static void
-store_gregs_to_thread (struct regcache *regcache, int regno, pid_t tid)
+store_gregs_to_thread (struct regcache *regcache, int regnum, pid_t tid)
{
- loongarch_gdbarch_tdep *tdep
- = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
- auto regs = tdep->regs;
elf_gregset_t regset;
- if (regno == -1 || (regs.r <= regno && regno < regs.r + 32)
- || regs.pc == regno || regs.badv == regno)
+ if (regnum == -1 || (regnum >= 0 && regnum < 32)
+ || regnum == LOONGARCH_PC_REGNUM
+ || regnum == LOONGARCH_BADV_REGNUM)
{
struct iovec iov;
@@ -94,7 +90,7 @@ store_gregs_to_thread (struct regcache *regcache, int regno, pid_t tid)
perror_with_name (_("Couldn't get NT_PRSTATUS registers"));
else
{
- loongarch_gregset.collect_regset (nullptr, regcache, regno,
+ loongarch_gregset.collect_regset (nullptr, regcache, regnum,
&regset, sizeof (regset));
if (ptrace (PTRACE_SETREGSET, tid, NT_PRSTATUS, (long) &iov) < 0)
perror_with_name (_("Couldn't set NT_PRSTATUS registers"));
@@ -106,39 +102,34 @@ store_gregs_to_thread (struct regcache *regcache, int regno, pid_t tid)
void
loongarch_linux_nat_target::fetch_registers (struct regcache *regcache,
- int regno)
+ int regnum)
{
pid_t tid = get_ptrace_pid (regcache->ptid ());
- fetch_gregs_from_thread(regcache, regno, tid);
+ fetch_gregs_from_thread(regcache, regnum, tid);
}
/* Implement the "store_registers" target_ops method. */
void
loongarch_linux_nat_target::store_registers (struct regcache *regcache,
- int regno)
+ int regnum)
{
pid_t tid = get_ptrace_pid (regcache->ptid ());
- store_gregs_to_thread (regcache, regno, tid);
+ store_gregs_to_thread (regcache, regnum, tid);
}
/* Return the address in the core dump or inferior of register REGNO. */
CORE_ADDR
loongarch_linux_nat_target::register_u_offset (struct gdbarch *gdbarch,
- int regno, int store_p)
+ int regnum, int store_p)
{
- loongarch_gdbarch_tdep *tdep
- = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
- auto regs = tdep->regs;
-
- /* According to <asm/ptrace.h> */
- if (0 <= regs.r && regs.r <= regno && regno < regs.r + GPR_NUM)
- return GPR_BASE + regno - regs.r;
- else if (regs.pc == regno)
- return PC;
+ if (regnum >= 0 && regnum < 32)
+ return regnum;
+ else if (regnum == LOONGARCH_PC_REGNUM)
+ return LOONGARCH_PC_REGNUM;
else
return -1;
}
@@ -156,9 +147,9 @@ supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregset)
void
fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregset,
- int regno)
+ int regnum)
{
- loongarch_gregset.collect_regset (nullptr, regcache, regno, gregset,
+ loongarch_gregset.collect_regset (nullptr, regcache, regnum, gregset,
sizeof (gdb_gregset_t));
}
@@ -169,7 +160,7 @@ supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregset)
void
fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregset,
- int regno)
+ int regnum)
{
}