Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA/commit/ia64-linux] Allow libunwind to fetch register 0
@ 2011-10-25 16:55 Joel Brobecker
  2011-10-25 17:27 ` Pedro Alves
  0 siblings, 1 reply; 15+ messages in thread
From: Joel Brobecker @ 2011-10-25 16:55 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker

On ia64-linux, GDB sometimes prints the following error when trying
to switch to a different task:

    (gdb) task 3
    Register 0 is not available

This is a random failure that sometimes happens, sometimes does not.
We should be able to see with any program that uses thread, probably
when the debugger stops the program at a certain point (which conditions
trigger the problem have not been investigated).

The error comes from the fact that the libunwind library is requesting
the value of register 0 (zero): This eventually leads us to
ia64-linux-nat.c:ia64_linux_fetch_register.

This function relies on ia64_cannot_fetch_register to determine
whether or not we have access to the register's value.  The ptrace
interface does not provide the r0 value, and so we end up telling
the regcache that this register's value is not available.  And yet,
for r0, we do not need to ask ptrace for its value, since it is
always zero.

So, the fix was to add a special rule for supplying a nul value
when regnum == 0.

gdb/ChangeLog:

        * ia64-linux-nat.c (ia64_linux_fetch_register): Add special
        handling for r0.

Tested on ia64-linux. I also tested it against the program I used
to reproduce the problem. It used to consistently reproduce once
every 1-10 times. Now, it doesn't anymore even after trying 50 times.

OK?

---
 gdb/ia64-linux-nat.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/gdb/ia64-linux-nat.c b/gdb/ia64-linux-nat.c
index 65e077b..f43e91e 100644
--- a/gdb/ia64-linux-nat.c
+++ b/gdb/ia64-linux-nat.c
@@ -681,6 +681,17 @@ ia64_linux_fetch_register (struct regcache *regcache, int regnum)
   PTRACE_TYPE_RET *buf;
   int pid, i;
 
+  /* r0 cannot be fetched but is always zero.  */
+  if (regnum == 0)
+    {
+      const char r0_value[8] = {0x00, 0x00, 0x00, 0x00,
+				0x00, 0x00, 0x00, 0x00};
+
+      gdb_assert (sizeof (r0_value) == register_size (gdbarch, regnum));
+      regcache_raw_supply (regcache, regnum, r0_value);
+      return;
+    }
+
   if (ia64_cannot_fetch_register (gdbarch, regnum))
     {
       regcache_raw_supply (regcache, regnum, NULL);
-- 
1.7.1


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

end of thread, other threads:[~2012-03-28 17:56 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-25 16:55 [RFA/commit/ia64-linux] Allow libunwind to fetch register 0 Joel Brobecker
2011-10-25 17:27 ` Pedro Alves
2011-10-25 17:37   ` Pedro Alves
2011-10-25 20:49   ` Joel Brobecker
2011-10-26  0:27     ` Pedro Alves
2012-03-27 19:32     ` Pedro Alves
2012-03-27 23:03       ` Joel Brobecker
2012-03-28 12:52         ` Pedro Alves
2012-03-28 14:55           ` [PATCH] IA64: EC, the Epilog Count register, is available in ptrace Pedro Alves
2012-03-28 17:12             ` Joel Brobecker
2012-03-28 17:55               ` Pedro Alves
2012-03-28 14:55           ` [PATCH] IA64: $fr0==0.0, $fr1==1.0 Pedro Alves
2012-03-28 17:15             ` Joel Brobecker
2012-03-28 17:56               ` Pedro Alves
2012-03-28 17:10           ` [RFA/commit/ia64-linux] Allow libunwind to fetch register 0 Joel Brobecker

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