gdbserver/linux-low: start turning linux target ops into methods

This is the beginning of a series of patches that convert the linux
low targets into classes derived from linux_process_target.  At the
end of the series we obtain a class hierarchy that looks like this:

process_stratum_target
^
|
|-- linux_process_target
    ^
    |
    |-- x86_target (defined in linux-x86-low)
    |-- aarch64_target (defined in linux-aarch64-low)
    |-- ppc_target (defined in linux-ppc-low)
    |-- ...

In several cases, linux_process_target simply forwards a target op
request to a corresponding linux_target_ops function.  For these
cases, the definition in linux_process_target will be removed and the
definition will be left to the deriving linux low target class; using
inheritance provides a nice and natural, object-oriented
simplification in these cases.

The series converts linux_target_ops into protected methods of
linux_process_target one by one.  Throughout the series, based on the
needs, static functions defined in linux-low.cc are converted to
private methods of linux_process_target as well.  This is done either
as separate patches or as integrated into a patch that convert a
particular linux_target_op into a method.

The series ends with the patch titled "gdbserver/linux-low: delete
'linux_target_ops' and 'the_low_target'".

Built and regression-tested on x86_64-linux.  The following linux low
targets have been built (but not tested) via cross-compilation:
aarch64, arm, m68k, mips, ppc, riscv, s390, sh, sparc.  The other
targets (bfin, cris, crisv32, ia64, m32r, nios2, tic6x, tile, xtensa)
were neither built nor tested.

gdbserver/ChangeLog:
2020-04-02  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* linux-low.h (the_linux_target): New extern declaration.
	* linux-low.cc (initialize_low): Use 'the_linux_target' to set
	'the_target'.
	(the_linux_target): Remove.
	* linux-x86-low.cc (class x86_target): New class.
	(the_x86_target): New static object.
	(the_linux_target): Define as pointer to the_x86_target.
	* linux-aarch64-low.cc (class aarch64_target): New class.
	(the_aarch64_target): New static object.
	(the_linux_target): Define as pointer to the_aarch64_target.
	* linux-arm-low.cc (class arm_target): New class.
	(the_arm_target): New static object.
	(the_linux_target): Define as pointer to the_arm_target.
	* linux-bfin-low.cc (class bfin_target): New class.
	(the_bfin_target): New static object.
	(the_linux_target): Define as pointer to the_bfin_target.
	* linux-cris-low.cc (class cris_target): New class.
	(the_cris_target): New static object.
	(the_linux_target): Define as pointer to the_cris_target.
	* linux-crisv32-low.cc (class crisv32_target): New class.
	(the_crisv32_target): New static object.
	(the_linux_target): Define as pointer to the_crisv32_target.
	* linux-ia64-low.cc (class ia64_target): New class.
	(the_ia64_target): New static object.
	(the_linux_target): Define as pointer to the_ia64_target.
	* linux-m32r-low.cc (class m32r_target): New class.
	(the_m32r_target): New static object.
	(the_linux_target): Define as pointer to the_m32r_target.
	* linux-m68k-low.cc (class m68k_target): New class.
	(the_m68k_target): New static object.
	(the_linux_target): Define as pointer to the_m68k_target.
	* linux-mips-low.cc (class mips_target): New class.
	(the_mips_target): New static object.
	(the_linux_target): Define as pointer to the_mips_target.
	* linux-nios2-low.cc (class nios2_target): New class.
	(the_nios2_target): New static object.
	(the_linux_target): Define as pointer to the_nios2_target.
	* linux-ppc-low.cc (class ppc_target): New class.
	(the_ppc_target): New static object.
	(the_linux_target): Define as pointer to the_ppc_target.
	* linux-riscv-low.cc (class riscv_target): New class.
	(the_riscv_target): New static object.
	(the_linux_target): Define as pointer to the_riscv_target.
	* linux-s390-low.cc (class s390_target): New class.
	(the_s390_target): New static object.
	(the_linux_target): Define as pointer to the_s390_target.
	* linux-sh-low.cc (class sh_target): New class.
	(the_sh_target): New static object.
	(the_linux_target): Define as pointer to the_sh_target.
	* linux-sparc-low.cc (class sparc_target): New class.
	(the_sparc_target): New static object.
	(the_linux_target): Define as pointer to the_sparc_target.
	* linux-tic6x-low.cc (class tic6x_target): New class.
	(the_tic6x_target): New static object.
	(the_linux_target): Define as pointer to the_tic6x_target.
	* linux-tile-low.cc (class tile_target): New class.
	(the_tile_target): New static object.
	(the_linux_target): Define as pointer to the_tile_target.
	* linux-xtensa-low.cc (class xtensa_target): New class.
	(the_xtensa_target): New static object.
	(the_linux_target): Define as pointer to the_xtensa_target.
This commit is contained in:
Tankut Baris Aktemur 2020-04-02 15:11:23 +02:00
parent d16f3f6c70
commit ef0478f611
22 changed files with 374 additions and 5 deletions

View File

@ -1,3 +1,67 @@
2020-04-02 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* linux-low.h (the_linux_target): New extern declaration.
* linux-low.cc (initialize_low): Use 'the_linux_target' to set
'the_target'.
(the_linux_target): Remove.
* linux-x86-low.cc (class x86_target): New class.
(the_x86_target): New static object.
(the_linux_target): Define as pointer to the_x86_target.
* linux-aarch64-low.cc (class aarch64_target): New class.
(the_aarch64_target): New static object.
(the_linux_target): Define as pointer to the_aarch64_target.
* linux-arm-low.cc (class arm_target): New class.
(the_arm_target): New static object.
(the_linux_target): Define as pointer to the_arm_target.
* linux-bfin-low.cc (class bfin_target): New class.
(the_bfin_target): New static object.
(the_linux_target): Define as pointer to the_bfin_target.
* linux-cris-low.cc (class cris_target): New class.
(the_cris_target): New static object.
(the_linux_target): Define as pointer to the_cris_target.
* linux-crisv32-low.cc (class crisv32_target): New class.
(the_crisv32_target): New static object.
(the_linux_target): Define as pointer to the_crisv32_target.
* linux-ia64-low.cc (class ia64_target): New class.
(the_ia64_target): New static object.
(the_linux_target): Define as pointer to the_ia64_target.
* linux-m32r-low.cc (class m32r_target): New class.
(the_m32r_target): New static object.
(the_linux_target): Define as pointer to the_m32r_target.
* linux-m68k-low.cc (class m68k_target): New class.
(the_m68k_target): New static object.
(the_linux_target): Define as pointer to the_m68k_target.
* linux-mips-low.cc (class mips_target): New class.
(the_mips_target): New static object.
(the_linux_target): Define as pointer to the_mips_target.
* linux-nios2-low.cc (class nios2_target): New class.
(the_nios2_target): New static object.
(the_linux_target): Define as pointer to the_nios2_target.
* linux-ppc-low.cc (class ppc_target): New class.
(the_ppc_target): New static object.
(the_linux_target): Define as pointer to the_ppc_target.
* linux-riscv-low.cc (class riscv_target): New class.
(the_riscv_target): New static object.
(the_linux_target): Define as pointer to the_riscv_target.
* linux-s390-low.cc (class s390_target): New class.
(the_s390_target): New static object.
(the_linux_target): Define as pointer to the_s390_target.
* linux-sh-low.cc (class sh_target): New class.
(the_sh_target): New static object.
(the_linux_target): Define as pointer to the_sh_target.
* linux-sparc-low.cc (class sparc_target): New class.
(the_sparc_target): New static object.
(the_linux_target): Define as pointer to the_sparc_target.
* linux-tic6x-low.cc (class tic6x_target): New class.
(the_tic6x_target): New static object.
(the_linux_target): Define as pointer to the_tic6x_target.
* linux-tile-low.cc (class tile_target): New class.
(the_tile_target): New static object.
(the_linux_target): Define as pointer to the_tile_target.
* linux-xtensa-low.cc (class xtensa_target): New class.
(the_xtensa_target): New static object.
(the_linux_target): Define as pointer to the_xtensa_target.
2020-04-02 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Turn some static functions in linux-low.cc into private methods of

View File

@ -49,6 +49,18 @@
#include <sys/reg.h>
#endif
/* Linux target op definitions for the AArch64 architecture. */
class aarch64_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static aarch64_target the_aarch64_target;
/* Per-process arch-specific data we want to keep. */
struct arch_process_info
@ -3088,6 +3100,10 @@ struct linux_target_ops the_low_target =
aarch64_get_syscall_trapinfo,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_aarch64_target;
void
initialize_low_arch (void)
{

View File

@ -54,6 +54,18 @@
#define PTRACE_SETHBPREGS 30
#endif
/* Linux target op definitions for the ARM architecture. */
class arm_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static arm_target the_arm_target;
/* Information describing the hardware breakpoint capabilities. */
static struct
{
@ -1044,6 +1056,10 @@ struct linux_target_ops the_low_target = {
arm_get_syscall_trapinfo,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_arm_target;
void
initialize_low_arch (void)
{

View File

@ -23,6 +23,18 @@
#include "linux-low.h"
#include <asm/ptrace.h>
/* Linux target op definitions for the BFIN architecture. */
class bfin_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static bfin_target the_bfin_target;
/* Defined in auto-generated file reg-bfin.c. */
void init_registers_bfin (void);
extern const struct target_desc *tdesc_bfin;
@ -151,6 +163,9 @@ struct linux_target_ops the_low_target = {
bfin_supports_hardware_single_step,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_bfin_target;
void
initialize_low_arch (void)

View File

@ -20,6 +20,18 @@
#include "linux-low.h"
#include "nat/gdb_ptrace.h"
/* Linux target op definitions for the CRIS architecture. */
class cris_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static cris_target the_cris_target;
/* Defined in auto-generated file reg-cris.c. */
void init_registers_cris (void);
extern const struct target_desc *tdesc_cris;
@ -125,6 +137,10 @@ struct linux_target_ops the_low_target = {
cris_breakpoint_at,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_cris_target;
void
initialize_low_arch (void)
{

View File

@ -20,6 +20,18 @@
#include "linux-low.h"
#include "nat/gdb_ptrace.h"
/* Linux target op definitions for the CRIS architecture. */
class crisv32_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static crisv32_target the_crisv32_target;
/* Defined in auto-generated file reg-crisv32.c. */
void init_registers_crisv32 (void);
extern const struct target_desc *tdesc_crisv32;
@ -431,6 +443,10 @@ struct linux_target_ops the_low_target = {
cris_supports_hardware_single_step,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_crisv32_target;
void
initialize_low_arch (void)
{

View File

@ -23,6 +23,18 @@
#include <sys/reg.h>
#endif
/* Linux target op definitions for the IA64 architecture. */
class ia64_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static ia64_target the_ia64_target;
/* Defined in auto-generated file reg-ia64.c. */
void init_registers_ia64 (void);
extern const struct target_desc *tdesc_ia64;
@ -353,6 +365,10 @@ struct linux_target_ops the_low_target = {
ia64_fetch_register,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_ia64_target;
void
initialize_low_arch (void)
{

View File

@ -7444,10 +7444,6 @@ linux_get_hwcap2 (int wordsize)
return hwcap2;
}
/* The linux target ops object. */
static linux_process_target the_linux_target;
#ifdef HAVE_LINUX_REGSETS
void
initialize_regsets_info (struct regsets_info *info)
@ -7465,7 +7461,7 @@ initialize_low (void)
struct sigaction sigchld_action;
memset (&sigchld_action, 0, sizeof (sigchld_action));
set_target_ops (&the_linux_target);
set_target_ops (the_linux_target);
linux_ptrace_init_warnings ();
linux_proc_init_warnings ();

View File

@ -563,8 +563,13 @@ private:
/* Move THREAD out of the jump pad. */
void move_out_of_jump_pad (thread_info *thread);
protected:
/* The architecture-specific "low" methods are listed below. */
};
extern linux_process_target *the_linux_target;
#define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
#define get_lwp_thread(lwp) ((lwp)->thread)

View File

@ -23,6 +23,18 @@
#include <sys/reg.h>
#endif
/* Linux target op definitions for the m32r architecture. */
class m32r_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static m32r_target the_m32r_target;
/* Defined in auto-generated file reg-m32r.c. */
void init_registers_m32r (void);
extern const struct target_desc *tdesc_m32r;
@ -150,6 +162,10 @@ struct linux_target_ops the_low_target = {
m32r_supports_hardware_single_step,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_m32r_target;
void
initialize_low_arch (void)
{

View File

@ -19,6 +19,18 @@
#include "server.h"
#include "linux-low.h"
/* Linux target op definitions for the m68k architecture. */
class m68k_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static m68k_target the_m68k_target;
/* Defined in auto-generated file reg-m68k.c. */
void init_registers_m68k (void);
extern const struct target_desc *tdesc_m68k;
@ -245,6 +257,10 @@ struct linux_target_ops the_low_target = {
m68k_supports_hardware_single_step,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_m68k_target;
void
initialize_low_arch (void)
{

View File

@ -25,6 +25,18 @@
#include "nat/mips-linux-watch.h"
#include "gdb_proc_service.h"
/* Linux target op definitions for the MIPS architecture. */
class mips_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static mips_target the_mips_target;
/* Defined in auto-generated file mips-linux.c. */
void init_registers_mips_linux (void);
extern const struct target_desc *tdesc_mips_linux;
@ -965,6 +977,10 @@ struct linux_target_ops the_low_target = {
mips_linux_prepare_to_resume
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_mips_target;
void
initialize_low_arch (void)
{

View File

@ -31,6 +31,18 @@
#define PTRACE_GET_THREAD_AREA 25
#endif
/* Linux target op definitions for the NIOS II architecture. */
class nios2_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static nios2_target the_nios2_target;
/* The following definition must agree with the number of registers
defined in "struct user_regs" in GLIBC
(sysdeps/unix/sysv/linux/nios2/sys/user.h), and also with
@ -250,6 +262,10 @@ struct linux_target_ops the_low_target =
nios2_breakpoint_at,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_nios2_target;
void
initialize_low_arch (void)
{

View File

@ -44,6 +44,18 @@
#define PPC_LI(insn) (PPC_SEXT (PPC_FIELD (insn, 6, 24), 24) << 2)
#define PPC_BD(insn) (PPC_SEXT (PPC_FIELD (insn, 16, 14), 14) << 2)
/* Linux target op definitions for the PowerPC architecture. */
class ppc_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static ppc_target the_ppc_target;
/* Holds the AT_HWCAP auxv entry. */
static unsigned long ppc_hwcap;
@ -3410,6 +3422,10 @@ struct linux_target_ops the_low_target = {
ppc_get_ipa_tdesc_idx,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_ppc_target;
void
initialize_low_arch (void)
{

View File

@ -30,6 +30,18 @@
# define NFPREG 33
#endif
/* Linux target op definitions for the RISC-V architecture. */
class riscv_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static riscv_target the_riscv_target;
/* Implementation of linux_target_ops method "arch_setup". */
static void
@ -270,6 +282,10 @@ struct linux_target_ops the_low_target =
riscv_breakpoint_at,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_riscv_target;
/* Initialize the RISC-V/Linux target. */
void

View File

@ -51,6 +51,18 @@
#define s390_num_regs 52
/* Linux target op definitions for the S/390 architecture. */
class s390_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static s390_target the_s390_target;
static int s390_regmap[] = {
PT_PSWMASK, PT_PSWADDR,
@ -2830,6 +2842,10 @@ struct linux_target_ops the_low_target = {
s390_get_ipa_tdesc_idx,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_s390_target;
void
initialize_low_arch (void)
{

View File

@ -19,6 +19,18 @@
#include "server.h"
#include "linux-low.h"
/* Linux target op definitions for the SH architecture. */
class sh_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static sh_target the_sh_target;
/* Defined in auto-generated file reg-sh.c. */
void init_registers_sh (void);
extern const struct target_desc *tdesc_sh;
@ -180,6 +192,10 @@ struct linux_target_ops the_low_target = {
sh_supports_hardware_single_step,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_sh_target;
void
initialize_low_arch (void)
{

View File

@ -42,6 +42,18 @@
#define sparc_num_regs \
(SPARC_R_REGS_NUM + SPARC_F_REGS_NUM + SPARC_CONTROL_REGS_NUM)
/* Linux target op definitions for the SPARC architecture. */
class sparc_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static sparc_target the_sparc_target;
/* Each offset is multiplied by 8, because of the register size.
These offsets apply to the buffer sent/filled by ptrace.
Additionally, the array elements order corresponds to the .dat file, and the
@ -316,6 +328,10 @@ struct linux_target_ops the_low_target = {
NULL, NULL
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_sparc_target;
void
initialize_low_arch (void)
{

View File

@ -38,6 +38,18 @@
#include <asm/ptrace.h>
/* Linux target op definitions for the TI C6x architecture. */
class tic6x_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static tic6x_target the_tic6x_target;
/* Defined in auto-generated file tic6x-c64xp-linux.c. */
void init_registers_tic6x_c64xp_linux (void);
extern const struct target_desc *tdesc_tic6x_c64xp_linux;
@ -439,6 +451,10 @@ tic6x_tdesc_test ()
}
#endif
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_tic6x_target;
void
initialize_low_arch (void)
{

View File

@ -23,6 +23,18 @@
#include <arch/abi.h>
#include "nat/gdb_ptrace.h"
/* Linux target op definitions for the TILE-Gx architecture. */
class tile_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static tile_target the_tile_target;
/* Defined in auto-generated file reg-tilegx.c. */
void init_registers_tilegx (void);
extern const struct target_desc *tdesc_tilegx;
@ -212,6 +224,10 @@ struct linux_target_ops the_low_target =
tile_supports_hardware_single_step,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_tile_target;
void
initialize_low_arch (void)
{

View File

@ -92,6 +92,20 @@ static const char *xmltarget_amd64_linux_no_xml = "@<target>\
#define ARCH_GET_GS 0x1004
#endif
/* Linux target op definitions for the x86 architecture.
This is initialized assuming an amd64 target.
'low_arch_setup' will correct it for i386 or amd64 targets. */
class x86_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static x86_target the_x86_target;
/* Per-process arch-specific data we want to keep. */
struct arch_process_info
@ -2901,6 +2915,10 @@ struct linux_target_ops the_low_target =
x86_get_ipa_tdesc_idx,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_x86_target;
void
initialize_low_arch (void)
{

View File

@ -20,6 +20,18 @@
#include "server.h"
#include "linux-low.h"
/* Linux target op definitions for the Xtensa architecture. */
class xtensa_target : public linux_process_target
{
public:
};
/* The singleton target ops object. */
static xtensa_target the_xtensa_target;
/* Defined in auto-generated file reg-xtensa.c. */
void init_registers_xtensa (void);
extern const struct target_desc *tdesc_xtensa;
@ -304,6 +316,9 @@ struct linux_target_ops the_low_target = {
xtensa_supports_hardware_single_step,
};
/* The linux target ops object. */
linux_process_target *the_linux_target = &the_xtensa_target;
void
initialize_low_arch (void)