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);
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;
}
#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
/* Fetch the tag from ptrace. */
if (ptrace (PTRACE_PEEKCAP, tid, address, &cap) < 0)
- return false;
+ {
+ morello_linux_peekcap_error (errno);
+ return false;
+ }
return true;
}
{
/* Fetch the tag from ptrace. */
if (ptrace (PTRACE_POKECAP, tid, address, &cap) < 0)
- return false;
+ {
+ morello_linux_pokecap_error (errno);
+ return false;
+ }
return true;
}
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);
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;