]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
btrace, gdbserver: Add ptwrite to btrace_config_pt.
authorFelix Willgerodt <felix.willgerodt@intel.com>
Tue, 21 Jul 2020 09:12:08 +0000 (11:12 +0200)
committerFelix Willgerodt <felix.willgerodt@intel.com>
Wed, 14 Aug 2024 09:20:56 +0000 (11:20 +0200)
This enables gdb and gdbserver to communicate about ptwrite support.  If
ptwrite support would be enabled unconditionally, GDBs with older libipt
versions would break.

Approved-By: Markus Metzger <markus.t.metzger@intel.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
gdb/doc/gdb.texinfo
gdb/features/btrace-conf.dtd
gdb/remote.c
gdbserver/linux-low.cc
gdbserver/server.cc
gdbsupport/btrace-common.h

index 09eef92c5b12c9b108b9aca50e401acd61165ec0..7938b0799f9a0a05b2a4a15e2547efd73efc313c 100644 (file)
@@ -44807,6 +44807,11 @@ These are the currently defined stub features and their properties:
 @tab @samp{-}
 @tab Yes
 
+@item @samp{Qbtrace-conf:pt:ptwrite}
+@tab Yes
+@tab @samp{-}
+@tab Yes
+
 @item @samp{QNonStop}
 @tab No
 @tab @samp{-}
@@ -45128,6 +45133,9 @@ The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
 @item Qbtrace-conf:pt:size
 The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
 
+@item Qbtrace-conf:pt:ptwrite
+The remote stub understands the @samp{Qbtrace-conf:pt:ptwrite} packet.
+
 @item swbreak
 The remote stub reports the @samp{swbreak} stop reason for memory
 breakpoints.
@@ -45617,6 +45625,18 @@ Reply:
 The ring buffer size has been set.
 @end table
 
+@item Qbtrace-conf:pt:ptwrite=@var{(yes|no)}
+Indicate support for @code{PTWRITE} packets.  This allows for backwards
+compatibility.
+
+Reply:
+@table @samp
+@item OK
+The ptwrite config parameter has been set.
+@item E.errtext
+A badly formed request or an error was encountered.
+@end table
+
 @end table
 
 @node Architecture-Specific Protocol Details
@@ -48258,6 +48278,7 @@ The formal DTD for the branch trace configuration format is given below:
 
 <!ELEMENT pt   EMPTY>
 <!ATTLIST pt   size    CDATA   #IMPLIED>
+<!ATTLIST pt   ptwrite (yes | no)      #IMPLIED>
 @end smallexample
 
 @include agentexpr.texi
index 57300eac90a4d36243cf70b783c54afdc5cebfc0..87a4a843cc207c69d1239d435b9aa607adb03f48 100644 (file)
@@ -12,3 +12,4 @@
 
 <!ELEMENT pt   EMPTY>
 <!ATTLIST pt   size    CDATA   #IMPLIED>
+<!ATTLIST pt   ptwrite (yes | no) #IMPLIED>
index ba304712bea26efa37ee289667d58f64529af15e..2c3988cb5075655e8a799d1cc5d4760ad8ed426e 100644 (file)
@@ -361,6 +361,9 @@ enum {
   /* Support for the Qbtrace-conf:pt:size packet.  */
   PACKET_Qbtrace_conf_pt_size,
 
+  /* Support for the Qbtrace-conf:pt:ptwrite packet.  */
+  PACKET_Qbtrace_conf_pt_ptwrite,
+
   /* Support for exec events.  */
   PACKET_exec_event_feature,
 
@@ -5810,6 +5813,8 @@ static const struct protocol_feature remote_protocol_features[] = {
     PACKET_exec_event_feature },
   { "Qbtrace-conf:pt:size", PACKET_DISABLE, remote_supported_packet,
     PACKET_Qbtrace_conf_pt_size },
+  { "Qbtrace-conf:pt:ptwrite", PACKET_DISABLE, remote_supported_packet,
+    PACKET_Qbtrace_conf_pt_ptwrite },
   { "vContSupported", PACKET_DISABLE, remote_supported_packet, PACKET_vContSupported },
   { "QThreadEvents", PACKET_DISABLE, remote_supported_packet, PACKET_QThreadEvents },
   { "QThreadOptions", PACKET_DISABLE, remote_supported_thread_options,
@@ -14736,7 +14741,7 @@ parse_xml_btrace_conf_pt (struct gdb_xml_parser *parser,
                          std::vector<gdb_xml_value> &attributes)
 {
   struct btrace_config *conf;
-  struct gdb_xml_value *size;
+  struct gdb_xml_value *size, *ptwrite;
 
   conf = (struct btrace_config *) user_data;
   conf->format = BTRACE_FORMAT_PT;
@@ -14745,10 +14750,16 @@ parse_xml_btrace_conf_pt (struct gdb_xml_parser *parser,
   size = xml_find_attribute (attributes, "size");
   if (size != NULL)
     conf->pt.size = (unsigned int) *(ULONGEST *) size->value.get ();
+
+  ptwrite = xml_find_attribute (attributes, "ptwrite");
+  if (ptwrite != nullptr)
+    conf->pt.ptwrite = (bool) *(ULONGEST *) ptwrite->value.get ();
 }
 
 static const struct gdb_xml_attribute btrace_conf_pt_attributes[] = {
   { "size", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL },
+  { "ptwrite", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_enum,
+    gdb_xml_enums_boolean },
   { NULL, GDB_XML_AF_NONE, NULL, NULL }
 };
 
@@ -14854,6 +14865,32 @@ remote_target::btrace_sync_conf (const btrace_config *conf)
 
       rs->btrace_config.pt.size = conf->pt.size;
     }
+
+  if ((m_features.packet_support (PACKET_Qbtrace_conf_pt_ptwrite)
+       == PACKET_ENABLE)
+       && conf->pt.ptwrite != rs->btrace_config.pt.ptwrite)
+    {
+      pos = buf;
+      const char *ptw = conf->pt.ptwrite ? "yes" : "no";
+      const char *name
+       = packets_descriptions[PACKET_Qbtrace_conf_pt_ptwrite].name;
+      pos += xsnprintf (pos, endbuf - pos, "%s=\"%s\"", name, ptw);
+
+      putpkt (buf);
+      getpkt (&rs->buf, 0);
+
+      packet_result result
+       = m_features.packet_ok (buf, PACKET_Qbtrace_conf_pt_ptwrite);
+      if (result.status () == PACKET_ERROR)
+       {
+         if (buf[0] == 'E' && buf[1] == '.')
+           error (_("Failed to sync ptwrite config: %s"), buf + 2);
+         else
+           error (_("Failed to sync ptwrite config."));
+       }
+
+      rs->btrace_config.pt.ptwrite = conf->pt.ptwrite;
+    }
 }
 
 /* Read TP's btrace configuration from the target and store it into CONF.  */
@@ -16308,6 +16345,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
   add_packet_config_cmd (PACKET_Qbtrace_conf_pt_size, "Qbtrace-conf:pt:size",
                         "btrace-conf-pt-size", 0);
 
+  add_packet_config_cmd (PACKET_Qbtrace_conf_pt_ptwrite, "Qbtrace-conf:pt:ptwrite",
+                        "btrace-conf-pt-ptwrite", 0);
+
   add_packet_config_cmd (PACKET_vContSupported, "vContSupported",
                         "verbose-resume-supported", 0);
 
index 266c7de8fb8bc810f9a7e1c52058dda30005e809..193d851af097a88efa9482c3f3b395286ea8e30f 100644 (file)
@@ -6968,6 +6968,9 @@ linux_process_target::read_btrace_conf (const btrace_target_info *tinfo,
          string_xml_appendf (*buffer, "<pt");
          string_xml_appendf (*buffer, " size=\"0x%x\"", conf->pt.size);
          string_xml_appendf (*buffer, "/>\n");
+         string_xml_appendf (*buffer, " ptwrite=\"%s\"",
+                            conf->pt.ptwrite ? "yes" : "no");
+         string_xml_appendf (*buffer, "/>\n");
          break;
        }
     }
index 87b2a26772117a975d4ac2aa64d3d41133acc85c..7c2973df000cd320f73415fbaf8eb0229e79bdfa 100644 (file)
@@ -537,6 +537,19 @@ handle_btrace_conf_general_set (char *own_buf)
 
       current_btrace_conf.pt.size = (unsigned int) size;
     }
+  else if (strncmp (op, "pt:ptwrite=", strlen ("pt:ptwrite=")) == 0)
+    {
+      op += strlen ("pt:ptwrite=");
+      if (strncmp (op, "\"yes\"", strlen ("\"yes\"")) == 0)
+       current_btrace_conf.pt.ptwrite = true;
+      else if (strncmp (op, "\"no\"", strlen ("\"no\"")) == 0)
+       current_btrace_conf.pt.ptwrite = false;
+      else
+       {
+         strcpy (own_buf, "E.Bad ptwrite value.");
+         return -1;
+       }
+    }
   else
     {
       strcpy (own_buf, "E.Bad Qbtrace configuration option.");
@@ -2484,6 +2497,7 @@ supported_btrace_packets (char *buf)
   strcat (buf, ";Qbtrace-conf:bts:size+");
   strcat (buf, ";Qbtrace:pt+");
   strcat (buf, ";Qbtrace-conf:pt:size+");
+  strcat (buf, ";Qbtrace-conf:pt:ptwrite+");
   strcat (buf, ";Qbtrace:off+");
   strcat (buf, ";qXfer:btrace:read+");
   strcat (buf, ";qXfer:btrace-conf:read+");
index bf57bc1615ea0c75aabf69d71ef058655bb39c3d..967c673ed800b78bc45055f3d05a9c43ffd4b837 100644 (file)
@@ -117,6 +117,12 @@ struct btrace_config_pt
      This is unsigned int and not size_t since it is registered as
      control variable for "set record btrace pt buffer-size".  */
   unsigned int size;
+
+  /* Configuration bit for ptwrite packets.
+
+     If both gdb and gdbserver support this, gdb will try to enable ptwrite
+     packets when tracing is started.  */
+  bool ptwrite;
 };
 
 /* A branch tracing configuration.