From: Gustavo Romero <gustavo.romero@linaro.org>
To: gdb-patches@sourceware.org
Cc: luis.machado@arm.com, thiago.bauermann@linaro.org, eliz@gnu.org,
tom@tromey.com, gustavo.romero@linaro.org
Subject: [PATCH v4 6/8] gdb: Add qIsAddressTagged packet
Date: Tue, 16 Apr 2024 14:07:26 +0000 [thread overview]
Message-ID: <20240416140728.198163-7-gustavo.romero@linaro.org> (raw)
In-Reply-To: <20240416140728.198163-1-gustavo.romero@linaro.org>
This commit adds a new packet, qIsAddressTagged, allowing GDB remote
targets to use it to query the stub if a given address is tagged.
Currently, the memory tagging address check is done via a read query,
where the contents of /proc/<PID>/smaps is read and the flags are
inspected for memory tagging-related flags that indicate the address is
in a memory tagged region.
This is not ideal, for example, for QEMU stub and other cases, such as
on bare-metal, where there is no notion of an OS file like 'smaps.'
Hence, the introduction of qIsAddressTagged packet allows checking
if an address is tagged in an agnostic way.
The is_address_tagged target hook in remote.c attempts to use the
qIsAddressTagged packet first for checking if an address is tagged and
if the stub does not support such a packet (reply is empty) it falls
back to using the current mechanism that reads the contents of
/proc/<PID>/smaps via vFile requests.
Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
---
gdb/remote.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/gdb/remote.c b/gdb/remote.c
index 9717db55e27..63799ac5e3f 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -15534,6 +15534,40 @@ create_store_memtags_request (gdb::char_vector &packet, CORE_ADDR address,
strcpy (packet.data (), request.c_str ());
}
+static void
+create_is_address_tagged_request (gdbarch *gdbarch, gdb::char_vector &packet,
+ CORE_ADDR address)
+{
+ int addr_size;
+ std::string request;
+
+ addr_size = gdbarch_addr_bit (gdbarch) / 8;
+ request = string_printf ("qIsAddressTagged:%s", phex_nz (address, addr_size));
+
+ if (packet.size () < request.length () + 1)
+ error (_("Contents too big for packet qIsAddressTagged."));
+
+ strcpy (packet.data (), request.c_str ());
+}
+
+static bool
+check_is_address_tagged_reply (gdb::char_vector &packet, bool *tagged)
+{
+ if (packet_check_result (packet).status () != PACKET_OK)
+ return false;
+
+ gdb_byte reply;
+ /* Convert only 2 hex digits, i.e. 1 byte in hex format. */
+ hex2bin (packet.data (), &reply, 1);
+
+ if (reply == 0x00 || reply == 0x01) {
+ *tagged = !!reply;
+ return true;
+ }
+
+ return false;
+}
+
/* Implement the "fetch_memtags" target_ops method. */
bool
@@ -15580,6 +15614,21 @@ remote_target::store_memtags (CORE_ADDR address, size_t len,
bool
remote_target::is_address_tagged (gdbarch *gdbarch, CORE_ADDR address)
{
+ struct remote_state *rs = get_remote_state ();
+ bool is_addr_tagged;
+
+ /* Firstly, attempt to check the address using the qIsAddressTagged
+ packet. */
+ create_is_address_tagged_request (gdbarch, rs->buf, address);
+
+ putpkt (rs->buf);
+ getpkt (&rs->buf);
+
+ if (check_is_address_tagged_reply (rs->buf, &is_addr_tagged))
+ return is_addr_tagged;
+
+ /* Fallback to arch-specific method of checking whether an address is tagged
+ if qIsAddressTagged fails. */
return gdbarch_tagged_address_p (gdbarch, address);
}
--
2.34.1
next prev parent reply other threads:[~2024-04-16 14:07 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-16 14:07 [PATCH v4 0/8] Add another way to check tagged addresses on remote targets Gustavo Romero
2024-04-16 14:07 ` [PATCH v4 1/8] gdb: aarch64: Remove MTE address checking from get_memtag Gustavo Romero
2024-04-16 14:07 ` [PATCH v4 2/8] gdb: aarch64: Move MTE address check out of set_memtag Gustavo Romero
2024-04-16 16:30 ` Luis Machado
2024-04-16 14:07 ` [PATCH v4 3/8] gdb: aarch64: Remove MTE address checking from memtag_matches_p Gustavo Romero
2024-04-16 14:07 ` [PATCH v4 4/8] gdb: Use passed gdbarch instead of calling current_inferior Gustavo Romero
2024-04-16 14:07 ` [PATCH v4 5/8] gdb: Introduce is_address_tagged target hook Gustavo Romero
2024-04-17 9:22 ` Luis Machado
2024-04-16 14:07 ` Gustavo Romero [this message]
2024-04-16 18:04 ` [PATCH v4 6/8] gdb: Add qIsAddressTagged packet Luis Machado
2024-04-17 20:57 ` Gustavo Romero
2024-04-16 14:07 ` [PATCH v4 7/8] gdb/testsuite: Add unittest for " Gustavo Romero
2024-04-17 9:38 ` Luis Machado
2024-04-17 19:03 ` Gustavo Romero
2024-04-17 19:11 ` Gustavo Romero
2024-04-16 14:07 ` [PATCH v4 8/8] gdb: Document " Gustavo Romero
2024-04-16 14:34 ` Eli Zaretskii
2024-04-16 23:10 ` Gustavo Romero
2024-04-17 12:09 ` Eli Zaretskii
2024-04-17 18:21 ` Gustavo Romero
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240416140728.198163-7-gustavo.romero@linaro.org \
--to=gustavo.romero@linaro.org \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=luis.machado@arm.com \
--cc=thiago.bauermann@linaro.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).