public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 3/4] Consistently use fprintf_filtered when displaying MIPS registers.
  2017-04-25 21:00 [PATCH v2 0/4] Cleanups for MIPS registers (mostly FreeBSD-specific) John Baldwin
@ 2017-04-25 21:00 ` John Baldwin
  2017-04-25 21:00 ` [PATCH v2 1/4] Cleanups to FreeBSD/mips native register operations John Baldwin
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: John Baldwin @ 2017-04-25 21:00 UTC (permalink / raw)
  To: gdb-patches

One line was using printf_filtered instead of fprintf_filtered
to the requested file.

gdb/ChangeLog:

	* mips-tdep.c (print_gp_register_row): Replace printf_filtered
	with fprintf_filtered.
---
 gdb/ChangeLog   | 5 +++++
 gdb/mips-tdep.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 10023d20ae..fcf0637245 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2017-04-25  John Baldwin  <jhb@FreeBSD.org>
 
+	* mips-tdep.c (print_gp_register_row): Replace printf_filtered
+	with fprintf_filtered.
+
+2017-04-25  John Baldwin  <jhb@FreeBSD.org>
+
 	* mips-fbsd-tdep.c (MIPS_PC_REGNUM): Remove.
 	(MIPS_FP0_REGNUM): Remove.
 	(MIPS_FSR_REGNUM): Remove.
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 45d1d731b0..2364c2efdc 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -6539,7 +6539,7 @@ print_gp_register_row (struct ui_file *file, struct frame_info *frame,
       for (byte = 0;
 	   byte < (mips_abi_regsize (gdbarch)
 		   - register_size (gdbarch, regnum)); byte++)
-	printf_filtered ("  ");
+	fprintf_filtered (file, "  ");
       /* Now print the register value in hex, endian order.  */
       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
 	for (byte =
-- 
2.11.0

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

* [PATCH v2 1/4] Cleanups to FreeBSD/mips native register operations.
  2017-04-25 21:00 [PATCH v2 0/4] Cleanups for MIPS registers (mostly FreeBSD-specific) John Baldwin
  2017-04-25 21:00 ` [PATCH v2 3/4] Consistently use fprintf_filtered when displaying MIPS registers John Baldwin
@ 2017-04-25 21:00 ` John Baldwin
  2017-04-25 21:00 ` [PATCH v2 2/4] Use mips_regnum instead of constants for FreeBSD/mips " John Baldwin
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: John Baldwin @ 2017-04-25 21:00 UTC (permalink / raw)
  To: gdb-patches

Compare against the "raw" PC register number instead of the cooked
register number when determining if a register was handled by
PT_GETREGS.  Previously the register fetch/store operations only tried
PT_GETREGS to fetch any individual register.  The result was that
fetching or storing an individual register not covered by PT_GETREGS
(such as floating point registers) did not work.

While here, remove an early exit to simplify the code flow from the
PT_GETREGS / PT_SETREGS case, and add a getfpregs_supplies similar to
getregs_supplies to describe the registers supplied by PT_GETFPREGS
and PT_SETFPREGS.

gdb/ChangeLog:

	* mips-fbsd-nat.c (getregs_supplies): Fix upper bound comparison.
	(getpfpregs_supplies): New function.
	(mips_fbsd_fetch_inferior_registers): Remove early exit and use
	getfpregs_supplies.
	(mips_fbsd_store_inferior_registers): Likewise.
---
 gdb/ChangeLog       |  8 ++++++++
 gdb/mips-fbsd-nat.c | 24 +++++++++++++-----------
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index be8df1b07c..eb26e8a7dc 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2017-04-25  John Baldwin  <jhb@FreeBSD.org>
+
+	* mips-fbsd-nat.c (getregs_supplies): Fix upper bound comparison.
+	(getpfpregs_supplies): New function.
+	(mips_fbsd_fetch_inferior_registers): Remove early exit and use
+	getfpregs_supplies.
+	(mips_fbsd_store_inferior_registers): Likewise.
+
 2017-04-25  Yao Qi  <yao.qi@linaro.org>
 
 	* regcache.c (struct regcache) <readonly_p>: Change its type
diff --git a/gdb/mips-fbsd-nat.c b/gdb/mips-fbsd-nat.c
index 078df52db6..53817d7cd7 100644
--- a/gdb/mips-fbsd-nat.c
+++ b/gdb/mips-fbsd-nat.c
@@ -31,13 +31,22 @@
 #include "mips-fbsd-tdep.h"
 #include "inf-ptrace.h"
 
-/* Determine if PT_GETREGS fetches this register.  */
+/* Determine if PT_GETREGS fetches REGNUM.  */
 
 static bool
 getregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
   return (regnum >= MIPS_ZERO_REGNUM
-	  && regnum <= gdbarch_pc_regnum (gdbarch));
+	  && regnum <= mips_regnum (gdbarch)->pc);
+}
+
+/* Determine if PT_GETFPREGS fetches REGNUM.  */
+
+static bool
+getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
+{
+  return (regnum >= mips_regnum (gdbarch)->fp0
+	  && regnum < mips_regnum (gdbarch)->fp_implementation_revision);
 }
 
 /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
@@ -58,12 +67,9 @@ mips_fbsd_fetch_inferior_registers (struct target_ops *ops,
 	perror_with_name (_("Couldn't get registers"));
 
       mips_fbsd_supply_gregs (regcache, regnum, &regs, sizeof (register_t));
-      if (regnum != -1)
-	return;
     }
 
-  if (regnum == -1
-      || regnum >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
+  if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
     {
       struct fpreg fpregs;
 
@@ -97,13 +103,9 @@ mips_fbsd_store_inferior_registers (struct target_ops *ops,
 
       if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
 	perror_with_name (_("Couldn't write registers"));
-
-      if (regnum != -1)
-	return;
     }
 
-  if (regnum == -1
-      || regnum >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
+  if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
     {
       struct fpreg fpregs;
 
-- 
2.11.0

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

* [PATCH v2 2/4] Use mips_regnum instead of constants for FreeBSD/mips register operations.
  2017-04-25 21:00 [PATCH v2 0/4] Cleanups for MIPS registers (mostly FreeBSD-specific) John Baldwin
  2017-04-25 21:00 ` [PATCH v2 3/4] Consistently use fprintf_filtered when displaying MIPS registers John Baldwin
  2017-04-25 21:00 ` [PATCH v2 1/4] Cleanups to FreeBSD/mips native register operations John Baldwin
@ 2017-04-25 21:00 ` John Baldwin
  2017-04-25 21:08 ` [PATCH v2 4/4] Don't throw an error in 'info registers' for unavailable MIPS GP registers John Baldwin
  2017-05-19 16:28 ` [PATCH v2 0/4] Cleanups for MIPS registers (mostly FreeBSD-specific) John Baldwin
  4 siblings, 0 replies; 6+ messages in thread
From: John Baldwin @ 2017-04-25 21:00 UTC (permalink / raw)
  To: gdb-patches

gdb/ChangeLog:

	* mips-fbsd-tdep.c (MIPS_PC_REGNUM): Remove.
	(MIPS_FP0_REGNUM): Remove.
	(MIPS_FSR_REGNUM): Remove.
	(mips_fbsd_supply_fpregs): Use mips_regnum.
	(mips_fbsd_supply_gregs): Likewise.
	(mips_fbsd_collect_fpregs): Likewise.
	(mips_fbsd_collect_gregs): Likewise.
---
 gdb/ChangeLog        | 10 ++++++++++
 gdb/mips-fbsd-tdep.c | 29 ++++++++++++++++-------------
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index eb26e8a7dc..10023d20ae 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,15 @@
 2017-04-25  John Baldwin  <jhb@FreeBSD.org>
 
+	* mips-fbsd-tdep.c (MIPS_PC_REGNUM): Remove.
+	(MIPS_FP0_REGNUM): Remove.
+	(MIPS_FSR_REGNUM): Remove.
+	(mips_fbsd_supply_fpregs): Use mips_regnum.
+	(mips_fbsd_supply_gregs): Likewise.
+	(mips_fbsd_collect_fpregs): Likewise.
+	(mips_fbsd_collect_gregs): Likewise.
+
+2017-04-25  John Baldwin  <jhb@FreeBSD.org>
+
 	* mips-fbsd-nat.c (getregs_supplies): Fix upper bound comparison.
 	(getpfpregs_supplies): New function.
 	(mips_fbsd_fetch_inferior_registers): Remove early exit and use
diff --git a/gdb/mips-fbsd-tdep.c b/gdb/mips-fbsd-tdep.c
index 00fae0ec60..d5bec3c157 100644
--- a/gdb/mips-fbsd-tdep.c
+++ b/gdb/mips-fbsd-tdep.c
@@ -29,11 +29,6 @@
 
 #include "solib-svr4.h"
 
-/* Shorthand for some register numbers used below.  */
-#define MIPS_PC_REGNUM  MIPS_EMBED_PC_REGNUM
-#define MIPS_FP0_REGNUM MIPS_EMBED_FP0_REGNUM
-#define MIPS_FSR_REGNUM MIPS_EMBED_FP0_REGNUM + 32
-
 /* Core file support. */
 
 /* Number of registers in `struct reg' from <machine/reg.h>.  The
@@ -108,13 +103,16 @@ void
 mips_fbsd_supply_fpregs (struct regcache *regcache, int regnum,
 			 const void *fpregs, size_t regsize)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   const gdb_byte *regs = (const gdb_byte *) fpregs;
-  int i;
+  int i, fp0num, fsrnum;
 
-  for (i = MIPS_FP0_REGNUM; i <= MIPS_FSR_REGNUM; i++)
+  fp0num = mips_regnum (gdbarch)->fp0;
+  fsrnum = mips_regnum (gdbarch)->fp_control_status;
+  for (i = fp0num; i <= fsrnum; i++)
     if (regnum == i || regnum == -1)
       mips_fbsd_supply_reg (regcache, i,
-			    regs + (i - MIPS_FP0_REGNUM) * regsize, regsize);
+			    regs + (i - fp0num) * regsize, regsize);
 }
 
 /* Supply the general-purpose registers stored in GREGS to REGCACHE.
@@ -125,10 +123,11 @@ void
 mips_fbsd_supply_gregs (struct regcache *regcache, int regnum,
 			const void *gregs, size_t regsize)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   const gdb_byte *regs = (const gdb_byte *) gregs;
   int i;
 
-  for (i = 0; i <= MIPS_PC_REGNUM; i++)
+  for (i = 0; i <= mips_regnum (gdbarch)->pc; i++)
     if (regnum == i || regnum == -1)
       mips_fbsd_supply_reg (regcache, i, regs + i * regsize, regsize);
 }
@@ -141,13 +140,16 @@ void
 mips_fbsd_collect_fpregs (const struct regcache *regcache, int regnum,
 			  void *fpregs, size_t regsize)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   gdb_byte *regs = (gdb_byte *) fpregs;
-  int i;
+  int i, fp0num, fsrnum;
 
-  for (i = MIPS_FP0_REGNUM; i <= MIPS_FSR_REGNUM; i++)
+  fp0num = mips_regnum (gdbarch)->fp0;
+  fsrnum = mips_regnum (gdbarch)->fp_control_status;
+  for (i = fp0num; i <= fsrnum; i++)
     if (regnum == i || regnum == -1)
       mips_fbsd_collect_reg (regcache, i,
-			     regs + (i - MIPS_FP0_REGNUM) * regsize, regsize);
+			     regs + (i - fp0num) * regsize, regsize);
 }
 
 /* Collect the general-purpose registers from REGCACHE and store them
@@ -158,10 +160,11 @@ void
 mips_fbsd_collect_gregs (const struct regcache *regcache, int regnum,
 			 void *gregs, size_t regsize)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   gdb_byte *regs = (gdb_byte *) gregs;
   int i;
 
-  for (i = 0; i <= MIPS_PC_REGNUM; i++)
+  for (i = 0; i <= mips_regnum (gdbarch)->pc; i++)
     if (regnum == i || regnum == -1)
       mips_fbsd_collect_reg (regcache, i, regs + i * regsize, regsize);
 }
-- 
2.11.0

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

* [PATCH v2 0/4] Cleanups for MIPS registers (mostly FreeBSD-specific)
@ 2017-04-25 21:00 John Baldwin
  2017-04-25 21:00 ` [PATCH v2 3/4] Consistently use fprintf_filtered when displaying MIPS registers John Baldwin
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: John Baldwin @ 2017-04-25 21:00 UTC (permalink / raw)
  To: gdb-patches

Changes since V1 are mostly small changes from review feedback as well
as using "<absent>" instead of "<unavai" for 32-bit registers that are
not available in the table format.

John Baldwin (4):
  Cleanups to FreeBSD/mips native register operations.
  Use mips_regnum instead of constants for FreeBSD/mips register
    operations.
  Consistently use fprintf_filtered when displaying MIPS registers.
  Don't throw an error in 'info registers' for unavailable MIPS GP
    registers.

 gdb/ChangeLog        | 28 ++++++++++++++++++++++++++++
 gdb/mips-fbsd-nat.c  | 24 +++++++++++++-----------
 gdb/mips-fbsd-tdep.c | 29 ++++++++++++++++-------------
 gdb/mips-tdep.c      | 12 +++++++++---
 4 files changed, 66 insertions(+), 27 deletions(-)

-- 
2.11.0

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

* [PATCH v2 4/4] Don't throw an error in 'info registers' for unavailable MIPS GP registers.
  2017-04-25 21:00 [PATCH v2 0/4] Cleanups for MIPS registers (mostly FreeBSD-specific) John Baldwin
                   ` (2 preceding siblings ...)
  2017-04-25 21:00 ` [PATCH v2 2/4] Use mips_regnum instead of constants for FreeBSD/mips " John Baldwin
@ 2017-04-25 21:08 ` John Baldwin
  2017-05-19 16:28 ` [PATCH v2 0/4] Cleanups for MIPS registers (mostly FreeBSD-specific) John Baldwin
  4 siblings, 0 replies; 6+ messages in thread
From: John Baldwin @ 2017-04-25 21:08 UTC (permalink / raw)
  To: gdb-patches

'info registers' for MIPS throws an error and when it first encounters
an unavailable register.  This does not match other architectures
which annotate unavailable registers and continue to print out the
values of subsequent registers.  Replace the error by displaying an
aligned "<unavailable>".  This string is truncated when displaying a
32-bit register.

gdb/ChangeLog:

	* mips-tdep.c (print_gp_register_row): Don't error for unavailable
	registers.
---
 gdb/ChangeLog   |  5 +++++
 gdb/mips-tdep.c | 10 ++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index fcf0637245..02ab2181a6 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2017-04-25  John Baldwin  <jhb@FreeBSD.org>
 
+	* mips-tdep.c (print_gp_register_row): Don't error for unavailable
+	registers.
+
+2017-04-25  John Baldwin  <jhb@FreeBSD.org>
+
 	* mips-tdep.c (print_gp_register_row): Replace printf_filtered
 	with fprintf_filtered.
 
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 2364c2efdc..4b8c89de23 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -6533,8 +6533,14 @@ print_gp_register_row (struct ui_file *file, struct frame_info *frame,
 
       /* OK: get the data in raw format.  */
       if (!deprecated_frame_register_read (frame, regnum, raw_buffer))
-	error (_("can't read register %d (%s)"),
-	       regnum, gdbarch_register_name (gdbarch, regnum));
+	{
+	  fprintf_filtered (file, "%*s ",
+			    (int) mips_abi_regsize (gdbarch) * 2,
+			    mips_abi_regsize (gdbarch) == 4 ? "<absent>"
+			    : "<unavailable>");
+	  col++;
+	  continue;
+	}
       /* pad small registers */
       for (byte = 0;
 	   byte < (mips_abi_regsize (gdbarch)
-- 
2.11.0

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

* Re: [PATCH v2 0/4] Cleanups for MIPS registers (mostly FreeBSD-specific)
  2017-04-25 21:00 [PATCH v2 0/4] Cleanups for MIPS registers (mostly FreeBSD-specific) John Baldwin
                   ` (3 preceding siblings ...)
  2017-04-25 21:08 ` [PATCH v2 4/4] Don't throw an error in 'info registers' for unavailable MIPS GP registers John Baldwin
@ 2017-05-19 16:28 ` John Baldwin
  4 siblings, 0 replies; 6+ messages in thread
From: John Baldwin @ 2017-05-19 16:28 UTC (permalink / raw)
  To: gdb-patches

On Tuesday, April 25, 2017 01:59:41 PM John Baldwin wrote:
> Changes since V1 are mostly small changes from review feedback as well
> as using "<absent>" instead of "<unavai" for 32-bit registers that are
> not available in the table format.
> 
> John Baldwin (4):
>   Cleanups to FreeBSD/mips native register operations.
>   Use mips_regnum instead of constants for FreeBSD/mips register
>     operations.
>   Consistently use fprintf_filtered when displaying MIPS registers.
>   Don't throw an error in 'info registers' for unavailable MIPS GP
>     registers.

I know patch 4 is still pending review, but the FreeBSD-specific patches
1 and 2 I think address all the earlier review comments from Luis.  Can
someone review and/or approve those?

-- 
John Baldwin

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

end of thread, other threads:[~2017-05-19 16:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-25 21:00 [PATCH v2 0/4] Cleanups for MIPS registers (mostly FreeBSD-specific) John Baldwin
2017-04-25 21:00 ` [PATCH v2 3/4] Consistently use fprintf_filtered when displaying MIPS registers John Baldwin
2017-04-25 21:00 ` [PATCH v2 1/4] Cleanups to FreeBSD/mips native register operations John Baldwin
2017-04-25 21:00 ` [PATCH v2 2/4] Use mips_regnum instead of constants for FreeBSD/mips " John Baldwin
2017-04-25 21:08 ` [PATCH v2 4/4] Don't throw an error in 'info registers' for unavailable MIPS GP registers John Baldwin
2017-05-19 16:28 ` [PATCH v2 0/4] Cleanups for MIPS registers (mostly FreeBSD-specific) John Baldwin

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).