diff options
author | Luis Machado <luis.machado@linaro.org> | 2021-12-24 11:37:52 -0300 |
---|---|---|
committer | Luis Machado <luis.machado@linaro.org> | 2022-01-14 11:30:05 -0300 |
commit | 4e67f2c4c0cb2b4dce4af638ff719585920ecf0b (patch) | |
tree | 65bacf6a53753cfc69371288fb58aa9180c23783 | |
parent | 9d59d79fd57801624624ec659c936a30037a46aa (diff) | |
download | binutils-gdb-4e67f2c4c0cb2b4dce4af638ff719585920ecf0b.tar.gz |
Improve error messages for capability reads/writes to memory
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.
-rw-r--r-- | gdb/aarch64-linux-nat.c | 8 | ||||
-rw-r--r-- | gdb/nat/aarch64-cap-linux.c | 54 | ||||
-rw-r--r-- | gdbserver/linux-aarch64-low.cc | 11 |
3 files changed, 59 insertions, 14 deletions
diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 5e0e599c735..3848a750939 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -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; } diff --git a/gdb/nat/aarch64-cap-linux.c b/gdb/nat/aarch64-cap-linux.c index 1b427803c16..34aa5ec1ac0 100644 --- a/gdb/nat/aarch64-cap-linux.c +++ b/gdb/nat/aarch64-cap-linux.c @@ -19,6 +19,50 @@ #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; } diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index 9c2a8349e86..627ddccc5f7 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -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; |