[3/7] btrace: Enable event tracing on Linux for Intel PT.

Message ID 20240902114949.918485-4-felix.willgerodt@intel.com
State New
Headers
Series btrace: Intel PT event tracing support |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Felix Willgerodt Sept. 2, 2024, 11:49 a.m. UTC
  Event tracing allows GDB to show information about interesting asyncronous
events when tracing with Intel PT.  Subsequent patches will add support for
displaying each type of event.

Enabling event-tracing unconditionally would result in rather noisy output, as
breakpoints themselves result in interrupt events.  Which is why this patch adds
a set/show command to allow the user to enable/disable event-tracing before
starting a recording. The event-tracing setting has no effect on an already
active recording.  The default setting is off.   As event tracing will use the
auxiliary infrastructure added by ptwrite, the user can still disable printing
events, even when event-tracing was enabled, by using the /a switch for the
record instruction-history/function-call-history commands.
---
 gdb/doc/gdb.texinfo          | 41 +++++++++++++++++++++++++----
 gdb/features/btrace-conf.dtd |  1 +
 gdb/nat/linux-btrace.c       | 11 ++++++++
 gdb/record-btrace.c          | 44 +++++++++++++++++++++++++++++++
 gdb/remote.c                 | 50 +++++++++++++++++++++++++++++++++++-
 gdbserver/linux-low.cc       |  2 ++
 gdbserver/server.cc          | 14 ++++++++++
 gdbsupport/btrace-common.h   |  3 +++
 8 files changed, 160 insertions(+), 6 deletions(-)
  

Comments

Eli Zaretskii Sept. 2, 2024, 12:09 p.m. UTC | #1
> From: Felix Willgerodt <felix.willgerodt@intel.com>
> Date: Mon,  2 Sep 2024 13:49:45 +0200
> 
> Event tracing allows GDB to show information about interesting asyncronous
                                                                 ^^^^^^^^^^^
Typo.

>  gdb/doc/gdb.texinfo          | 41 +++++++++++++++++++++++++----
>  gdb/features/btrace-conf.dtd |  1 +
>  gdb/nat/linux-btrace.c       | 11 ++++++++
>  gdb/record-btrace.c          | 44 +++++++++++++++++++++++++++++++
>  gdb/remote.c                 | 50 +++++++++++++++++++++++++++++++++++-
>  gdbserver/linux-low.cc       |  2 ++
>  gdbserver/server.cc          | 14 ++++++++++
>  gdbsupport/btrace-common.h   |  3 +++
>  8 files changed, 160 insertions(+), 6 deletions(-)

Thanks, the documentation parts are OK.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
  
Eli Zaretskii Sept. 2, 2024, 12:10 p.m. UTC | #2
> Date: Mon, 02 Sep 2024 15:09:12 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: gdb-patches@sourceware.org, markus.t.metzger@intel.com
> 
> > From: Felix Willgerodt <felix.willgerodt@intel.com>
> > Date: Mon,  2 Sep 2024 13:49:45 +0200
> > 
> > Event tracing allows GDB to show information about interesting asyncronous
>                                                                  ^^^^^^^^^^^
> Typo.
> 
> >  gdb/doc/gdb.texinfo          | 41 +++++++++++++++++++++++++----
> >  gdb/features/btrace-conf.dtd |  1 +
> >  gdb/nat/linux-btrace.c       | 11 ++++++++
> >  gdb/record-btrace.c          | 44 +++++++++++++++++++++++++++++++
> >  gdb/remote.c                 | 50 +++++++++++++++++++++++++++++++++++-
> >  gdbserver/linux-low.cc       |  2 ++
> >  gdbserver/server.cc          | 14 ++++++++++
> >  gdbsupport/btrace-common.h   |  3 +++
> >  8 files changed, 160 insertions(+), 6 deletions(-)
> 
> Thanks, the documentation parts are OK.

Actually, one question: should this be mentioned in NEWS?
  
Felix Willgerodt Sept. 2, 2024, 1:32 p.m. UTC | #3
> -----Original Message-----
> From: Eli Zaretskii <eliz@gnu.org>
> Sent: Montag, 2. September 2024 14:11
> To: Willgerodt, Felix <felix.willgerodt@intel.com>
> Cc: gdb-patches@sourceware.org; Metzger, Markus T
> <markus.t.metzger@intel.com>
> Subject: Re: [PATCH 3/7] btrace: Enable event tracing on Linux for Intel PT.
> 
> > Date: Mon, 02 Sep 2024 15:09:12 +0300
> > From: Eli Zaretskii <eliz@gnu.org>
> > Cc: gdb-patches@sourceware.org, markus.t.metzger@intel.com
> >
> > > From: Felix Willgerodt <felix.willgerodt@intel.com>
> > > Date: Mon,  2 Sep 2024 13:49:45 +0200
> > >
> > > Event tracing allows GDB to show information about interesting asyncronous
> >                                                                  ^^^^^^^^^^^
> > Typo.
> >
> > >  gdb/doc/gdb.texinfo          | 41 +++++++++++++++++++++++++----
> > >  gdb/features/btrace-conf.dtd |  1 +
> > >  gdb/nat/linux-btrace.c       | 11 ++++++++
> > >  gdb/record-btrace.c          | 44 +++++++++++++++++++++++++++++++
> > >  gdb/remote.c                 | 50 +++++++++++++++++++++++++++++++++++-
> > >  gdbserver/linux-low.cc       |  2 ++
> > >  gdbserver/server.cc          | 14 ++++++++++
> > >  gdbsupport/btrace-common.h   |  3 +++
> > >  8 files changed, 160 insertions(+), 6 deletions(-)
> >
> > Thanks, the documentation parts are OK.
> 
> Actually, one question: should this be mentioned in NEWS?

Hi Eli,

Thanks for the review, I have fixed the typo locally. And yes, this probably warrants
a NEWS entry. I have written this now in my local branch:

diff --git a/gdb/NEWS b/gdb/NEWS
index 2f5d5ebbcef..8f45593cf02 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,11 @@
 
 *** Changes since GDB 15
 
+* GDB now supports printing of asynchronous events from the Intel Processor
+  Trace during 'record instruction-history', 'record function-call-history'
+  and all stepping commands.  This can be controlled with the new
+  "set record btrace pt event-tracing" command.
+
 * GDB now supports printing of ptwrite payloads from the Intel Processor
   Trace during 'record instruction-history', 'record function-call-history'
   and all stepping commands.  The payload is also accessible in Python as a

Regards,
Felix

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  
Eli Zaretskii Sept. 2, 2024, 1:41 p.m. UTC | #4
> From: "Willgerodt, Felix" <felix.willgerodt@intel.com>
> CC: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>, "Metzger,
>  Markus T" <markus.t.metzger@intel.com>
> Date: Mon, 2 Sep 2024 13:32:46 +0000
> 
> Thanks for the review, I have fixed the typo locally. And yes, this probably warrants
> a NEWS entry. I have written this now in my local branch:
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 2f5d5ebbcef..8f45593cf02 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,11 @@
>  
>  *** Changes since GDB 15
>  
> +* GDB now supports printing of asynchronous events from the Intel Processor
> +  Trace during 'record instruction-history', 'record function-call-history'
> +  and all stepping commands.  This can be controlled with the new
> +  "set record btrace pt event-tracing" command.
> +
>  * GDB now supports printing of ptwrite payloads from the Intel Processor
>    Trace during 'record instruction-history', 'record function-call-history'
>    and all stepping commands.  The payload is also accessible in Python as a

LGTM, thanks.
  
Metzger, Markus T Sept. 10, 2024, 10:48 a.m. UTC | #5
Hello Felix,

>+  if (conf->event_tracing)
>+    {
>+      if (linux_supports_pt_feature ("event_trace"))
>+	{
>+	  tinfo->attr.config |= linux_read_pt_config_bitmask ("event");
>+	  tinfo->conf.pt.event_tracing = conf->event_tracing;

We know that conf->event_tracing is true, here; we checked it above.

>+	}
>+      else
>+	error (_("Event tracing for record btrace pt is not supported."));

Have you checked that this correctly results in the 'record btrace' command
getting aborted in the remote debug scenario?


>+static bool event_tracing = false;
>+
>+/* The "record pt event-tracing" show value function.  */
>+
>+static void
>+show_record_pt_event_tracing_value (struct ui_file *file, int from_tty,
>+				    struct cmd_list_element *c,
>+				    const char *value)
>+{
>+#if (LIBIPT_VERSION >= 0x201)
>+  gdb_printf (file, _("record pt event-tracing is %s.\n"), value);
>+#else
>+  gdb_printf (_("Event-tracing support was disabled at compile time.\n"));
>+#endif /* defined (LIBIPT_VERSION >= 0x201) */

I'm wondering if it is clear that GDB's compile-time is meant here.  Maybe
something like 'Event tracing is not supported by GDB.' or 'Event tracing
support has been disabled in GDB.' would be clearer.

We use a similar phrase in gdb/btrace.c to indicate lack of PT support, but it
is more difficult to change existing strings, so I'm not sure whether it makes
sense to adjust that one, too.

>+  /* Event tracing is a user setting, warn if it is set but the target
>+     doesn't support it.  */
>+  if ((m_features.packet_support (PACKET_Qbtrace_conf_pt_event_tracing)
>+       != PACKET_ENABLE)
>+	&& conf->pt.event_tracing)
>+    error (_("Target does not support event-tracing."));

The comment says warn, but the code errors out.

Regards,
Markus.

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  
Felix Willgerodt Sept. 11, 2024, 2:45 p.m. UTC | #6
> -----Original Message-----
> From: Metzger, Markus T <markus.t.metzger@intel.com>
> Sent: Dienstag, 10. September 2024 12:48
> To: Willgerodt, Felix <felix.willgerodt@intel.com>
> Cc: gdb-patches@sourceware.org
> Subject: RE: [PATCH 3/7] btrace: Enable event tracing on Linux for Intel PT.
> 
> Hello Felix,
> 
> >+  if (conf->event_tracing)
> >+    {
> >+      if (linux_supports_pt_feature ("event_trace"))
> >+	{
> >+	  tinfo->attr.config |= linux_read_pt_config_bitmask ("event");
> >+	  tinfo->conf.pt.event_tracing = conf->event_tracing;
> 
> We know that conf->event_tracing is true, here; we checked it above.

Fixed locally.

> >+	}
> >+      else
> >+	error (_("Event tracing for record btrace pt is not supported."));
> 
> Have you checked that this correctly results in the 'record btrace' command
> getting aborted in the remote debug scenario?

I tested it both on the same host and on two different machines.
This is the behaviour for both:

0x00007ffff7fe3290 in _start () from target:/lib64/ld-linux-x86-64.so.2
(gdb) set record btrace pt event-tracing on
(gdb) rec pt
Could not enable branch tracing for Thread 537568.537568: Event tracing for record btrace pt is not supported.
(gdb)  

This looks correct to me.

> >+static bool event_tracing = false;
> >+
> >+/* The "record pt event-tracing" show value function.  */
> >+
> >+static void
> >+show_record_pt_event_tracing_value (struct ui_file *file, int from_tty,
> >+				    struct cmd_list_element *c,
> >+				    const char *value)
> >+{
> >+#if (LIBIPT_VERSION >= 0x201)
> >+  gdb_printf (file, _("record pt event-tracing is %s.\n"), value);
> >+#else
> >+  gdb_printf (_("Event-tracing support was disabled at compile time.\n"));
> >+#endif /* defined (LIBIPT_VERSION >= 0x201) */
> 
> I'm wondering if it is clear that GDB's compile-time is meant here.  Maybe
> something like 'Event tracing is not supported by GDB.' or 'Event tracing
> support has been disabled in GDB.' would be clearer.
> 
> We use a similar phrase in gdb/btrace.c to indicate lack of PT support, but it
> is more difficult to change existing strings, so I'm not sure whether it makes
> sense to adjust that one, too.

You make a good point, I just copied it but never liked it either. I will use
'Event tracing is not supported by GDB.'.

> >+  /* Event tracing is a user setting, warn if it is set but the target
> >+     doesn't support it.  */
> >+  if ((m_features.packet_support (PACKET_Qbtrace_conf_pt_event_tracing)
> >+       != PACKET_ENABLE)
> >+	&& conf->pt.event_tracing)
> >+    error (_("Target does not support event-tracing."));
> 
> The comment says warn, but the code errors out.

I will make it a warning.

Thanks,
Felix
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  
Metzger, Markus T Sept. 11, 2024, 3:19 p.m. UTC | #7
Hello Felix,

>> >+	}
>> >+      else
>> >+	error (_("Event tracing for record btrace pt is not supported."));
>>
>> Have you checked that this correctly results in the 'record btrace' command
>> getting aborted in the remote debug scenario?
>
>I tested it both on the same host and on two different machines.
>This is the behaviour for both:
>
>0x00007ffff7fe3290 in _start () from target:/lib64/ld-linux-x86-64.so.2
>(gdb) set record btrace pt event-tracing on
>(gdb) rec pt
>Could not enable branch tracing for Thread 537568.537568: Event tracing for
>record btrace pt is not supported.
>(gdb)
>
>This looks correct to me.

This looks good.

Thanks,
Markus.

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  

Patch

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 8cde2f22637..63281141363 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -8116,6 +8116,16 @@  also need longer to process the branch trace data before it can be used.
 Show the current setting of the requested ring buffer size for branch
 tracing in Intel Processor Trace format.
 
+@item set record btrace pt event-tracing
+Enable or disable event tracing for branch tracing in Intel Processor
+Trace format.  When enabled, events are recorded during execution as
+auxiliary information and will be printed during stepping commands and
+commands displaying the execution history.  Changing this setting has no
+effect on an active recording.  The default is off.
+
+@item show record btrace pt event-tracing
+Show the current setting of Intel Processor Trace event tracing.
+
 @kindex info record
 @item info record
 Show various statistics about the recording depending on the recording
@@ -44983,6 +44993,11 @@  These are the currently defined stub features and their properties:
 @tab @samp{-}
 @tab Yes
 
+@item @samp{Qbtrace-conf:pt:event-tracing}
+@tab Yes
+@tab @samp{-}
+@tab Yes
+
 @item @samp{QNonStop}
 @tab No
 @tab @samp{-}
@@ -45307,6 +45322,9 @@  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 Qbtrace-conf:pt:event-tracing
+The remote stub understands the @samp{Qbtrace-conf:pt:event-tracing} packet.
+
 @item swbreak
 The remote stub reports the @samp{swbreak} stop reason for memory
 breakpoints.
@@ -45808,6 +45826,18 @@  The ptwrite config parameter has been set.
 A badly formed request or an error was encountered.
 @end table
 
+@item Qbtrace-conf:pt:event-tracing=@var{(yes|no)}
+Indicate support for event-tracing packets.  This allows for backwards
+compatibility.
+
+Reply:
+@table @samp
+@item OK
+The event-tracing 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
@@ -48441,15 +48471,16 @@  branch trace configuration discovery.  @xref{Expat}.
 The formal DTD for the branch trace configuration format is given below:
 
 @smallexample
-<!ELEMENT btrace-conf	(bts?, pt?)>
-<!ATTLIST btrace-conf	version	CDATA	#FIXED "1.0">
+<!ELEMENT btrace-conf		(bts?, pt?)>
+<!ATTLIST btrace-conf		version	CDATA	#FIXED "1.0">
 
 <!ELEMENT bts	EMPTY>
-<!ATTLIST bts	size	CDATA	#IMPLIED>
+<!ATTLIST bts	size		CDATA	#IMPLIED>
 
 <!ELEMENT pt	EMPTY>
-<!ATTLIST pt	size	CDATA	#IMPLIED>
-<!ATTLIST pt	ptwrite	(yes | no)	#IMPLIED>
+<!ATTLIST pt	size		CDATA	#IMPLIED>
+<!ATTLIST pt	ptwrite		(yes | no)	#IMPLIED>
+<!ATTLIST pt	event-tracing	(yes | no)	#IMPLIED>
 @end smallexample
 
 @include agentexpr.texi
diff --git a/gdb/features/btrace-conf.dtd b/gdb/features/btrace-conf.dtd
index 87a4a843cc2..c6f3f609d00 100644
--- a/gdb/features/btrace-conf.dtd
+++ b/gdb/features/btrace-conf.dtd
@@ -13,3 +13,4 @@ 
 <!ELEMENT pt	EMPTY>
 <!ATTLIST pt	size	CDATA	#IMPLIED>
 <!ATTLIST pt	ptwrite	(yes | no) #IMPLIED>
+<!ATTLIST pt	event-tracing	(yes | no)	#IMPLIED>
diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
index 59e8ae6bef6..7c90d62c8d0 100644
--- a/gdb/nat/linux-btrace.c
+++ b/gdb/nat/linux-btrace.c
@@ -686,6 +686,17 @@  linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf)
       tinfo->conf.pt.ptwrite = true;
     }
 
+  if (conf->event_tracing)
+    {
+      if (linux_supports_pt_feature ("event_trace"))
+	{
+	  tinfo->attr.config |= linux_read_pt_config_bitmask ("event");
+	  tinfo->conf.pt.event_tracing = conf->event_tracing;
+	}
+      else
+	error (_("Event tracing for record btrace pt is not supported."));
+    }
+
   errno = 0;
   scoped_fd fd (syscall (SYS_perf_event_open, &tinfo->attr, pid, -1, -1, 0));
   if (fd.get () < 0)
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 997f442af55..20f30a1912c 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -3180,6 +3180,36 @@  show_record_pt_buffer_size_value (struct ui_file *file, int from_tty,
 	      value);
 }
 
+
+static bool event_tracing = false;
+
+/* The "record pt event-tracing" show value function.  */
+
+static void
+show_record_pt_event_tracing_value (struct ui_file *file, int from_tty,
+				    struct cmd_list_element *c,
+				    const char *value)
+{
+#if (LIBIPT_VERSION >= 0x201)
+  gdb_printf (file, _("record pt event-tracing is %s.\n"), value);
+#else
+  gdb_printf (_("Event-tracing support was disabled at compile time.\n"));
+#endif /* defined (LIBIPT_VERSION >= 0x201) */
+}
+
+/* The "record pt event-tracing" set value function.  */
+
+static void
+set_record_pt_event_tracing_value (const char *args, int from_tty,
+				   cmd_list_element *c)
+{
+#if (LIBIPT_VERSION >= 0x201)
+  record_btrace_conf.pt.event_tracing = event_tracing;
+#else
+  gdb_printf (_("Event-tracing support was disabled at compile time.\n"));
+#endif /* defined (LIBIPT_VERSION >= 0x201) */
+}
+
 /* Initialize btrace commands.  */
 
 void _initialize_record_btrace ();
@@ -3299,6 +3329,19 @@  to see the actual buffer size."), NULL, show_record_pt_buffer_size_value,
 			    &set_record_btrace_pt_cmdlist,
 			    &show_record_btrace_pt_cmdlist);
 
+  add_setshow_boolean_cmd ("event-tracing", no_class, &event_tracing,
+			   _("Set event-tracing for record pt."),
+			   _("Show event-tracing for record pt."),
+			   _("\
+Use \"on\" to enable event tracing for recordings with Intel Processor Trace,  \
+and \"off\" to disable it.\n\
+Without an argument, event tracing is enabled.  Changing this setting has no\
+effect on an active recording."),
+			   set_record_pt_event_tracing_value,
+			   show_record_pt_event_tracing_value,
+			   &set_record_btrace_pt_cmdlist,
+			   &show_record_btrace_pt_cmdlist);
+
   add_target (record_btrace_target_info, record_btrace_target_open);
 
   bfcache = htab_create_alloc (50, bfcache_hash, bfcache_eq, NULL,
@@ -3311,4 +3354,5 @@  to see the actual buffer size."), NULL, show_record_pt_buffer_size_value,
 #else
   record_btrace_conf.pt.ptwrite = false;
 #endif
+  record_btrace_conf.pt.event_tracing = false;
 }
diff --git a/gdb/remote.c b/gdb/remote.c
index 2c3988cb507..d76ad4567f7 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -364,6 +364,9 @@  enum {
   /* Support for the Qbtrace-conf:pt:ptwrite packet.  */
   PACKET_Qbtrace_conf_pt_ptwrite,
 
+  /* Support for the Qbtrace-conf:pt:event-tracing packet.  */
+  PACKET_Qbtrace_conf_pt_event_tracing,
+
   /* Support for exec events.  */
   PACKET_exec_event_feature,
 
@@ -5815,6 +5818,8 @@  static const struct protocol_feature remote_protocol_features[] = {
     PACKET_Qbtrace_conf_pt_size },
   { "Qbtrace-conf:pt:ptwrite", PACKET_DISABLE, remote_supported_packet,
     PACKET_Qbtrace_conf_pt_ptwrite },
+  { "Qbtrace-conf:pt:event-tracing", PACKET_DISABLE, remote_supported_packet,
+    PACKET_Qbtrace_conf_pt_event_tracing },
   { "vContSupported", PACKET_DISABLE, remote_supported_packet, PACKET_vContSupported },
   { "QThreadEvents", PACKET_DISABLE, remote_supported_packet, PACKET_QThreadEvents },
   { "QThreadOptions", PACKET_DISABLE, remote_supported_thread_options,
@@ -14741,7 +14746,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, *ptwrite;
+  struct gdb_xml_value *size, *ptwrite, *event_tracing;
 
   conf = (struct btrace_config *) user_data;
   conf->format = BTRACE_FORMAT_PT;
@@ -14754,12 +14759,18 @@  parse_xml_btrace_conf_pt (struct gdb_xml_parser *parser,
   ptwrite = xml_find_attribute (attributes, "ptwrite");
   if (ptwrite != nullptr)
     conf->pt.ptwrite = (bool) *(ULONGEST *) ptwrite->value.get ();
+
+  event_tracing = xml_find_attribute (attributes, "event-tracing");
+  if (event_tracing != nullptr)
+    conf->pt.event_tracing = (bool) *(ULONGEST *) event_tracing->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 },
+  { "event-tracing", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_enum,
+    gdb_xml_enums_boolean },
   { NULL, GDB_XML_AF_NONE, NULL, NULL }
 };
 
@@ -14891,6 +14902,39 @@  remote_target::btrace_sync_conf (const btrace_config *conf)
 
       rs->btrace_config.pt.ptwrite = conf->pt.ptwrite;
     }
+
+  /* Event tracing is a user setting, warn if it is set but the target
+     doesn't support it.  */
+  if ((m_features.packet_support (PACKET_Qbtrace_conf_pt_event_tracing)
+       != PACKET_ENABLE)
+	&& conf->pt.event_tracing)
+    error (_("Target does not support event-tracing."));
+
+  if ((m_features.packet_support (PACKET_Qbtrace_conf_pt_event_tracing)
+       == PACKET_ENABLE)
+	&& conf->pt.event_tracing != rs->btrace_config.pt.event_tracing)
+    {
+      pos = buf;
+      const char *event_tracing = conf->pt.event_tracing ? "yes" : "no";
+      const char *name
+	= packets_descriptions[PACKET_Qbtrace_conf_pt_event_tracing].name;
+      pos += xsnprintf (pos, endbuf - pos, "%s=\"%s\"", name, event_tracing);
+
+      putpkt (buf);
+      getpkt (&rs->buf, 0);
+
+      packet_result result
+	= m_features.packet_ok (buf, PACKET_Qbtrace_conf_pt_event_tracing);
+      if (result.status () == PACKET_ERROR)
+	{
+	  if (buf[0] == 'E' && buf[1] == '.')
+	    error (_("Failed to sync event-tracing config: %s"), buf + 2);
+	  else
+	    error (_("Failed to sync event-tracing config."));
+	}
+
+      rs->btrace_config.pt.event_tracing = conf->pt.event_tracing;
+    }
 }
 
 /* Read TP's btrace configuration from the target and store it into CONF.  */
@@ -16348,6 +16392,10 @@  Show the maximum size of the address (in bits) in a memory packet."), NULL,
   add_packet_config_cmd (PACKET_Qbtrace_conf_pt_ptwrite, "Qbtrace-conf:pt:ptwrite",
 			 "btrace-conf-pt-ptwrite", 0);
 
+  add_packet_config_cmd (PACKET_Qbtrace_conf_pt_event_tracing,
+			 "Qbtrace-conf:pt:event-tracing",
+			 "btrace-conf-pt-event-tracing", 0);
+
   add_packet_config_cmd (PACKET_vContSupported, "vContSupported",
 			 "verbose-resume-supported", 0);
 
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index 193d851af09..79512c07a22 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -6970,6 +6970,8 @@  linux_process_target::read_btrace_conf (const btrace_target_info *tinfo,
 	  string_xml_appendf (*buffer, "/>\n");
 	  string_xml_appendf (*buffer, " ptwrite=\"%s\"",
 			     conf->pt.ptwrite ? "yes" : "no");
+	  string_xml_appendf (*buffer, " event-tracing=\"%s\"",
+			     conf->pt.event_tracing ? "yes" : "no");
 	  string_xml_appendf (*buffer, "/>\n");
 	  break;
 	}
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index ee537760cfe..2c1e7cb15a7 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -550,6 +550,19 @@  handle_btrace_conf_general_set (char *own_buf)
 	  return -1;
 	}
     }
+  else if (strncmp (op, "pt:event-tracing=", strlen ("pt:event-tracing=")) == 0)
+    {
+      op += strlen ("pt:event-tracing=");
+      if (strncmp (op, "\"yes\"", strlen ("\"yes\"")) == 0)
+	current_btrace_conf.pt.event_tracing = true;
+      else if (strncmp (op, "\"no\"", strlen ("\"no\"")) == 0)
+	current_btrace_conf.pt.event_tracing = false;
+      else
+	{
+	  strcpy (own_buf, "E.Bad event-tracing value.");
+	  return -1;
+	}
+    }
   else
     {
       strcpy (own_buf, "E.Bad Qbtrace configuration option.");
@@ -2498,6 +2511,7 @@  supported_btrace_packets (char *buf)
   strcat (buf, ";Qbtrace:pt+");
   strcat (buf, ";Qbtrace-conf:pt:size+");
   strcat (buf, ";Qbtrace-conf:pt:ptwrite+");
+  strcat (buf, ";Qbtrace-conf:pt:event-tracing+");
   strcat (buf, ";Qbtrace:off+");
   strcat (buf, ";qXfer:btrace:read+");
   strcat (buf, ";qXfer:btrace-conf:read+");
diff --git a/gdbsupport/btrace-common.h b/gdbsupport/btrace-common.h
index 967c673ed80..490a176c297 100644
--- a/gdbsupport/btrace-common.h
+++ b/gdbsupport/btrace-common.h
@@ -123,6 +123,9 @@  struct btrace_config_pt
      If both gdb and gdbserver support this, gdb will try to enable ptwrite
      packets when tracing is started.  */
   bool ptwrite;
+
+  /* Event tracing setting.  */
+  bool event_tracing;
 };
 
 /* A branch tracing configuration.