• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Révisiona8accd9ade3ea8d648c7df64403064ef168311a4 (tree)
l'heure2020-06-16 21:58:32
AuteurLuis Machado <luis.machado@lina...>
CommiterLuis Machado

Message de Log

GDBserver memory tagging remote packet support

This patch adds the generic remote bits to gdbserver so it can check for memory
tagging support and handle fetch tags and store tags requests.

gdbserver/ChangeLog:

YYYY-MM-DD Luis Machado <luis.machado@linaro.org>

* remote-utils.cc (decode_m_packet_params): Renamed from ...
(decode_m_packet): ... this, which now calls decode_m_packet_params.
(decode_M_packet): Use decode_m_packet_params.
* remote-utils.h (decode_m_packet_params): New prototype.
* server.cc (create_fmemtags_reply, parse_smemtags_request): New
functions.
(handle_general_set): Handle the QMemTags packet.
(parse_fmemtags_request): New function.
(handle_query): Handle the qMemTags packet and advertise memory
tagging support.
(captured_main): Initialize memory tagging flag.
* server.h (struct client_state): Initialize memory tagging flag.
* target.cc (process_stratum_target::supports_memory_tagging)
(process_stratum_target::fetch_memtags)
(process_stratum_target::store_memtags): New methods.
* target.h: Include gdbsupport/byte-vector.h.
(class process_stratum_target) <supports_memory_tagging>
<fetch_memtags, store_memtags>: New class virtual methods.
(target_supports_memory_tagging): Define.

Change Summary

Modification

--- a/gdbserver/remote-utils.cc
+++ b/gdbserver/remote-utils.cc
@@ -1302,10 +1302,14 @@ prepare_resume_reply (char *buf, ptid_t ptid,
13021302 }
13031303 }
13041304
1305-void
1306-decode_m_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr)
1305+/* Decode ADDR and LEN from a parameter of the form "addr,len<x>", with <x>
1306+ being an end marker character. */
1307+
1308+char *
1309+decode_m_packet_params (char *from, CORE_ADDR *mem_addr_ptr,
1310+ unsigned int *len_ptr, const char end_marker)
13071311 {
1308- int i = 0, j = 0;
1312+ int i = 0;
13091313 char ch;
13101314 *mem_addr_ptr = *len_ptr = 0;
13111315
@@ -1315,39 +1319,31 @@ decode_m_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr)
13151319 *mem_addr_ptr |= fromhex (ch) & 0x0f;
13161320 }
13171321
1318- for (j = 0; j < 4; j++)
1322+ while ((ch = from[i++]) != end_marker)
13191323 {
1320- if ((ch = from[i++]) == 0)
1321- break;
13221324 *len_ptr = *len_ptr << 4;
13231325 *len_ptr |= fromhex (ch) & 0x0f;
13241326 }
1327+
1328+ return from + i;
1329+}
1330+
1331+void
1332+decode_m_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr)
1333+{
1334+ decode_m_packet_params (from, mem_addr_ptr, len_ptr, '\0');
13251335 }
13261336
13271337 void
13281338 decode_M_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr,
13291339 unsigned char **to_p)
13301340 {
1331- int i = 0;
1332- char ch;
1333- *mem_addr_ptr = *len_ptr = 0;
1334-
1335- while ((ch = from[i++]) != ',')
1336- {
1337- *mem_addr_ptr = *mem_addr_ptr << 4;
1338- *mem_addr_ptr |= fromhex (ch) & 0x0f;
1339- }
1340-
1341- while ((ch = from[i++]) != ':')
1342- {
1343- *len_ptr = *len_ptr << 4;
1344- *len_ptr |= fromhex (ch) & 0x0f;
1345- }
1341+ from = decode_m_packet_params (from, mem_addr_ptr, len_ptr, ':');
13461342
13471343 if (*to_p == NULL)
13481344 *to_p = (unsigned char *) xmalloc (*len_ptr);
13491345
1350- hex2bin (&from[i++], *to_p, *len_ptr);
1346+ hex2bin (from, *to_p, *len_ptr);
13511347 }
13521348
13531349 int
--- a/gdbserver/remote-utils.h
+++ b/gdbserver/remote-utils.h
@@ -45,6 +45,8 @@ void prepare_resume_reply (char *buf, ptid_t ptid,
4545
4646 const char *decode_address_to_semicolon (CORE_ADDR *addrp, const char *start);
4747 void decode_address (CORE_ADDR *addrp, const char *start, int len);
48+char *decode_m_packet_params (char *from, CORE_ADDR *mem_addr_ptr,
49+ unsigned int *len_ptr, const char end_marker);
4850 void decode_m_packet (char *from, CORE_ADDR * mem_addr_ptr,
4951 unsigned int *len_ptr);
5052 void decode_M_packet (char *from, CORE_ADDR * mem_addr_ptr,
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -545,12 +545,55 @@ handle_btrace_conf_general_set (char *own_buf)
545545 return 1;
546546 }
547547
548+/* Create the qMemTags packet reply given TAGS. */
549+
550+static int
551+create_fmemtags_reply (char *reply, const gdb::byte_vector &tags)
552+{
553+ /* It is an error to pass a zero-sized tag vector. */
554+ if (tags.size () == 0)
555+ return 1;
556+
557+ std::string packet ("m");
558+
559+ /* Write the tag data. */
560+ packet += bin2hex (tags.data (), tags.size ());
561+ strcpy (reply, packet.c_str ());
562+
563+ return 0;
564+}
565+
566+/* Parse the QMemTags request into ADDR, LEN and TAGS.
567+
568+ Return 0 if successful, non-zero otherwise. */
569+
570+static int
571+parse_smemtags_request (char *request, CORE_ADDR *addr, size_t *len,
572+ gdb::byte_vector &tags)
573+{
574+ if (!startswith (request, "QMemTags:"))
575+ return 1;
576+
577+ char *p = request + strlen ("QMemTags:");
578+
579+ /* Read address and length. */
580+ unsigned int length = 0;
581+ p = decode_m_packet_params (p, addr, &length, ':');
582+ *len = length;
583+
584+ /* Read the tag data. */
585+ tags = hex2bin (p);
586+
587+ return 0;
588+}
589+
548590 /* Handle all of the extended 'Q' packets. */
549591
550592 static void
551593 handle_general_set (char *own_buf)
552594 {
553595 client_state &cs = get_client_state ();
596+
554597 if (startswith (own_buf, "QPassSignals:"))
555598 {
556599 int numsigs = (int) GDB_SIGNAL_LAST, i;
@@ -899,6 +942,30 @@ handle_general_set (char *own_buf)
899942 return;
900943 }
901944
945+
946+ /* Handle store memory tags packets. */
947+ if (startswith (own_buf, "QMemTags:")
948+ && target_supports_memory_tagging ())
949+ {
950+ gdb::byte_vector tags;
951+ CORE_ADDR addr = 0;
952+ size_t len = 0;
953+
954+ require_running_or_return (own_buf);
955+
956+ int ret = parse_smemtags_request (own_buf, &addr, &len, tags);
957+
958+ if (ret == 0)
959+ ret = the_target->store_memtags (addr, len, tags);
960+
961+ if (ret)
962+ write_enn (own_buf);
963+ else
964+ write_ok (own_buf);
965+
966+ return;
967+ }
968+
902969 /* Otherwise we didn't know what packet it was. Say we didn't
903970 understand it. */
904971 own_buf[0] = 0;
@@ -2119,6 +2186,26 @@ crc32 (CORE_ADDR base, int len, unsigned int crc)
21192186 return (unsigned long long) crc;
21202187 }
21212188
2189+/* Parse the qMemTags packet request into ADDR and LEN.
2190+
2191+ Return 0 if successful, non-zero otherwise. */
2192+
2193+static int
2194+parse_fmemtags_request (char *request, CORE_ADDR *addr, size_t *len)
2195+{
2196+ if (!startswith (request, "qMemTags:"))
2197+ return 1;
2198+
2199+ char *p = request + strlen ("qMemTags:");
2200+
2201+ /* Read address and length. */
2202+ unsigned int length = 0;
2203+ decode_m_packet (p, addr, &length);
2204+ *len = length;
2205+
2206+ return 0;
2207+}
2208+
21222209 /* Add supported btrace packets to BUF. */
21232210
21242211 static void
@@ -2344,6 +2431,12 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
23442431 events. */
23452432 report_no_resumed = true;
23462433 }
2434+ else if (strcmp (p, "memory-tagging+") == 0)
2435+ {
2436+ /* GDB supports memory tagging features. */
2437+ if (target_supports_memory_tagging ())
2438+ cs.memory_tagging_feature = true;
2439+ }
23472440 else
23482441 {
23492442 /* Move the unknown features all together. */
@@ -2467,6 +2560,9 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
24672560
24682561 strcat (own_buf, ";no-resumed+");
24692562
2563+ if (target_supports_memory_tagging ())
2564+ strcat (own_buf, ";memory-tagging+");
2565+
24702566 /* Reinitialize components as needed for the new connection. */
24712567 hostio_handle_new_gdb_connection ();
24722568 target_handle_new_gdb_connection ();
@@ -2659,6 +2755,31 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
26592755 if (target_supports_tracepoints () && handle_tracepoint_query (own_buf))
26602756 return;
26612757
2758+ /* Handle fetch memory tags packets. */
2759+ if (startswith (own_buf, "qMemTags:")
2760+ && target_supports_memory_tagging ())
2761+ {
2762+ gdb::byte_vector tags;
2763+ CORE_ADDR addr = 0;
2764+ size_t len = 0;
2765+
2766+ require_running_or_return (own_buf);
2767+
2768+ int ret = parse_fmemtags_request (own_buf, &addr, &len);
2769+
2770+ if (ret == 0)
2771+ ret = the_target->fetch_memtags (addr, len, tags);
2772+
2773+ if (ret == 0)
2774+ ret = create_fmemtags_reply (own_buf, tags);
2775+
2776+ if (ret)
2777+ write_enn (own_buf);
2778+
2779+ *new_packet_len_p = strlen (own_buf);
2780+ return;
2781+ }
2782+
26622783 /* Otherwise we didn't know what packet it was. Say we didn't
26632784 understand it. */
26642785 own_buf[0] = 0;
@@ -3865,6 +3986,7 @@ captured_main (int argc, char *argv[])
38653986 cs.swbreak_feature = 0;
38663987 cs.hwbreak_feature = 0;
38673988 cs.vCont_supported = 0;
3989+ cs.memory_tagging_feature = false;
38683990
38693991 remote_open (port);
38703992
--- a/gdbserver/server.h
+++ b/gdbserver/server.h
@@ -190,6 +190,9 @@ struct client_state
190190
191191 int current_traceframe = -1;
192192
193+ /* If true, memory tagging features are supported. */
194+ bool memory_tagging_feature = false;
195+
193196 };
194197
195198 client_state &get_client_state ();
--- a/gdbserver/target.cc
+++ b/gdbserver/target.cc
@@ -463,6 +463,26 @@ process_stratum_target::supports_read_offsets ()
463463 return false;
464464 }
465465
466+bool
467+process_stratum_target::supports_memory_tagging ()
468+{
469+ return false;
470+}
471+
472+int
473+process_stratum_target::fetch_memtags (CORE_ADDR address, size_t len,
474+ gdb::byte_vector &tags)
475+{
476+ return 0;
477+}
478+
479+int
480+process_stratum_target::store_memtags (CORE_ADDR address, size_t len,
481+ const gdb::byte_vector &tags)
482+{
483+ return 0;
484+}
485+
466486 int
467487 process_stratum_target::read_offsets (CORE_ADDR *text, CORE_ADDR *data)
468488 {
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -29,6 +29,7 @@
2929 #include "mem-break.h"
3030 #include "gdbsupport/btrace-common.h"
3131 #include <vector>
32+#include "gdbsupport/byte-vector.h"
3233
3334 struct emit_ops;
3435 struct buffer;
@@ -497,6 +498,19 @@ public:
497498
498499 /* Return tdesc index for IPA. */
499500 virtual int get_ipa_tdesc_idx ();
501+
502+ /* Returns true if the target supports memory tagging facilities. */
503+ virtual bool supports_memory_tagging ();
504+
505+ /* Return the allocated memory tags associated with
506+ [ADDRESS, ADDRESS + LEN) in TAGS. */
507+ virtual int fetch_memtags (CORE_ADDR address, size_t len,
508+ gdb::byte_vector &tags);
509+
510+ /* Write the allocation tags contained in TAGS to the memory range
511+ [ADDRESS, ADDRESS + LEN). */
512+ virtual int store_memtags (CORE_ADDR address, size_t len,
513+ const gdb::byte_vector &tags);
500514 };
501515
502516 extern process_stratum_target *the_target;
@@ -523,6 +537,9 @@ int kill_inferior (process_info *proc);
523537 #define target_supports_exec_events() \
524538 the_target->supports_exec_events ()
525539
540+#define target_supports_memory_tagging() \
541+ the_target->supports_memory_tagging ()
542+
526543 #define target_handle_new_gdb_connection() \
527544 the_target->handle_new_gdb_connection ()
528545