[v4,1/2] gdb/regcache: return REG_UNAVAILABLE in raw_read if NOT_AVAILABLE_ERROR is seen

Message ID f47c4f22525652992977aa6f4e8630a3c47ee879.1702909611.git.tankut.baris.aktemur@intel.com
State New
Headers
Series Querying registers of already-exited processes |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Aktemur, Tankut Baris Dec. 18, 2023, 2:40 p.m. UTC
  In regcache's raw_read, it is possible that 'raw_update' fails with an
exception.  This could happen, for instance, if the debugged thread is
already exited and the target cannot fetch its registers.  Catch the
exception and return REG_UNAVAILABLE if the error is of kind
NOT_AVAILABLE_ERROR.  This makes clients' lives easier.

Regression-tested on X86_64-Linux using the unix, native-gdbserver, and
native-extended-gdbserver board files.
---
 gdb/regcache.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gdb/regcache.c b/gdb/regcache.c
index 6140a05f02b..0ed433aa182 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -616,7 +616,17 @@  readable_regcache::raw_read (int regnum, gdb::array_view<gdb_byte> dst)
   assert_regnum (regnum);
   gdb_assert (dst.size () == m_descr->sizeof_register[regnum]);
 
-  raw_update (regnum);
+  try
+    {
+      raw_update (regnum);
+    }
+  catch (const gdb_exception_error &ex)
+    {
+      if (ex.error != NOT_AVAILABLE_ERROR)
+	throw;
+
+      m_register_status[regnum] = REG_UNAVAILABLE;
+    }
 
   if (m_register_status[regnum] != REG_VALID)
     memset (dst.data (), 0, dst.size ());