From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8fxMB16j5GoseBQAWB0awg (envelope-from ) for ; Fri, 30 Oct 2026 10:02:06 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=i4miKhgD; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 15C6B378002; Fri, 30 Oct 2026 10:02:06 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id DE0D91E033 for ; Fri, 30 Oct 2026 10:02:02 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 048364BA902C for ; Fri, 30 Oct 2026 14:02:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 048364BA902C Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=i4miKhgD Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by sourceware.org (Postfix) with ESMTPS id 517FE4BAE7C4 for ; Fri, 30 Oct 2026 13:58:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 517FE4BAE7C4 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 517FE4BAE7C4 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793368684; cv=none; b=SGGxGL5Pul4T5NUgp41BlpC1jMNpuOBaPM6nnNQMUzkUoGK+pUFK442/izYQpjXZwSr5L/yR/rgqUM08wnQuG6xG8BNdZuy5JxpEB7gRvcRLPolejk0O1JgaFpMnO6r2gzbpwuidwj9WmaargGtZTJasm126X0Fw2LEvYJxCfDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793368684; c=relaxed/simple; bh=y00l0iumZqKxM57VfflGauj25cBYqYkXw3ZwRCbVoQ0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=f5spYvFqUATRZHOoMJOH47xJG704sDLzV0IQYMdY0k51HnJUF3nurr5PGi5dSHyNm8YTeqHbRV9dBn0qCB8rnNcUbk+kzzZkLiH3jFMO4WAXulXEr61fbgEH3+qiE4zk7ZV81TwF7KQIJJ56ZEgK5wdqkZiPAH2vVCzKsmZJqew= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=i4miKhgD DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 517FE4BAE7C4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1793368685; x=1824904685; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=y00l0iumZqKxM57VfflGauj25cBYqYkXw3ZwRCbVoQ0=; b=i4miKhgDkfwohNopBbZncaOB57ej79KTMVGDg0YBnOPN8DPy3IxfUoJg eC366mzFQjRUGYonXptJPogb3pblqSt3n3kHxp82wmyyY/CuBhO/Hk+uk mlwDj1fvDfzotUwEYnuH3as63aGFZoIW1xuc0/wRKNYR93BwMvjiHwZDp 4c2JN+EyCsP8arRtIgWX8+vCqABqQq8ZNp00k6dg14k1OxPyhFYcVNBWv I238Ot4FsG/hO39KRRNNCt4S9tM24mDNAi8aV1p9XKgaAd+iTLB+KxIzX BR8LC5tuU/hT5eYxD9v+p7HWuZ7rHx9LW/9wWutaJ/aOdxrd5bszfgPST g==; X-CSE-ConnectionGUID: QdQR/dgGQiSzlAhhT3l7wQ== X-CSE-MsgGUID: zUe/rpX6R5CNvfiE9HXJAg== X-IronPort-AV: E=McAfee;i="6800,10657,11951"; a="2011315" X-IronPort-AV: E=Sophos;i="6.27,186,1787036400"; d="scan'208";a="2011315" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2026 06:58:04 -0700 X-CSE-ConnectionGUID: ZpzDELGJQ4K8iXOhnnPPJQ== X-CSE-MsgGUID: lhwD36KvTvmk4zK20m45zg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,186,1787036400"; d="scan'208";a="5331846" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2026 06:58:02 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Subject: [PATCH 5/5] gdb, gdbserver, btrace: resync on error Date: Fri, 30 Oct 2026 14:57:44 +0100 Message-ID: <20261030135744.921562-6-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261030135744.921562-1-markus.t.metzger@intel.com> References: <20261030135744.921562-1-markus.t.metzger@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Starting with libipt version 2.2, we can try to re-synchronize on the next IP-providing packet instead of skipping everything until the next trace stream synchronization packet on CPUs that do not support deferred TIPs. Add a new setting set record btrace pt enhanced-resync on|off to enable that on supported CPUs and extend the qXfer:btrace:read response with a new attribute allow_resync in the pt-config part of the response. This should normally not be needed and the setting defaults to off. When running into decode errors, however, it may help as an advanced option to make the most out of the recorded trace. --- gdb/NEWS | 12 +++++++ gdb/btrace.c | 68 +++++++++++++++++++++++++++++++++----- gdb/doc/gdb.texinfo | 26 +++++++++++++++ gdb/features/btrace.dtd | 1 + gdb/nat/linux-btrace.c | 1 + gdb/record-btrace.c | 57 +++++++++++++++++++++++++++++++- gdb/record-btrace.h | 5 +++ gdb/remote.c | 27 +++++++++++++-- gdbserver/linux-low.cc | 3 +- gdbsupport/btrace-common.h | 6 ++++ 10 files changed, 194 insertions(+), 12 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index cddecf2040e..c582095068a 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -75,6 +75,11 @@ set record btrace pt return-compression on|off show record btrace pt return-compression Enable or disable Intel Processor Trace return compression (default: on). +set record btrace pt enhanced-resync on|off +show record btrace pt enhanced-resync + Enable or disable enhanced decoder synchronization after a trace + decoding error (default: off). + * Changed commands set stop-on-solib-events on|off @@ -92,6 +97,13 @@ info locals Qbtrace-conf:pt:return-compression Configure Intel Processor Trace return-compression settings. +* Changed remote packets + +qXfer:btrace:read + The pt-config part of a pt response may now contain a new attribute + allow_resync to indicate to GDB that enhanced decoder synchronization + after a trace decoding error is supported on this processor. + *** Changes in GDB 18 * Support for the Common Trace Format (CTF) has been removed. GDB now diff --git a/gdb/btrace.c b/gdb/btrace.c index 5c47f9129ae..b1c78075d0f 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -35,7 +35,7 @@ #include "extension.h" #include "gdbarch.h" -/* For maintenance commands. */ +/* For maintenance commands and record_btrace_conf. */ #include "record-btrace.h" #include @@ -1732,6 +1732,40 @@ ftrace_warn_pt (btrace_thread_info *btinfo, pt_insn_decoder *decoder, pt_errstr (pt_errcode (status))); } +#if (LIBIPT_VERSION >= 0x202) +/* Resynchronize at an IP-providing packet, if possible. Returns the + decoder status, which is non-negative on success and negative + otherwise. */ + +static int +ftrace_resync_pt (btrace_thread_info *btinfo, pt_insn_decoder *decoder, + std::vector &gaps) +{ + int status; + + for (;;) + { + status = pt_insn_resync (decoder); + if (status >= 0) + return status; + + if (status != -pte_event_ignored) + break; + + /* This libipt version will HAVE_PT_INSN_EVENT. */ + status = handle_pt_insn_event (btinfo, decoder, gaps); + if (status < 0) + break; + } + + if (status != -pte_eos) + warning (_("Resynchronization error (%d): %s"), status, + pt_errstr (pt_errcode (status))); + + return status; +} +#endif /* (LIBIPT_VERSION >= 0x202) */ + /* Decode the trace and handle events as long as there is no error. Returns the last decoder status. */ @@ -1777,6 +1811,7 @@ ftrace_decode_pt (btrace_thread_info *btinfo, static void ftrace_add_pt (btrace_thread_info *btinfo, + const btrace_data_pt_config *config, pt_insn_decoder *decoder, int *plevel, std::vector &gaps) @@ -1795,13 +1830,30 @@ ftrace_add_pt (btrace_thread_info *btinfo, break; } - status = ftrace_decode_pt (btinfo, decoder, plevel, gaps, status); - if (status == -pte_eos) - break; + for (;;) + { + status = ftrace_decode_pt (btinfo, decoder, plevel, gaps, status); + gdb_assert (status < 0); + if (status == -pte_eos) + return; + + /* Indicate the gap in the trace. */ + btrace_function *bfun = ftrace_new_gap (btinfo, status, gaps); + ftrace_warn_pt (btinfo, decoder, bfun, status); - /* Indicate the gap in the trace. */ - btrace_function *bfun = ftrace_new_gap (btinfo, status, gaps); - ftrace_warn_pt (btinfo, decoder, bfun, status); +#if (LIBIPT_VERSION >= 0x202) + if (record_btrace_conf.pt.enhanced_resync + && config->allow_resync) + status = ftrace_resync_pt (btinfo, decoder, gaps); +#endif + if (status < 0) + { + if (status == -pte_eos) + return; + + break; + } + } } } @@ -1928,7 +1980,7 @@ btrace_compute_ftrace_pt (struct thread_info *tp, error (_("Failed to configure the Intel Processor Trace decoder: " "%s."), pt_errstr (pt_errcode (errcode))); - ftrace_add_pt (btinfo, decoder, &level, gaps); + ftrace_add_pt (btinfo, &btrace->config, decoder, &level, gaps); } catch (const gdb_exception &error) { diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 8cfaffd4fc7..9462dccc205 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -8433,6 +8433,31 @@ overhead and trace size. The default is on. @item show record btrace pt return-compression Show the current setting of Intel Processor Trace return compression. +@item set record btrace pt enhanced-resync +Enable or disable enhanced synchronization. When disabled and trace +decode fails with an error, the decoder synchronizes at the next trace +synchronization packet sequence (PSB+). This provides the initial +decode state for the next trace section. This is a safe option but +may skip a fair amount of trace. + +When enabled and trace decode fails with an error, the decoder +synchronizes at the next packet that provides a full instruction +address on processors that do not use deferred TIP packets. This +usually skips a lot less trace, but it does not allow the decoder to +maintain its decode state, which may lead to subsequent decode errors. + +Most notably, the call stack will not be maintained for direct calls, +which may lead to decode errors when encountering a compressed return. +Disabling return compression avoids that at the cost of increased +trace size and recording overhead. + +The default is off. The setting may be changed at any time. When the +setting is changed, threads stop replaying and trace is re-decoded +with the new setting. + +@item show record btrace pt enhanced-resync +Show the current setting of enhanced synchronization. + @kindex info record @item info record Show various statistics about the recording depending on the recording @@ -49400,6 +49425,7 @@ The formal DTD for the branch trace format is given below: + + cpu = btrace_this_cpu (); + conf->allow_resync = linux_supports_pt_feature ("topa_multiple_entries"); } /* Read branch trace data in Intel Processor Trace format for the thread diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 30cd8c8b2b6..115a954e056 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -186,7 +186,7 @@ static struct async_event_handler *record_btrace_async_inferior_event_handler; static int record_btrace_generating_corefile; /* The current branch trace configuration. */ -static struct btrace_config record_btrace_conf; +btrace_config record_btrace_conf; /* Command list for "record btrace". */ static struct cmd_list_element *record_btrace_cmdlist; @@ -3167,6 +3167,38 @@ set_record_pt_return_compression_value (const char *args, int from_tty, record_btrace_conf.pt.return_compression = return_compression; } +static bool enhanced_resync = false; + +/* The "record pt enhanced-resync" show value function. */ + +static void +show_record_pt_enhanced_resync_value (ui_file *file, int from_tty, + cmd_list_element *c, const char *value) +{ + gdb_printf (file, _("record pt enhanced-resync is %s.\n"), value); +} + +/* The "record pt enhanced-resync" set value function. */ + +static void +set_record_pt_enhanced_resync_value (const char *args, int from_tty, + cmd_list_element *c) +{ +#if (LIBIPT_VERSION >= 0x202) + if (record_btrace_conf.pt.enhanced_resync != enhanced_resync) + { + record_btrace_conf.pt.enhanced_resync = enhanced_resync; + + /* Clear the trace of all threads so we decode with the new + settings. This also stops replaying. */ + for (thread_info &tp : all_non_exited_threads ()) + btrace_clear (&tp); + } +#else + error (_("Enhanced synchronization is not supported by GDB.\n")); +#endif +} + /* Initialize btrace commands. */ INIT_GDB_FILE (record_btrace) @@ -3311,8 +3343,30 @@ has no effect on an active recording. The default is \"on\"."), &set_record_btrace_pt_cmdlist, &show_record_btrace_pt_cmdlist); + add_setshow_boolean_cmd + ("enhanced-resync", no_class, &enhanced_resync, + _("Set enhanced synchronizing after a decode error."), + _("Show enhanced synchronizing after a decode error."), + _("\ +Use \"on\" to enable enhanced synchronization and \"off\" to disable it.\n\n\ +After a trace decoding error, decode synchronizes at special packets (PSB+)\n\ +in the trace stream that supply the initial decode state. This may skip a\n\ +fair amount of trace.\n\ +With this option, the decoder tries to synchronize earlier at packets that\n\ +provide a full instruction address. This usually skips much less trace, but\n\ +may result in subsequent decode errors because the decoder is not able to\n\ +update its state while skipping packets. Disabling return compression may\n\ +help in this situation.\n\n\ +This setting is \"off\" by default and may be changed at any time. When the\n\ +setting changes, stop replaying and re-decode the trace for all threads."), + set_record_pt_enhanced_resync_value, + show_record_pt_enhanced_resync_value, + &set_record_btrace_pt_cmdlist, + &show_record_btrace_pt_cmdlist); + add_target (record_btrace_target_info, record_btrace_target_open); + memset (&record_btrace_conf, 0, sizeof (record_btrace_conf)); record_btrace_conf.bts.size = 64 * 1024; record_btrace_conf.pt.size = 16 * 1024; #if (LIBIPT_VERSION >= 0x200) @@ -3322,4 +3376,5 @@ has no effect on an active recording. The default is \"on\"."), #endif record_btrace_conf.pt.event_tracing = false; record_btrace_conf.pt.return_compression = return_compression; + record_btrace_conf.pt.enhanced_resync = enhanced_resync; } diff --git a/gdb/record-btrace.h b/gdb/record-btrace.h index 99ea0741709..caa17aa7b2b 100644 --- a/gdb/record-btrace.h +++ b/gdb/record-btrace.h @@ -22,6 +22,8 @@ #ifndef GDB_RECORD_BTRACE_H #define GDB_RECORD_BTRACE_H +#include "gdbsupport/btrace-common.h" + /* Push the record_btrace target. */ extern void record_btrace_push_target (void); @@ -29,4 +31,7 @@ extern void record_btrace_push_target (void); NULL if the cpu was configured as auto. */ extern const struct btrace_cpu *record_btrace_get_cpu (void); +/* The current branch trace configuration. */ +extern btrace_config record_btrace_conf; + #endif /* GDB_RECORD_BTRACE_H */ diff --git a/gdb/remote.c b/gdb/remote.c index 3e564fdd91f..2cf735a1f2a 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -15228,6 +15228,22 @@ parse_xml_btrace_pt_config_cpu (struct gdb_xml_parser *parser, btrace->variant.pt.config.cpu.stepping = *stepping; } +/* Parse a btrace pt-config xml record. */ + +static void +parse_xml_btrace_pt_config (gdb_xml_parser *parser, + const gdb_xml_element *element, void *user_data, + std::vector &attributes) +{ + btrace_data *btrace = (btrace_data *) user_data; + gdb_xml_value *allow_resync = xml_find_attribute (attributes, + "allow_resync"); + btrace->variant.pt.config.allow_resync + = ((allow_resync != nullptr) + ? (bool) *(ULONGEST *) allow_resync->value.get () + : false); +} + /* Parse a btrace pt "raw" xml record. */ static void @@ -15255,6 +15271,7 @@ parse_xml_btrace_pt (struct gdb_xml_parser *parser, btrace = (struct btrace_data *) user_data; btrace->format = BTRACE_FORMAT_PT; btrace->variant.pt.config.cpu.vendor = CV_UNKNOWN; + btrace->variant.pt.config.allow_resync = false; btrace->variant.pt.data = NULL; btrace->variant.pt.size = 0; } @@ -15273,6 +15290,12 @@ static const struct gdb_xml_attribute btrace_pt_config_cpu_attributes[] = { { NULL, GDB_XML_AF_NONE, NULL, NULL } }; +static const struct gdb_xml_attribute btrace_pt_config_attributes[] = { + { "allow_resync", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_enum, + gdb_xml_enums_boolean }, + { NULL, GDB_XML_AF_NONE, NULL, NULL } +}; + static const struct gdb_xml_element btrace_pt_config_children[] = { { "cpu", btrace_pt_config_cpu_attributes, NULL, GDB_XML_EF_OPTIONAL, parse_xml_btrace_pt_config_cpu, NULL }, @@ -15280,8 +15303,8 @@ static const struct gdb_xml_element btrace_pt_config_children[] = { }; static const struct gdb_xml_element btrace_pt_children[] = { - { "pt-config", NULL, btrace_pt_config_children, GDB_XML_EF_OPTIONAL, NULL, - NULL }, + { "pt-config", btrace_pt_config_attributes, btrace_pt_config_children, + GDB_XML_EF_OPTIONAL, parse_xml_btrace_pt_config, NULL }, { "raw", NULL, NULL, GDB_XML_EF_OPTIONAL, NULL, parse_xml_btrace_pt_raw }, { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } }; diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 7bcb85e641a..661447a8062 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -6889,7 +6889,8 @@ static void linux_low_encode_pt_config (std::string *buffer, const struct btrace_data_pt_config *config) { - *buffer += "\n"; + string_xml_appendf (*buffer, "\n", + (config->allow_resync ? "yes" : "no")); switch (config->cpu.vendor) { diff --git a/gdbsupport/btrace-common.h b/gdbsupport/btrace-common.h index f2b274c79a7..10c58ef3c88 100644 --- a/gdbsupport/btrace-common.h +++ b/gdbsupport/btrace-common.h @@ -129,6 +129,9 @@ struct btrace_config_pt /* Return compression setting. */ bool return_compression; + + /* Configuration bit for enhanced synchronization after decode errors. */ + bool enhanced_resync; }; /* A branch tracing configuration. @@ -164,6 +167,9 @@ struct btrace_data_pt_config { /* The processor on which the trace has been collected. */ struct btrace_cpu cpu; + + /* Whether the processor supports resyncing on IP-providing packets. */ + bool allow_resync; }; /* Branch trace in Intel Processor Trace format. */ -- 2.53.0 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.