aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
authorLuis Machado <luis.machado@linaro.org>2020-06-15 15:49:37 -0300
committerLuis Machado <luis.machado@linaro.org>2021-03-24 14:57:53 -0300
commit48136e006e324980195e21f70ca4accd7f722ceb (patch)
treec01722116f1c614606212f84c31c0991b85ab092 /gdbsupport
parentffcc2a15499644040a4c6a80828cf1795d9bc54b (diff)
downloadgdb-48136e006e324980195e21f70ca4accd7f722ceb.zip
gdb-48136e006e324980195e21f70ca4accd7f722ceb.tar.gz
gdb-48136e006e324980195e21f70ca4accd7f722ceb.tar.bz2
New memory-tag commands
Add new commands under the "memory-tag" prefix to allow users to inspect, modify and check memory tags in different ways. The available subcommands are the following: - memory-tag print-logical-tag <expression>: Prints the logical tag for a particular address. - memory-tag withltag <expression> <tag>: Prints the address tagged with the logical tag <tag>. - memory-tag print-allocation-tag <expression>: Prints the allocation tag for a particular address. - memory-tag setatag <expression> <length> <tags>: Sets one or more allocation tags to the specified tags. - memory-tag check <expression>: Checks if the logical tag in <address> matches its allocation tag. These commands make use of the memory tagging gdbarch methods, and are still available, but disabled, when memory tagging is not supported by the architecture. I've pondered about a way to make these commands invisible when memory tagging is not available, but given the check is at runtime (and support may come and go based on a process' configuration), that is a bit too late in the process to either not include the commands or get rid of them. Ideas are welcome. gdb/ChangeLog: 2021-03-24 Luis Machado <luis.machado@linaro.org> * printcmd.c: Include gdbsupport/rsp-low.h. (memory_tag_list): New static global. (process_print_command_args): Factored out of print_command_1. (print_command_1): Use process_print_command_args. (show_addr_not_tagged, show_memory_tagging_unsupported) (memory_tag_command, memory_tag_print_tag_command) (memory_tag_print_logical_tag_command) (memory_tag_print_allocation_tag_command, parse_with_logical_tag_input) (memory_tag_with_logical_tag_command, parse_set_allocation_tag_input) (memory_tag_set_allocation_tag_command, memory_tag_check_command): New functions. (_initialize_printcmd): Add "memory-tag" prefix and subcommands. gdbsupport/ChangeLog: 2021-03-24 Luis Machado <luis.machado@linaro.org> * rsp-low.cc (fromhex, hex2bin): Move to ... * common-utils.cc: ... here. (fromhex) Change error message text to not be RSP-specific. * rsp-low.h (fromhex, hex2bin): Move to ... * common-utils.h: ... here.
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/ChangeLog8
-rw-r--r--gdbsupport/common-utils.cc49
-rw-r--r--gdbsupport/common-utils.h15
-rw-r--r--gdbsupport/rsp-low.cc49
-rw-r--r--gdbsupport/rsp-low.h19
5 files changed, 72 insertions, 68 deletions
diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog
index a838cfc..cf275a4 100644
--- a/gdbsupport/ChangeLog
+++ b/gdbsupport/ChangeLog
@@ -1,3 +1,11 @@
+2021-03-24 Luis Machado <luis.machado@linaro.org>
+
+ * rsp-low.cc (fromhex, hex2bin): Move to ...
+ * common-utils.cc: ... here.
+ (fromhex) Change error message text to not be RSP-specific.
+ * rsp-low.h (fromhex, hex2bin): Move to ...
+ * common-utils.h: ... here.
+
2021-03-21 Alan Modra <amodra@gmail.com>
* common-utils.h (startswith): Delete version now supplied by bfd.h.
diff --git a/gdbsupport/common-utils.cc b/gdbsupport/common-utils.cc
index ed33480..8ce839a 100644
--- a/gdbsupport/common-utils.cc
+++ b/gdbsupport/common-utils.cc
@@ -392,3 +392,52 @@ align_down (ULONGEST v, int n)
gdb_assert (n && (n & (n-1)) == 0);
return (v & -n);
}
+
+/* See gdbsupport/common-utils.h. */
+
+int
+fromhex (int a)
+{
+ if (a >= '0' && a <= '9')
+ return a - '0';
+ else if (a >= 'a' && a <= 'f')
+ return a - 'a' + 10;
+ else if (a >= 'A' && a <= 'F')
+ return a - 'A' + 10;
+ else
+ error (_("Invalid hex digit %d"), a);
+}
+
+/* See gdbsupport/common-utils.h. */
+
+int
+hex2bin (const char *hex, gdb_byte *bin, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ {
+ if (hex[0] == 0 || hex[1] == 0)
+ {
+ /* Hex string is short, or of uneven length.
+ Return the count that has been converted so far. */
+ return i;
+ }
+ *bin++ = fromhex (hex[0]) * 16 + fromhex (hex[1]);
+ hex += 2;
+ }
+ return i;
+}
+
+/* See gdbsupport/common-utils.h. */
+
+gdb::byte_vector
+hex2bin (const char *hex)
+{
+ size_t bin_len = strlen (hex) / 2;
+ gdb::byte_vector bin (bin_len);
+
+ hex2bin (hex, bin.data (), bin_len);
+
+ return bin;
+}
diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
index 1de747f..224e1f3 100644
--- a/gdbsupport/common-utils.h
+++ b/gdbsupport/common-utils.h
@@ -22,6 +22,7 @@
#include <string>
#include <vector>
+#include "gdbsupport/byte-vector.h"
#include "poison.h"
@@ -191,4 +192,18 @@ in_inclusive_range (T value, T low, T high)
extern ULONGEST align_up (ULONGEST v, int n);
extern ULONGEST align_down (ULONGEST v, int n);
+/* Convert hex digit A to a number, or throw an exception. */
+extern int fromhex (int a);
+
+/* HEX is a string of characters representing hexadecimal digits.
+ Convert pairs of hex digits to bytes and store sequentially into
+ BIN. COUNT is the maximum number of characters to convert. This
+ will convert fewer characters if the number of hex characters
+ actually seen is odd, or if HEX terminates before COUNT characters.
+ Returns the number of characters actually converted. */
+extern int hex2bin (const char *hex, gdb_byte *bin, int count);
+
+/* Like the above, but return a gdb::byte_vector. */
+gdb::byte_vector hex2bin (const char *hex);
+
#endif /* COMMON_COMMON_UTILS_H */
diff --git a/gdbsupport/rsp-low.cc b/gdbsupport/rsp-low.cc
index eb8f70a..8900ed4 100644
--- a/gdbsupport/rsp-low.cc
+++ b/gdbsupport/rsp-low.cc
@@ -23,21 +23,6 @@
/* See rsp-low.h. */
int
-fromhex (int a)
-{
- if (a >= '0' && a <= '9')
- return a - '0';
- else if (a >= 'a' && a <= 'f')
- return a - 'a' + 10;
- else if (a >= 'A' && a <= 'F')
- return a - 'A' + 10;
- else
- error (_("Reply contains invalid hex digit %d"), a);
-}
-
-/* See rsp-low.h. */
-
-int
tohex (int nib)
{
if (nib < 10)
@@ -111,40 +96,6 @@ unpack_varlen_hex (const char *buff, /* packet to parse */
/* See rsp-low.h. */
-int
-hex2bin (const char *hex, gdb_byte *bin, int count)
-{
- int i;
-
- for (i = 0; i < count; i++)
- {
- if (hex[0] == 0 || hex[1] == 0)
- {
- /* Hex string is short, or of uneven length.
- Return the count that has been converted so far. */
- return i;
- }
- *bin++ = fromhex (hex[0]) * 16 + fromhex (hex[1]);
- hex += 2;
- }
- return i;
-}
-
-/* See rsp-low.h. */
-
-gdb::byte_vector
-hex2bin (const char *hex)
-{
- size_t bin_len = strlen (hex) / 2;
- gdb::byte_vector bin (bin_len);
-
- hex2bin (hex, bin.data (), bin_len);
-
- return bin;
-}
-
-/* See rsp-low.h. */
-
std::string
hex2str (const char *hex)
{
diff --git a/gdbsupport/rsp-low.h b/gdbsupport/rsp-low.h
index fd0b16f..6ef4b36 100644
--- a/gdbsupport/rsp-low.h
+++ b/gdbsupport/rsp-low.h
@@ -20,12 +20,6 @@
#ifndef COMMON_RSP_LOW_H
#define COMMON_RSP_LOW_H
-#include "gdbsupport/byte-vector.h"
-
-/* Convert hex digit A to a number, or throw an exception. */
-
-extern int fromhex (int a);
-
/* Convert number NIB to a hex digit. */
extern int tohex (int nib);
@@ -45,19 +39,6 @@ extern char *pack_hex_byte (char *pkt, int byte);
extern const char *unpack_varlen_hex (const char *buff, ULONGEST *result);
-/* HEX is a string of characters representing hexadecimal digits.
- Convert pairs of hex digits to bytes and store sequentially into
- BIN. COUNT is the maximum number of characters to convert. This
- will convert fewer characters if the number of hex characters
- actually seen is odd, or if HEX terminates before COUNT characters.
- Returns the number of characters actually converted. */
-
-extern int hex2bin (const char *hex, gdb_byte *bin, int count);
-
-/* Like the above, but return a gdb::byte_vector. */
-
-gdb::byte_vector hex2bin (const char *hex);
-
/* Like hex2bin, but return a std::string. */
extern std::string hex2str (const char *hex);