This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Replace some $ARCH_{get,set}_pc with linux_{get,set}_pc_32bit
- From: Yao Qi <qiyaoltc at gmail dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 11 Jan 2016 09:11:51 +0000
- Subject: [PATCH] Replace some $ARCH_{get,set}_pc with linux_{get,set}_pc_32bit
- Authentication-results: sourceware.org; auth=none
This patch adds a pair of new functions linux_get_pc_32bit and
linux_set_pc_32bit which get and set 32-bit register "pc" from
regcache. This function can be used some targets and these own
$ARCH_{get,set}_pc are replaced by linux_{get,set}_pc_32bit
respectively.
This patch touches many targets, but I only have arm board to
test and no regression. I also rebuilt nios2-linux GDBserver.
If it is right to go, I'll post the 64-bit counterpart later.
gdb/gdbserver:
2016-01-11 Yao Qi <yao.qi@linaro.org>
* linux-arm-low.c (debug_threads): Remove declaration.
(arm_get_pc, arm_set_pc): Remove.
(the_low_target): Use linux_get_pc_32bit and
linux_set_pc_32bit.
* linux-bfin-low.c (bfin_get_pc, bfin_set_pc): Remove.
(the_low_target): Use linux_get_pc_32bit and
linux_set_pc_32bit.
* linux-cris-low.c (debug_threads): Remove declaration.
(cris_get_pc, cris_set_pc,): Remove.
(the_low_target): Use linux_get_pc_32bit and
linux_set_pc_32bit.
* linux-crisv32-low.c (debug_threads): Remove declaration.
(cris_get_pc, cris_set_pc): Remove.
(the_low_target): Use linux_get_pc_32bit and
linux_set_pc_32bit.
* linux-low.c: Include inttypes.h.
(linux_get_pc_32bit, linux_set_pc_32bit): New functions.
* linux-low.h (linux_get_pc_32bit, linux_set_pc_32bit): Declare.
* linux-m32r-low.c (m32r_get_pc, m32r_set_pc): Remove.
(the_low_target): Use linux_get_pc_32bit and
linux_set_pc_32bit.
* linux-m68k-low.c (m68k_get_pc, m68k_set_pc): Remove.
(the_low_target): Use linux_get_pc_32bit and
linux_set_pc_32bit.
* linux-nios2-low.c (nios2_get_pc, nios2_set_pc): Remove.
(the_low_target): Use linux_get_pc_32bit and
linux_set_pc_32bit.
* linux-sh-low.c (sh_get_pc, sh_set_pc): Remove.
(the_low_target): Use linux_get_pc_32bit and
linux_set_pc_32bit.
* linux-xtensa-low.c (xtensa_get_pc, xtensa_set_pc): Remove.
(the_low_target): Use linux_get_pc_32bit and
linux_set_pc_32bit.
---
gdb/gdbserver/linux-arm-low.c | 23 ++---------------------
gdb/gdbserver/linux-bfin-low.c | 22 ++--------------------
gdb/gdbserver/linux-cris-low.c | 23 ++---------------------
gdb/gdbserver/linux-crisv32-low.c | 23 ++---------------------
gdb/gdbserver/linux-low.c | 26 ++++++++++++++++++++++++++
gdb/gdbserver/linux-low.h | 3 +++
gdb/gdbserver/linux-m32r-low.c | 21 ++-------------------
gdb/gdbserver/linux-m68k-low.c | 21 ++-------------------
gdb/gdbserver/linux-nios2-low.c | 26 ++------------------------
gdb/gdbserver/linux-sh-low.c | 19 ++-----------------
gdb/gdbserver/linux-xtensa-low.c | 20 ++------------------
11 files changed, 47 insertions(+), 180 deletions(-)
diff --git a/gdb/gdbserver/linux-arm-low.c b/gdb/gdbserver/linux-arm-low.c
index 30981dc..39cb745 100644
--- a/gdb/gdbserver/linux-arm-low.c
+++ b/gdb/gdbserver/linux-arm-low.c
@@ -245,25 +245,6 @@ arm_store_vfpregset (struct regcache *regcache, const void *buf)
arm_store_vfpregset_num (regcache, buf, num);
}
-extern int debug_threads;
-
-static CORE_ADDR
-arm_get_pc (struct regcache *regcache)
-{
- unsigned long pc;
- collect_register_by_name (regcache, "pc", &pc);
- if (debug_threads)
- debug_printf ("stop pc is %08lx\n", pc);
- return pc;
-}
-
-static void
-arm_set_pc (struct regcache *regcache, CORE_ADDR pc)
-{
- unsigned long newpc = pc;
- supply_register_by_name (regcache, "pc", &newpc);
-}
-
/* Wrapper of arm_is_thumb_mode for get_next_pcs. */
static int
get_next_pcs_is_thumb (struct arm_get_next_pcs *self)
@@ -1011,8 +992,8 @@ struct linux_target_ops the_low_target = {
arm_cannot_fetch_register,
arm_cannot_store_register,
NULL, /* fetch_register */
- arm_get_pc,
- arm_set_pc,
+ linux_get_pc_32bit,
+ linux_set_pc_32bit,
arm_breakpoint_kind_from_pc,
arm_sw_breakpoint_from_kind,
arm_gdbserver_get_next_pcs,
diff --git a/gdb/gdbserver/linux-bfin-low.c b/gdb/gdbserver/linux-bfin-low.c
index 5fdb7d4..8d08f7a 100644
--- a/gdb/gdbserver/linux-bfin-low.c
+++ b/gdb/gdbserver/linux-bfin-low.c
@@ -54,24 +54,6 @@ bfin_cannot_fetch_register (int regno)
return (regno >= bfin_num_regs);
}
-static CORE_ADDR
-bfin_get_pc (struct regcache *regcache)
-{
- unsigned long pc;
-
- collect_register_by_name (regcache, "pc", &pc);
-
- return pc;
-}
-
-static void
-bfin_set_pc (struct regcache *regcache, CORE_ADDR pc)
-{
- unsigned long newpc = pc;
-
- supply_register_by_name (regcache, "pc", &newpc);
-}
-
#define bfin_breakpoint_len 2
static const gdb_byte bfin_breakpoint[bfin_breakpoint_len] = {0xa1, 0x00};
@@ -137,8 +119,8 @@ struct linux_target_ops the_low_target = {
bfin_cannot_fetch_register,
bfin_cannot_store_register,
NULL, /* fetch_register */
- bfin_get_pc,
- bfin_set_pc,
+ linux_get_pc_32bit,
+ linux_set_pc_32bit,
NULL, /* breakpoint_kind_from_pc */
bfin_sw_breakpoint_from_kind,
NULL, /* get_next_pcs */
diff --git a/gdb/gdbserver/linux-cris-low.c b/gdb/gdbserver/linux-cris-low.c
index ca0f0ff..45d4299 100644
--- a/gdb/gdbserver/linux-cris-low.c
+++ b/gdb/gdbserver/linux-cris-low.c
@@ -59,25 +59,6 @@ cris_cannot_fetch_register (int regno)
return (regno >= cris_num_regs);
}
-extern int debug_threads;
-
-static CORE_ADDR
-cris_get_pc (struct regcache *regcache)
-{
- unsigned long pc;
- collect_register_by_name (regcache, "pc", &pc);
- if (debug_threads)
- debug_printf ("stop pc is %08lx\n", pc);
- return pc;
-}
-
-static void
-cris_set_pc (struct regcache *regcache, CORE_ADDR pc)
-{
- unsigned long newpc = pc;
- supply_register_by_name (regcache, "pc", &newpc);
-}
-
static const unsigned short cris_breakpoint = 0xe938;
#define cris_breakpoint_len 2
@@ -135,8 +116,8 @@ struct linux_target_ops the_low_target = {
cris_cannot_fetch_register,
cris_cannot_store_register,
NULL, /* fetch_register */
- cris_get_pc,
- cris_set_pc,
+ linux_get_pc_32bit,
+ linux_set_pc_32bit,
NULL, /* breakpoint_kind_from_pc */
cris_sw_breakpoint_from_kind,
NULL, /* get_next_pcs */
diff --git a/gdb/gdbserver/linux-crisv32-low.c b/gdb/gdbserver/linux-crisv32-low.c
index 35b2048..16c1f72 100644
--- a/gdb/gdbserver/linux-crisv32-low.c
+++ b/gdb/gdbserver/linux-crisv32-low.c
@@ -55,25 +55,6 @@ static int cris_regmap[] = {
};
-extern int debug_threads;
-
-static CORE_ADDR
-cris_get_pc (struct regcache *regcache)
-{
- unsigned long pc;
- collect_register_by_name (regcache, "pc", &pc);
- if (debug_threads)
- debug_printf ("stop pc is %08lx\n", pc);
- return pc;
-}
-
-static void
-cris_set_pc (struct regcache *regcache, CORE_ADDR pc)
-{
- unsigned long newpc = pc;
- supply_register_by_name (regcache, "pc", &newpc);
-}
-
static const unsigned short cris_breakpoint = 0xe938;
#define cris_breakpoint_len 2
@@ -418,8 +399,8 @@ struct linux_target_ops the_low_target = {
NULL,
NULL,
NULL, /* fetch_register */
- cris_get_pc,
- cris_set_pc,
+ linux_get_pc_32bit,
+ linux_set_pc_32bit,
NULL, /* breakpoint_kind_from_pc */
cris_sw_breakpoint_from_kind,
NULL, /* get_next_pcs */
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 4f8f573..738bd13 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -46,6 +46,7 @@
#include "filestuff.h"
#include "tracepoint.h"
#include "hostio.h"
+#include <inttypes.h>
#ifndef ELFMAG0
/* Don't include <linux/elf.h> here. If it got included by gdb_proc_service.h
then ELFMAG0 will have been defined. If it didn't get included by
@@ -7111,6 +7112,31 @@ linux_breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
return linux_breakpoint_kind_from_pc (pcptr);
}
+/* Default implementation of linux_target_ops method "set_pc" for
+ 32-bit pc register which is literally named "pc". */
+
+void
+linux_set_pc_32bit (struct regcache *regcache, CORE_ADDR pc)
+{
+ uint32_t newpc = pc;
+
+ supply_register_by_name (regcache, "pc", &newpc);
+}
+
+/* Default implementation of linux_target_ops method "get_pc" for
+ 32-bit pc register which is literally named "pc". */
+
+CORE_ADDR
+linux_get_pc_32bit (struct regcache *regcache)
+{
+ uint32_t pc;
+
+ collect_register_by_name (regcache, "pc", &pc);
+ if (debug_threads)
+ debug_printf ("stop pc is 0x%" PRIx32 "\n", pc);
+ return pc;
+}
+
static struct target_ops linux_target_ops = {
linux_create_inferior,
linux_post_create_inferior,
diff --git a/gdb/gdbserver/linux-low.h b/gdb/gdbserver/linux-low.h
index e80c67f..1031f2e 100644
--- a/gdb/gdbserver/linux-low.h
+++ b/gdb/gdbserver/linux-low.h
@@ -379,6 +379,9 @@ void initialize_regsets_info (struct regsets_info *regsets_info);
void initialize_low_arch (void);
+void linux_set_pc_32bit (struct regcache *regcache, CORE_ADDR pc);
+CORE_ADDR linux_get_pc_32bit (struct regcache *regcache);
+
/* From thread-db.c */
int thread_db_init (void);
void thread_db_detach (struct process_info *);
diff --git a/gdb/gdbserver/linux-m32r-low.c b/gdb/gdbserver/linux-m32r-low.c
index f0431eb..39eb929 100644
--- a/gdb/gdbserver/linux-m32r-low.c
+++ b/gdb/gdbserver/linux-m32r-low.c
@@ -53,23 +53,6 @@ m32r_cannot_fetch_register (int regno)
return (regno >= m32r_num_regs);
}
-static CORE_ADDR
-m32r_get_pc (struct regcache *regcache)
-{
- unsigned long pc;
- collect_register_by_name (regcache, "pc", &pc);
- if (debug_threads)
- debug_printf ("stop pc is %08lx\n", pc);
- return pc;
-}
-
-static void
-m32r_set_pc (struct regcache *regcache, CORE_ADDR pc)
-{
- unsigned long newpc = pc;
- supply_register_by_name (regcache, "pc", &newpc);
-}
-
static const unsigned short m32r_breakpoint = 0x10f1;
#define m32r_breakpoint_len 2
@@ -135,8 +118,8 @@ struct linux_target_ops the_low_target = {
m32r_cannot_fetch_register,
m32r_cannot_store_register,
NULL, /* fetch_register */
- m32r_get_pc,
- m32r_set_pc,
+ linux_get_pc_32bit,
+ linux_set_pc_32bit,
NULL, /* breakpoint_from_pc */
m32r_sw_breakpoint_from_kind,
NULL,
diff --git a/gdb/gdbserver/linux-m68k-low.c b/gdb/gdbserver/linux-m68k-low.c
index bee21c7..df3d7c6 100644
--- a/gdb/gdbserver/linux-m68k-low.c
+++ b/gdb/gdbserver/linux-m68k-low.c
@@ -134,23 +134,6 @@ m68k_sw_breakpoint_from_kind (int kind, int *size)
return m68k_breakpoint;
}
-static CORE_ADDR
-m68k_get_pc (struct regcache *regcache)
-{
- unsigned long pc;
-
- collect_register_by_name (regcache, "pc", &pc);
- return pc;
-}
-
-static void
-m68k_set_pc (struct regcache *regcache, CORE_ADDR value)
-{
- unsigned long newpc = value;
-
- supply_register_by_name (regcache, "pc", &newpc);
-}
-
static int
m68k_breakpoint_at (CORE_ADDR pc)
{
@@ -222,8 +205,8 @@ struct linux_target_ops the_low_target = {
m68k_cannot_fetch_register,
m68k_cannot_store_register,
NULL, /* fetch_register */
- m68k_get_pc,
- m68k_set_pc,
+ linux_get_pc_32bit,
+ linux_set_pc_32bit,
NULL, /* breakpoint_kind_from_pc */
m68k_sw_breakpoint_from_kind,
NULL,
diff --git a/gdb/gdbserver/linux-nios2-low.c b/gdb/gdbserver/linux-nios2-low.c
index ba852ac..ea0ded1 100644
--- a/gdb/gdbserver/linux-nios2-low.c
+++ b/gdb/gdbserver/linux-nios2-low.c
@@ -95,28 +95,6 @@ nios2_cannot_store_register (int regno)
return 0;
}
-/* Implement the get_pc linux_target_ops method. */
-
-static CORE_ADDR
-nios2_get_pc (struct regcache *regcache)
-{
- union nios2_register pc;
-
- collect_register_by_name (regcache, "pc", pc.buf);
- return pc.reg32;
-}
-
-/* Implement the set_pc linux_target_ops method. */
-
-static void
-nios2_set_pc (struct regcache *regcache, CORE_ADDR pc)
-{
- union nios2_register newpc;
-
- newpc.reg32 = pc;
- supply_register_by_name (regcache, "pc", newpc.buf);
-}
-
/* Breakpoint support. Also see comments on nios2_breakpoint_from_pc
in nios2-tdep.c. */
@@ -263,8 +241,8 @@ struct linux_target_ops the_low_target =
nios2_cannot_fetch_register,
nios2_cannot_store_register,
NULL,
- nios2_get_pc,
- nios2_set_pc,
+ linux_get_pc_32bit,
+ linux_set_pc_32bit,
NULL, /* breakpoint_kind_from_pc */
nios2_sw_breakpoint_from_kind,
NULL, /* get_next_pcs */
diff --git a/gdb/gdbserver/linux-sh-low.c b/gdb/gdbserver/linux-sh-low.c
index 56f3406..38612e2 100644
--- a/gdb/gdbserver/linux-sh-low.c
+++ b/gdb/gdbserver/linux-sh-low.c
@@ -58,21 +58,6 @@ sh_cannot_fetch_register (int regno)
return 0;
}
-static CORE_ADDR
-sh_get_pc (struct regcache *regcache)
-{
- unsigned long pc;
- collect_register_by_name (regcache, "pc", &pc);
- return pc;
-}
-
-static void
-sh_set_pc (struct regcache *regcache, CORE_ADDR pc)
-{
- unsigned long newpc = pc;
- supply_register_by_name (regcache, "pc", &newpc);
-}
-
/* Correct in either endianness, obviously. */
static const unsigned short sh_breakpoint = 0xc3c3;
#define sh_breakpoint_len 2
@@ -163,8 +148,8 @@ struct linux_target_ops the_low_target = {
sh_cannot_fetch_register,
sh_cannot_store_register,
NULL, /* fetch_register */
- sh_get_pc,
- sh_set_pc,
+ linux_get_pc_32bit,
+ linux_set_pc_32bit,
NULL, /* breakpoint_kind_from_pc */
sh_sw_breakpoint_from_kind,
NULL,
diff --git a/gdb/gdbserver/linux-xtensa-low.c b/gdb/gdbserver/linux-xtensa-low.c
index 647dbf4..6e945ea 100644
--- a/gdb/gdbserver/linux-xtensa-low.c
+++ b/gdb/gdbserver/linux-xtensa-low.c
@@ -163,22 +163,6 @@ xtensa_sw_breakpoint_from_kind (int kind, int *size)
return xtensa_breakpoint;
}
-static CORE_ADDR
-xtensa_get_pc (struct regcache *regcache)
-{
- unsigned long pc;
-
- collect_register_by_name (regcache, "pc", &pc);
- return pc;
-}
-
-static void
-xtensa_set_pc (struct regcache *regcache, CORE_ADDR pc)
-{
- unsigned long newpc = pc;
- supply_register_by_name (regcache, "pc", &newpc);
-}
-
static int
xtensa_breakpoint_at (CORE_ADDR where)
{
@@ -249,8 +233,8 @@ struct linux_target_ops the_low_target = {
0,
0,
NULL, /* fetch_register */
- xtensa_get_pc,
- xtensa_set_pc,
+ linux_get_pc_32bit,
+ linux_set_pc_32bit,
NULL, /* breakpoint_kind_from_pc */
xtensa_sw_breakpoint_from_kind,
NULL,
--
1.9.1