btrace: Enable event tracing on Linux for Intel PT.

Event tracing allows GDB to show information about interesting asynchronous
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.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Markus Metzger <markus.t.metzger@intel.com>
This commit is contained in:
Felix Willgerodt
2023-06-28 10:15:04 +02:00
parent 48bc2f1c65
commit 13b3a89bc2
9 changed files with 165 additions and 6 deletions

View File

@@ -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)
warning (_("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);