public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 1/5] gdb: xtensa: clean up xtensa_default_isa initialization
  2017-02-22  2:09 [PATCH v2 0/5] xtensa: support call0 ABI native linux gdb and gdbserver Max Filippov
@ 2017-02-22  2:09 ` Max Filippov
  2017-02-22  2:09 ` [PATCH v2 2/5] gdb: gdbserver: xtensa: make C0_NREGS available Max Filippov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Max Filippov @ 2017-02-22  2:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Maxim Grigoriev, Woody LaRue, Marc Gauthier, Max Filippov

This fixes segfault in native gdb because isa is not initialized at the
point of call to xtensa_isa_maxlength.

gdb/
2017-02-21  Max Filippov  <jcmvbkbc@gmail.com>

	* xtensa-tdep.c (xtensa_scan_prologue, call0_analyze_prologue):
	Drop xtensa_default_isa initialization.
	(xtensa_gdbarch_init): Initialize xtensa_default_isa.
---
Changes v1->v2:
- clean up xtensa_default_isa initialization;
- move directory name up in the commit message.

 gdb/xtensa-tdep.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index 376f4c7..efbd5ab 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -1151,8 +1151,6 @@ xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
   if (start_addr == 0)
     return fp_regnum;
 
-  if (!xtensa_default_isa)
-    xtensa_default_isa = xtensa_isa_init (0, 0);
   isa = xtensa_default_isa;
   gdb_assert (XTENSA_ISA_BSZ >= xtensa_isa_maxlength (isa));
   ins = xtensa_insnbuf_alloc (isa);
@@ -2427,8 +2425,6 @@ call0_analyze_prologue (struct gdbarch *gdbarch,
   cache->call0 = 1;
   rtmp = (xtensa_c0reg_t*) alloca(nregs * sizeof(xtensa_c0reg_t));
 
-  if (!xtensa_default_isa)
-    xtensa_default_isa = xtensa_isa_init (0, 0);
   isa = xtensa_default_isa;
   gdb_assert (XTENSA_ISA_BSZ >= xtensa_isa_maxlength (isa));
   ins = xtensa_insnbuf_alloc (isa);
@@ -3186,6 +3182,9 @@ xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   DEBUGTRACE ("gdbarch_init()\n");
 
+  if (!xtensa_default_isa)
+    xtensa_default_isa = xtensa_isa_init (0, 0);
+
   /* We have to set the byte order before we call gdbarch_alloc.  */
   info.byte_order = XCHAL_HAVE_BE ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
 
-- 
2.1.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 4/5] gdbserver: xtensa: add call0 support
  2017-02-22  2:09 [PATCH v2 0/5] xtensa: support call0 ABI native linux gdb and gdbserver Max Filippov
  2017-02-22  2:09 ` [PATCH v2 1/5] gdb: xtensa: clean up xtensa_default_isa initialization Max Filippov
  2017-02-22  2:09 ` [PATCH v2 2/5] gdb: gdbserver: xtensa: make C0_NREGS available Max Filippov
@ 2017-02-22  2:09 ` Max Filippov
  2017-02-22  2:09 ` [PATCH v2 3/5] gdb: xtensa-linux: " Max Filippov
  2017-02-22  2:11 ` [PATCH v2 5/5] gdb: xtensa: fix test for privileged register number Max Filippov
  4 siblings, 0 replies; 6+ messages in thread
From: Max Filippov @ 2017-02-22  2:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Maxim Grigoriev, Woody LaRue, Marc Gauthier, Max Filippov

Correctly handle a0- registers on requests from remote gdb. This fixes

  'Register 1 is not available'

and subsequent assertion in the remote gdb connecting to the gdbserver:

  'findvar.c:291: internal-error: value_of_register_lazy:
    Assertion `frame_id_p(get_frame_id (frame))' failed.'

The register structure is the same for windowed and call0 ABIs because
currently linux kernel internally requires windowed registers, so they
are always present.

gdb/gdbserver/
2017-01-18  Max Filippov  <jcmvbkbc@gmail.com>

	* linux-xtensa-low.c (C0_NREGS): New definition.
	(xtensa_fill_gregset): Call collect_register for all registers in
	a0_regnum..a0_regnum + C0_NREGS range.
	(xtensa_store_gregset): Call supply_register for all registers in
	a0_regnum..a0_regnum + C0_NREGS range.
---
Changes v1->v2:
- add missing spaces to type casts;
- add parentheses to new conditions;
- move directory name up in the commit message.

 gdb/gdbserver/linux-xtensa-low.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/gdb/gdbserver/linux-xtensa-low.c b/gdb/gdbserver/linux-xtensa-low.c
index 98c0bf2..89efa05 100644
--- a/gdb/gdbserver/linux-xtensa-low.c
+++ b/gdb/gdbserver/linux-xtensa-low.c
@@ -45,6 +45,7 @@ xtensa_fill_gregset (struct regcache *regcache, void *buf)
   elf_greg_t* rset = (elf_greg_t*)buf;
   const struct target_desc *tdesc = regcache->tdesc;
   int ar0_regnum;
+  int a0_regnum;
   char *ptr;
   int i;
 
@@ -72,6 +73,17 @@ xtensa_fill_gregset (struct regcache *regcache, void *buf)
   collect_register_by_name (regcache, "ps", (char*)&rset[R_PS]);
   collect_register_by_name (regcache, "windowbase", (char*)&rset[R_WB]);
   collect_register_by_name (regcache, "windowstart", (char*)&rset[R_WS]);
+
+  a0_regnum = find_regno (tdesc, "a0");
+  ptr = (char *) &rset[R_A0 + 4 * rset[R_WB]];
+
+  for (i = a0_regnum; i < a0_regnum + C0_NREGS; i++)
+    {
+      if ((4 * rset[R_WB] + i - a0_regnum) == XCHAL_NUM_AREGS)
+	ptr = (char *) &rset[R_A0];
+      collect_register (regcache, i, ptr);
+      ptr += register_size (tdesc, i);
+    }
 }
 
 static void
@@ -80,6 +92,7 @@ xtensa_store_gregset (struct regcache *regcache, const void *buf)
   const elf_greg_t* rset = (const elf_greg_t*)buf;
   const struct target_desc *tdesc = regcache->tdesc;
   int ar0_regnum;
+  int a0_regnum;
   char *ptr;
   int i;
 
@@ -94,6 +107,17 @@ xtensa_store_gregset (struct regcache *regcache, const void *buf)
       ptr += register_size (tdesc, i);
     }
 
+  a0_regnum = find_regno (tdesc, "a0");
+  ptr = (char *) &rset[R_A0 + (4 * rset[R_WB]) % XCHAL_NUM_AREGS];
+
+  for (i = a0_regnum; i < a0_regnum + C0_NREGS; i++)
+    {
+      if ((4 * rset[R_WB] + i - a0_regnum) == XCHAL_NUM_AREGS)
+	ptr = (char *) &rset[R_A0];
+      supply_register (regcache, i, ptr);
+      ptr += register_size (tdesc, i);
+    }
+
   /* Loop registers, if hardware has it.  */
 
 #if XCHAL_HAVE_LOOPS
-- 
2.1.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 0/5] xtensa: support call0 ABI native linux gdb and gdbserver
@ 2017-02-22  2:09 Max Filippov
  2017-02-22  2:09 ` [PATCH v2 1/5] gdb: xtensa: clean up xtensa_default_isa initialization Max Filippov
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Max Filippov @ 2017-02-22  2:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Maxim Grigoriev, Woody LaRue, Marc Gauthier, Max Filippov

Hello,

this series adds call0 ABI support to native xtensa-linux gdb and gdbserver
ports.

Changes v1->v2:
- clean up xtensa_default_isa initialization;
- move C0_NREGS definition to gdb/arch/xtensa.h;
- add missing spaces to type casts;
- add parentheses to new conditions;
- fix privileged register number test for call0 ABI;
- move directory name up in the commit message.

Max Filippov (5):
  gdb: xtensa: clean up xtensa_default_isa initialization
  gdb: gdbserver: xtensa: make C0_NREGS available
  gdb: xtensa-linux: add call0 support
  gdbserver: xtensa: add call0 support
  gdb: xtensa: fix test for privileged register number

 gdb/arch/xtensa.h                |  2 ++
 gdb/gdbserver/linux-xtensa-low.c | 24 ++++++++++++++++++++++++
 gdb/xtensa-linux-nat.c           | 28 ++++++++++++++++++++++++++++
 gdb/xtensa-tdep.c                | 11 +++++------
 4 files changed, 59 insertions(+), 6 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 3/5] gdb: xtensa-linux: add call0 support
  2017-02-22  2:09 [PATCH v2 0/5] xtensa: support call0 ABI native linux gdb and gdbserver Max Filippov
                   ` (2 preceding siblings ...)
  2017-02-22  2:09 ` [PATCH v2 4/5] gdbserver: xtensa: add call0 support Max Filippov
@ 2017-02-22  2:09 ` Max Filippov
  2017-02-22  2:11 ` [PATCH v2 5/5] gdb: xtensa: fix test for privileged register number Max Filippov
  4 siblings, 0 replies; 6+ messages in thread
From: Max Filippov @ 2017-02-22  2:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Maxim Grigoriev, Woody LaRue, Marc Gauthier, Max Filippov

Correctly handle a0- registers. This allows debugging call0 code in
linux natively.
The register structure is the same for windowed and call0 ABIs because
currently linux kernel internally requires windowed registers, so they are
always present.

gdb/
2017-01-18  Max Filippov  <jcmvbkbc@gmail.com>

	* xtensa-linux-nat.c (C0_NREGS): New definition.
	(fill_gregset): Call regcache_raw_collect for a single specified
	register or for all registers in a0_base..a0_base + C0_NREGS
	range.
	(supply_gregset_reg): Call regcache_raw_supply for a single
	specified register or for all registers in a0_base..a0_base +
	C0_NREGS range.
---
Changes v1->v2:
- move directory name up in the commit message.

 gdb/xtensa-linux-nat.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/gdb/xtensa-linux-nat.c b/gdb/xtensa-linux-nat.c
index afe15f6..e5a2d84 100644
--- a/gdb/xtensa-linux-nat.c
+++ b/gdb/xtensa-linux-nat.c
@@ -94,6 +94,20 @@ fill_gregset (const struct regcache *regcache,
 			      gdbarch_tdep (gdbarch)->ar_base + i,
 			      &regs->ar[i]);
     }
+  if (regnum >= gdbarch_tdep (gdbarch)->a0_base
+      && regnum < gdbarch_tdep (gdbarch)->a0_base + C0_NREGS)
+    regcache_raw_collect (regcache, regnum,
+			  &regs->ar[(4 * regs->windowbase + regnum
+				     - gdbarch_tdep (gdbarch)->a0_base)
+			  % gdbarch_tdep (gdbarch)->num_aregs]);
+  else if (regnum == -1)
+    {
+      for (i = 0; i < C0_NREGS; ++i)
+	regcache_raw_collect (regcache,
+			      gdbarch_tdep (gdbarch)->a0_base + i,
+			      &regs->ar[(4 * regs->windowbase + i)
+			      % gdbarch_tdep (gdbarch)->num_aregs]);
+    }
 }
 
 static void
@@ -146,6 +160,20 @@ supply_gregset_reg (struct regcache *regcache,
 			      gdbarch_tdep (gdbarch)->ar_base + i,
 			      &regs->ar[i]);
     }
+  if (regnum >= gdbarch_tdep (gdbarch)->a0_base
+      && regnum < gdbarch_tdep (gdbarch)->a0_base + C0_NREGS)
+    regcache_raw_supply (regcache, regnum,
+			 &regs->ar[(4 * regs->windowbase + regnum
+				    - gdbarch_tdep (gdbarch)->a0_base)
+			 % gdbarch_tdep (gdbarch)->num_aregs]);
+  else if (regnum == -1)
+    {
+      for (i = 0; i < C0_NREGS; ++i)
+	regcache_raw_supply (regcache,
+			     gdbarch_tdep (gdbarch)->a0_base + i,
+			     &regs->ar[(4 * regs->windowbase + i)
+			     % gdbarch_tdep (gdbarch)->num_aregs]);
+    }
 }
 
 void
-- 
2.1.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 2/5] gdb: gdbserver: xtensa: make C0_NREGS available
  2017-02-22  2:09 [PATCH v2 0/5] xtensa: support call0 ABI native linux gdb and gdbserver Max Filippov
  2017-02-22  2:09 ` [PATCH v2 1/5] gdb: xtensa: clean up xtensa_default_isa initialization Max Filippov
@ 2017-02-22  2:09 ` Max Filippov
  2017-02-22  2:09 ` [PATCH v2 4/5] gdbserver: xtensa: add call0 support Max Filippov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Max Filippov @ 2017-02-22  2:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Maxim Grigoriev, Woody LaRue, Marc Gauthier, Max Filippov

Both gdb and gdbserver need this definition to properly work with call0
ABI. Make it available to both.

gdb/
2017-02-21  Max Filippov  <jcmvbkbc@gmail.com>

	* arch/xtensa.h (C0_NREGS): Add definition.
	* xtensa-tdep.c (C0_NREGS): Remove definition.
---
Changes v1->v2:
- new patch.

 gdb/arch/xtensa.h | 2 ++
 gdb/xtensa-tdep.c | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/arch/xtensa.h b/gdb/arch/xtensa.h
index 2c328c8..63bbec6 100644
--- a/gdb/arch/xtensa.h
+++ b/gdb/arch/xtensa.h
@@ -43,4 +43,6 @@ typedef struct
 #define XTENSA_ELF_NGREG (sizeof (xtensa_elf_gregset_t) \
 			  / sizeof (xtensa_elf_greg_t))
 
+#define C0_NREGS   16	/* Number of A-registers to track in call0 ABI.  */
+
 #endif
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index efbd5ab..0000155 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -942,7 +942,6 @@ typedef struct xtensa_windowed_frame_cache
 
 #define C0_MAXOPDS  3	/* Maximum number of operands for prologue
 			   analysis.  */
-#define C0_NREGS   16	/* Number of A-registers to track.  */
 #define C0_CLESV   12	/* Callee-saved registers are here and up.  */
 #define C0_SP	    1	/* Register used as SP.  */
 #define C0_FP	   15	/* Register used as FP.  */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 5/5] gdb: xtensa: fix test for privileged register number
  2017-02-22  2:09 [PATCH v2 0/5] xtensa: support call0 ABI native linux gdb and gdbserver Max Filippov
                   ` (3 preceding siblings ...)
  2017-02-22  2:09 ` [PATCH v2 3/5] gdb: xtensa-linux: " Max Filippov
@ 2017-02-22  2:11 ` Max Filippov
  4 siblings, 0 replies; 6+ messages in thread
From: Max Filippov @ 2017-02-22  2:11 UTC (permalink / raw)
  To: gdb-patches; +Cc: Maxim Grigoriev, Woody LaRue, Marc Gauthier, Max Filippov

There are no a0-a15 pseudoregisters at the top of the register set in
call0 registers layout. All registers above gdbarch_num_regs (gdbarch)
are privileged. Treat them as such. This fixes the following gdb
assertion seen when 'finish' command is invoked:

  regcache.c:649: internal-error: register_status
  regcache_raw_read(regcache*, int, gdb_byte*):
  Assertion `regnum >= 0 && regnum < regcache->descr->nr_raw_registers'
  failed.

gdb/
2017-02-21  Max Filippov  <jcmvbkbc@gmail.com>

	* xtensa-tdep.c (xtensa_pseudo_register_read): Treat all
	registers above gdbarch_num_regs (gdbarch) as privileged in
	call0 ABI.
---
Changes v1->v2:
- new patch.

 gdb/xtensa-tdep.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index 0000155..2338ac1 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -578,7 +578,8 @@ xtensa_pseudo_register_read (struct gdbarch *gdbarch,
   /* We have to find out how to deal with priveleged registers.
      Let's treat them as pseudo-registers, but we cannot read/write them.  */
      
-  else if (regnum < gdbarch_tdep (gdbarch)->a0_base)
+  else if (gdbarch_tdep (gdbarch)->call_abi == CallAbiCall0Only
+	   || regnum < gdbarch_tdep (gdbarch)->a0_base)
     {
       buffer[0] = (gdb_byte)0;
       buffer[1] = (gdb_byte)0;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-02-22  2:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-22  2:09 [PATCH v2 0/5] xtensa: support call0 ABI native linux gdb and gdbserver Max Filippov
2017-02-22  2:09 ` [PATCH v2 1/5] gdb: xtensa: clean up xtensa_default_isa initialization Max Filippov
2017-02-22  2:09 ` [PATCH v2 2/5] gdb: gdbserver: xtensa: make C0_NREGS available Max Filippov
2017-02-22  2:09 ` [PATCH v2 4/5] gdbserver: xtensa: add call0 support Max Filippov
2017-02-22  2:09 ` [PATCH v2 3/5] gdb: xtensa-linux: " Max Filippov
2017-02-22  2:11 ` [PATCH v2 5/5] gdb: xtensa: fix test for privileged register number Max Filippov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).