]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Improve error messages for capability reads/writes to memory
authorLuis Machado <luis.machado@linaro.org>
Fri, 24 Dec 2021 14:37:52 +0000 (11:37 -0300)
committerLuis Machado <luis.machado@linaro.org>
Fri, 14 Jan 2022 14:30:05 +0000 (11:30 -0300)
Improve the messages a little so the errors are more clear. One case in
particular is when we attempt to write a tagged capability to a shared
mapping area that doesn't support tags.

GDB and GDBserver share the same error messages now.

gdb/aarch64-linux-nat.c
gdb/nat/aarch64-cap-linux.c
gdbserver/linux-aarch64-low.cc

index 5e0e599c735399eea4db6ee9ad896e22b270f6f5..3848a750939ba8db1d1eadfcc8be1c9f6627bb84 100644 (file)
@@ -1101,7 +1101,10 @@ aarch64_linux_nat_target::read_capability (CORE_ADDR addr)
   struct user_cap cap;
 
   if (!aarch64_linux_read_capability (tid, addr, cap))
-    perror_with_name (_("Unable to read capability from address."));
+    {
+      gdb::byte_vector cap_vec;
+      return cap_vec;
+    }
 
   gdb::byte_vector cap_vec (17);
   memcpy (cap_vec.data (), &cap.tag, 1);
@@ -1124,8 +1127,7 @@ aarch64_linux_nat_target::write_capability (CORE_ADDR addr,
   memcpy (&cap.val, buffer.data () + 1, 16);
 
   if (!aarch64_linux_write_capability (tid, addr, cap))
-    perror_with_name (_("Unable to write capability to address.\n"
-                       "Please run \"sysctl cheri.ptrace_forge_cap=1\"."));
+    return false;
 
   return true;
 }
index 1b427803c1636deb34803310bf96eef8210bd7aa..34aa5ec1ac02c43ddf9cb6fbe47d78ca949dc1dc 100644 (file)
 #include "aarch64-cap-linux.h"
 #include "gdb_ptrace.h"
 
+/* Helper function to display various possible errors when reading
+   Morello capabilities from memory.  */
+
+static void
+morello_linux_peekcap_error (int error)
+{
+  switch (error)
+    {
+    case EIO:
+    case EFAULT:
+      warning (_("PTRACE_PEEKCAP: Couldn't fetch capability"));
+      break;
+    default:
+      warning (_("PTRACE_PEEKCAP: Unknown error"));
+      break;
+    }
+}
+
+/* Helper function to display various possible errors when writing
+   Morello capabilities to memory.  */
+
+static void
+morello_linux_pokecap_error (int error)
+{
+  switch (error)
+    {
+    case EIO:
+    case EFAULT:
+      warning (_("PTRACE_POKECAP: Couldn't store capability"));
+      break;
+    case EPERM:
+      warning (_("PTRACE_POKECAP:: Couldn't store capability.\n"
+                "Make sure the sysctl flag cheri.ptrace_forge_cap is 1"));
+      break;
+    case EOPNOTSUPP:
+      warning (_("PTRACE_POKECAP: Capability tags not enabled for"
+                " requested address"));
+      break;
+    default:
+      warning (_("PTRACE_POKECAP: Unknown error"));
+      break;
+    }
+}
+
 /* See aarch64-cap-linux.h */
 
 bool
@@ -31,7 +75,10 @@ aarch64_linux_read_capability (int tid, CORE_ADDR address,
 
   /* Fetch the tag from ptrace.  */
   if (ptrace (PTRACE_PEEKCAP, tid, address, &cap) < 0)
-    return false;
+    {
+      morello_linux_peekcap_error (errno);
+      return false;
+    }
 
   return true;
 }
@@ -44,7 +91,10 @@ aarch64_linux_write_capability (int tid, CORE_ADDR address,
 {
   /* Fetch the tag from ptrace.  */
   if (ptrace (PTRACE_POKECAP, tid, address, &cap) < 0)
-    return false;
+    {
+      morello_linux_pokecap_error (errno);
+      return false;
+    }
 
   return true;
 }
index 9c2a8349e866add9a210c850a5a4094a14174fbe..627ddccc5f79c57898e45f44ee73202487634daf 100644 (file)
@@ -3338,10 +3338,7 @@ aarch64_target::qxfer_capability (const CORE_ADDR address,
   if (readbuf != nullptr)
     {
       if (!aarch64_linux_read_capability (tid, address, cap))
-       {
-         warning (_("Unable to read capability from address."));
-         return 0;
-       }
+       return 0;
 
       /* Copy data to readbuf.  */
       memcpy (readbuf, &cap.tag, 1);
@@ -3355,11 +3352,7 @@ aarch64_target::qxfer_capability (const CORE_ADDR address,
       memset (&cap.__reserved, 0, 15);
 
       if (!aarch64_linux_write_capability (tid, address, cap))
-       {
-         warning (_("Unable to write capability to address.\n"
-                    "Please run \"sysctl cheri.ptrace_forge_cap=1\"."));
-         return 0;
-       }
+       return 0;
     }
 
   return sizeof (cap.val) + 1;