gdb: xtensa: make tdep and linux-nat dynamically configurable

This commit is contained in:
Alexey Lapshin
2022-11-02 16:37:13 +04:00
parent 9cb3fd7ce6
commit e0fe2843da
3 changed files with 35 additions and 9 deletions

View File

@ -62,7 +62,7 @@ const xtensa_mask_t xtensa_mask15 = { 1, xtensa_submask15 };
/* Register map. */
static xtensa_register_t rmap[] =
xtensa_register_t rmap[] =
{
/* idx ofs bi sz al targno flags cp typ group name */
XTREG( 0, 0,32, 4, 4,0x0020,0x0006,-2, 9,0x0100,pc, 0,0,0,0,0,0)
@ -212,5 +212,3 @@ static xtensa_register_t rmap[] =
0,0,&xtensa_mask15,0,0,0)
XTREG_END
};
xtensa_gdbarch_tdep xtensa_tdep (rmap);

View File

@ -36,6 +36,18 @@
#include "gregset.h"
#include "xtensa-tdep.h"
#include "xtensa-dynconfig.h"
static xtensa_regtable_t *xtensa_config_get_regmap_table (void)
{
static xtensa_regtable_t *regtable;
if (!regtable)
regtable = (xtensa_regtable_t *) xtensa_load_config
("xtensa_regmap_table", &xtensa_regmap_table);
return regtable;
}
/* Defines ps_err_e, struct ps_prochandle. */
#include "gdb_proc_service.h"
@ -256,7 +268,7 @@ fetch_xtregs (struct regcache *regcache, int regnum)
if (ptrace (PTRACE_GETXTREGS, tid, 0, (long)&xtregs) < 0)
perror_with_name (_("Couldn't get extended registers"));
for (ptr = xtensa_regmap_table; ptr->name; ptr++)
for (ptr = xtensa_config_get_regmap_table (); ptr->name; ptr++)
if (regnum == ptr->gdb_regnum || regnum == -1)
regcache->raw_supply (ptr->gdb_regnum, xtregs + ptr->ptrace_offset);
}
@ -271,7 +283,7 @@ store_xtregs (struct regcache *regcache, int regnum)
if (ptrace (PTRACE_GETXTREGS, tid, 0, (long)&xtregs) < 0)
perror_with_name (_("Couldn't get extended registers"));
for (ptr = xtensa_regmap_table; ptr->name; ptr++)
for (ptr = xtensa_config_get_regmap_table (); ptr->name; ptr++)
if (regnum == ptr->gdb_regnum || regnum == -1)
regcache->raw_collect (ptr->gdb_regnum, xtregs + ptr->ptrace_offset);
@ -337,7 +349,7 @@ _initialize_xtensa_linux_nat ()
/* Calculate the number range for extended registers. */
xtreg_lo = 1000000000;
xtreg_high = -1;
for (ptr = xtensa_regmap_table; ptr->name; ptr++)
for (ptr = xtensa_config_get_regmap_table (); ptr->name; ptr++)
{
if (ptr->gdb_regnum < xtreg_lo)
xtreg_lo = ptr->gdb_regnum;

View File

@ -42,6 +42,7 @@
#include "xtensa-isa.h"
#include "xtensa-tdep.h"
#include "xtensa-config.h"
#include "xtensa-dynconfig.h"
#include <algorithm>
@ -3143,9 +3144,24 @@ xtensa_derive_tdep (xtensa_gdbarch_tdep *tdep)
tdep->max_register_virtual_size = max_size;
}
/* Module "constructor" function. */
static xtensa_gdbarch_tdep *xtensa_config_get_tdep (void)
{
extern xtensa_register_t *rmap;
static xtensa_gdbarch_tdep tdep = xtensa_gdbarch_tdep (rmap);
static int init;
extern xtensa_gdbarch_tdep xtensa_tdep;
if (!init)
{
xtensa_register_t *regmap =
(xtensa_register_t *) xtensa_load_config ("rmap", rmap);
tdep = xtensa_gdbarch_tdep (regmap);
init = 1;
}
return &tdep;
}
/* Module "constructor" function. */
static struct gdbarch *
xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
@ -3160,7 +3176,7 @@ xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
/* We have to set the byte order before we call gdbarch_alloc. */
info.byte_order = XCHAL_HAVE_BE ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
xtensa_gdbarch_tdep *tdep = &xtensa_tdep;
xtensa_gdbarch_tdep *tdep = xtensa_config_get_tdep ();
gdbarch = gdbarch_alloc (&info, tdep);
xtensa_derive_tdep (tdep);