Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [hppa patch] Fix register definitions for hppa
@ 2007-08-03 17:06 Randolph Chung
  2007-08-03 17:11 ` Daniel Jacobowitz
  2007-08-03 18:42 ` [parisc-linux] " Carlos O'Donell
  0 siblings, 2 replies; 6+ messages in thread
From: Randolph Chung @ 2007-08-03 17:06 UTC (permalink / raw)
  To: gdb-patches; +Cc: parisc-linux

Should be self-explanatory. We came across this while debugging
TLS-enabled thread debugging on hppa-linux. GDB was not reading 
cr27 (hppa's thread register), so thread-debugging failed quite 
miserably :(

If there are no comments, I shall commit in a couple of days.

thanks,
randolph

2007-08-03  Randolph Chung  <tausq@debian.org>

	* hppa-tdep.c (hppa32_cannot_fetch_register)
	(hppa64_cannot_fetch_register): New functions.
	(hppa_gdbarch_init): Set cannot_fetch_register appropriately.
	* hppa-tdep.h (hppa_regnum): Add HPPA_CR26_REGNUM.

Index: hppa-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/hppa-tdep.c,v
retrieving revision 1.234
diff -u -p -r1.234 hppa-tdep.c
--- hppa-tdep.c	15 Jun 2007 22:44:55 -0000	1.234
+++ hppa-tdep.c	13 Jul 2007 16:26:29 -0000
@@ -2676,6 +2676,16 @@ hppa32_cannot_store_register (int regnum
 }
 
 static int
+hppa32_cannot_fetch_register (int regnum)
+{
+  /* cr26 and cr27 are readable (but not writable) from userspace.  */
+  if (regnum == HPPA_CR26_REGNUM || regnum == HPPA_CR27_REGNUM)
+    return 0;
+  else
+    return hppa32_cannot_store_register (regnum);
+}
+
+static int
 hppa64_cannot_store_register (int regnum)
 {
   return (regnum == 0
@@ -2684,6 +2694,16 @@ hppa64_cannot_store_register (int regnum
           || (regnum > HPPA_IPSW_REGNUM && regnum < HPPA64_FP4_REGNUM));
 }
 
+static int
+hppa64_cannot_fetch_register (int regnum)
+{
+  /* cr26 and cr27 are readable (but not writable) from userspace.  */
+  if (regnum == HPPA_CR26_REGNUM || regnum == HPPA_CR27_REGNUM)
+    return 0;
+  else
+    return hppa64_cannot_store_register (regnum);
+}
+
 static CORE_ADDR
 hppa_smash_text_address (CORE_ADDR addr)
 {
@@ -3076,7 +3096,7 @@ hppa_gdbarch_init (struct gdbarch_info i
 	set_gdbarch_cannot_store_register (gdbarch,
 					   hppa32_cannot_store_register);
 	set_gdbarch_cannot_fetch_register (gdbarch,
-					   hppa32_cannot_store_register);
+					   hppa32_cannot_fetch_register);
         break;
       case 8:
         set_gdbarch_num_regs (gdbarch, hppa64_num_regs);
@@ -3087,7 +3107,7 @@ hppa_gdbarch_init (struct gdbarch_info i
 	set_gdbarch_cannot_store_register (gdbarch,
 					   hppa64_cannot_store_register);
 	set_gdbarch_cannot_fetch_register (gdbarch,
-					   hppa64_cannot_store_register);
+					   hppa64_cannot_fetch_register);
         break;
       default:
         internal_error (__FILE__, __LINE__, _("Unsupported address size: %d"),
Index: hppa-tdep.h
===================================================================
RCS file: /cvs/src/src/gdb/hppa-tdep.h,v
retrieving revision 1.30
diff -u -p -r1.30 hppa-tdep.h
--- hppa-tdep.h	15 Jun 2007 22:44:55 -0000	1.30
+++ hppa-tdep.h	13 Jul 2007 16:26:29 -0000
@@ -59,6 +59,7 @@ enum hppa_regnum
   HPPA_PID3_REGNUM = 56,	/* Protection ID */
   HPPA_CCR_REGNUM = 54,		/* Coprocessor Configuration Register */
   HPPA_TR0_REGNUM = 57,		/* Temporary Registers (cr24 -> cr31) */
+  HPPA_CR26_REGNUM = 59,
   HPPA_CR27_REGNUM = 60,	/* Base register for thread-local storage, cr27 */
   HPPA_FP0_REGNUM = 64,		/* First floating-point.  */
   HPPA_FP4_REGNUM = 72,


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

* Re: [hppa patch] Fix register definitions for hppa
  2007-08-03 17:06 [hppa patch] Fix register definitions for hppa Randolph Chung
@ 2007-08-03 17:11 ` Daniel Jacobowitz
  2007-08-03 18:42 ` [parisc-linux] " Carlos O'Donell
  1 sibling, 0 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2007-08-03 17:11 UTC (permalink / raw)
  To: Randolph Chung; +Cc: gdb-patches, parisc-linux

On Fri, Aug 03, 2007 at 05:06:46PM +0000, Randolph Chung wrote:
> Should be self-explanatory. We came across this while debugging
> TLS-enabled thread debugging on hppa-linux. GDB was not reading 
> cr27 (hppa's thread register), so thread-debugging failed quite 
> miserably :(
> 
> If there are no comments, I shall commit in a couple of days.

Seems OK to me too.

-- 
Daniel Jacobowitz
CodeSourcery


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

* Re: [parisc-linux] [hppa patch] Fix register definitions for hppa
  2007-08-03 17:06 [hppa patch] Fix register definitions for hppa Randolph Chung
  2007-08-03 17:11 ` Daniel Jacobowitz
@ 2007-08-03 18:42 ` Carlos O'Donell
  2007-08-03 20:12   ` Randolph Chung
  1 sibling, 1 reply; 6+ messages in thread
From: Carlos O'Donell @ 2007-08-03 18:42 UTC (permalink / raw)
  To: Randolph Chung; +Cc: gdb-patches, parisc-linux

On 8/3/07, Randolph Chung <randolph@tausq.org> wrote:
> 2007-08-03  Randolph Chung  <tausq@debian.org>
>
>         * hppa-tdep.c (hppa32_cannot_fetch_register)
>         (hppa64_cannot_fetch_register): New functions.
>         (hppa_gdbarch_init): Set cannot_fetch_register appropriately.
>         * hppa-tdep.h (hppa_regnum): Add HPPA_CR26_REGNUM.
>
> Index: hppa-tdep.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/hppa-tdep.c,v
> retrieving revision 1.234
> diff -u -p -r1.234 hppa-tdep.c
> --- hppa-tdep.c 15 Jun 2007 22:44:55 -0000      1.234
> +++ hppa-tdep.c 13 Jul 2007 16:26:29 -0000
> @@ -2676,6 +2676,16 @@ hppa32_cannot_store_register (int regnum
>  }
>
>  static int
> +hppa32_cannot_fetch_register (int regnum)
> +{
> +  /* cr26 and cr27 are readable (but not writable) from userspace.  */
> +  if (regnum == HPPA_CR26_REGNUM || regnum == HPPA_CR27_REGNUM)
> +    return 0;
> +  else
> +    return hppa32_cannot_store_register (regnum);
> +}
> +

Isn't there a way we can teach gdb that cr27 is writable via this sequence?

e.g.
static inline void __set_cr27(struct pthread *cr27)
{
  asm ( "ble    0xe0(%%sr2, %%r0)\n\t"
        "copy   %0, %%r26"
        : : "r" (cr27) : "r26" );
}

At the very least please adjust the comment to say "cr27 is writable via
a kernel helper function."

How does gdb read cr27? It must know how to use mfctl?

Cheers,
Carlos.


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

* Re: [parisc-linux] [hppa patch] Fix register definitions for hppa
  2007-08-03 18:42 ` [parisc-linux] " Carlos O'Donell
@ 2007-08-03 20:12   ` Randolph Chung
  2007-08-04 16:35     ` Carlos O'Donell
  0 siblings, 1 reply; 6+ messages in thread
From: Randolph Chung @ 2007-08-03 20:12 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: gdb-patches, parisc-linux

> Isn't there a way we can teach gdb that cr27 is writable via this sequence?
> 
> e.g.
> static inline void __set_cr27(struct pthread *cr27)
> {
>   asm ( "ble    0xe0(%%sr2, %%r0)\n\t"
>         "copy   %0, %%r26"
>         : : "r" (cr27) : "r26" );
> }
> 
> At the very least please adjust the comment to say "cr27 is writable via
> a kernel helper function."
> 
> How does gdb read cr27? It must know how to use mfctl?

Remember that gdb is reading the cr27 of the debuggee, not of itself, so
__set_cr27 is irrelevant.

 From the architecture point of view, CR26 and CR27 are only readable
from userspace, so gdb should not enable somebody to set them from
inside gdb.

GDB gets the value of cr26/cr27 the same way it gets the value of other
registers -- via ptrace or the register set returned in a core dump,
etc...

randolph
-- 
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/


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

* Re: [parisc-linux] [hppa patch] Fix register definitions for hppa
  2007-08-03 20:12   ` Randolph Chung
@ 2007-08-04 16:35     ` Carlos O'Donell
  2007-08-04 17:02       ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Carlos O'Donell @ 2007-08-04 16:35 UTC (permalink / raw)
  To: Randolph Chung; +Cc: gdb-patches, parisc-linux

On 8/3/07, Randolph Chung <randolph@tausq.org> wrote:
> Remember that gdb is reading the cr27 of the debuggee, not of itself, so
> __set_cr27 is irrelevant.

Is it usefull to be able to adjust the inferior's thread register?

>  From the architecture point of view, CR26 and CR27 are only readable
> from userspace, so gdb should not enable somebody to set them from
> inside gdb.

Would it be usefull to adjust the thread register when debugging glibc?

Cheers,
Carlos.


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

* Re: [parisc-linux] [hppa patch] Fix register definitions for hppa
  2007-08-04 16:35     ` Carlos O'Donell
@ 2007-08-04 17:02       ` Daniel Jacobowitz
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2007-08-04 17:02 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: Randolph Chung, gdb-patches, parisc-linux

On Sat, Aug 04, 2007 at 12:35:26PM -0400, Carlos O'Donell wrote:
> >  From the architecture point of view, CR26 and CR27 are only readable
> > from userspace, so gdb should not enable somebody to set them from
> > inside gdb.
> 
> Would it be usefull to adjust the thread register when debugging glibc?

Not especially.  You can call a glibc function to do so, if you need.

-- 
Daniel Jacobowitz
CodeSourcery


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

end of thread, other threads:[~2007-08-04 17:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-03 17:06 [hppa patch] Fix register definitions for hppa Randolph Chung
2007-08-03 17:11 ` Daniel Jacobowitz
2007-08-03 18:42 ` [parisc-linux] " Carlos O'Donell
2007-08-03 20:12   ` Randolph Chung
2007-08-04 16:35     ` Carlos O'Donell
2007-08-04 17:02       ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox