From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +c+3EeSi5GoseBQAWB0awg (envelope-from ) for ; Fri, 30 Oct 2026 10:00:04 -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=LSnTjZEL; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 43CFD378002; Fri, 30 Oct 2026 10:00:04 -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 27FFC1E023 for ; Fri, 30 Oct 2026 10:00:03 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 24BA04BA900B for ; Fri, 30 Oct 2026 14:00:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24BA04BA900B 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=LSnTjZEL Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by sourceware.org (Postfix) with ESMTPS id CA8464BA9031 for ; Fri, 30 Oct 2026 13:57:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA8464BA9031 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 CA8464BA9031 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=1793368675; cv=none; b=YHmYHCZKEsxHPAkd2cZ+0eFH2J7P5fLzkfEr3n3bI9ArQ3EFiJ0ONFHi+g4o7hsKWTjPYc0J1nrH4M/BUkp9ZzenN+JVSZBpLy6imq5ozKoWZggfW6w+uYM40bQeOrZI8cAYYDTSbpd50udvgBV8x+ialr/W4vyHShU3Hm46jj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793368675; c=relaxed/simple; bh=8KIl++d6c4ExVOPEh77anoNnEZ93FOQ7+UFYANZexVc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=OaZinLauwvTSgv1wswnCde1m86clespmGbSD+zqkf0GCNWtEwq5MXqcB1NDQMTrHSp+Sc4pO9sgaZpdbIxjkXnPeBLL65aRAT+oCpcaIr3UPJuuJASrXAdgqxx5W6Jr9diCPY1BWuI3mT3BO7pjbtJj6Z3+7Ttq8R+yEy6ciPIs= 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=LSnTjZEL DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA8464BA9031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1793368675; x=1824904675; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=8KIl++d6c4ExVOPEh77anoNnEZ93FOQ7+UFYANZexVc=; b=LSnTjZELLJHcmtRl1818b5LCV2wfPZ2phwLWJ3IPzY2/1P6Hem5BumX6 lb7E6Ano38VHVA7MQdJctR/eo+AvGo6HDdUBVPEfbXXt8KEAZhSpQxHCW WHfBL8l08qSFmB1bx86DJ7DMNzARKyEJmzU9YQFuUFR2sJneAAuJdmN41 7T/xaszCLDDFuW0e0war/J3ERx3hAloGVD9DQkuN+jMS8nkW9IyvCJKzg 8oG02ENvxplckWgBPYoZWTek9ZN8BPYMvx7fjVDZfPn7XQqVjKVhdIiam iagMU7CWWndweNLI/RnO5ISHP/aS0VChv9RA5Zgtm67QGDrbFdXYYvAgx g==; X-CSE-ConnectionGUID: 0j+RCtQ3SAyGsUpaxLjXqQ== X-CSE-MsgGUID: ywbZ7RDIQXiFdBGgV/DRsA== X-IronPort-AV: E=McAfee;i="6800,10657,11951"; a="2011300" X-IronPort-AV: E=Sophos;i="6.27,186,1787036400"; d="scan'208";a="2011300" 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:57:55 -0700 X-CSE-ConnectionGUID: ctKHOVAGTViHfZOXn/Bw+w== X-CSE-MsgGUID: aAF7s8u1TWK0gI5vQtN/eA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,186,1787036400"; d="scan'208";a="5331824" 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:57:53 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Subject: [PATCH 2/5] gdb, btrace: refactor ftrace_add_pt() Date: Fri, 30 Oct 2026 14:57:41 +0100 Message-ID: <20261030135744.921562-3-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 Extract the main decode loop and generating a decode error warning out of ftrace_add_pt() to prepare for a subsequent patch to extend decode error handling. There should be no functional change except that the decode error warning would now print pc=? if an error was added after a preceding gap or auxiliary instruction instead of the PC of the last real instruction. The PC value now matches the instruction offset that is also printed with the decode error warning. --- gdb/btrace.c | 112 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 69 insertions(+), 43 deletions(-) diff --git a/gdb/btrace.c b/gdb/btrace.c index ddc7b2551df..5c47f9129ae 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -1710,26 +1710,83 @@ handle_pt_insn_event_flags (struct btrace_thread_info *btinfo, #endif /* defined (HAVE_STRUCT_PT_INSN_RESYNCED) */ } +/* Generate a decode error warning. */ + +static void +ftrace_warn_pt (btrace_thread_info *btinfo, pt_insn_decoder *decoder, + btrace_function *bfun, int status) +{ + gdb_assert (bfun != nullptr); + + unsigned int ioffset = bfun->insn_offset - 1; + uint64_t offset; + pt_insn_get_offset (decoder, &offset); + + btrace_insn_iterator it; + int found = btrace_find_insn_by_number (&it, btinfo, ioffset); + const btrace_insn *binsn = (found != 0) ? btrace_insn_get (&it) : nullptr; + + warning (_("Decode error (%d) at instruction %u (offset = 0x%" PRIx64 + ", pc = %s): %s."), status, ioffset, offset, + (binsn != nullptr) ? hex_string (binsn->pc) : "?", + pt_errstr (pt_errcode (status))); +} + +/* Decode the trace and handle events as long as there is no error. + Returns the last decoder status. */ + +static int +ftrace_decode_pt (btrace_thread_info *btinfo, + pt_insn_decoder *decoder, + int *plevel, + std::vector &gaps, + int status) +{ + gdb_assert (status >= 0); + for (;;) + { +#if defined (HAVE_PT_INSN_EVENT) + /* Handle events from the previous iteration or synchronization. */ + while (status & pts_event_pending) + { + status = handle_pt_insn_event (btinfo, decoder, gaps); + if (status < 0) + return status; + } +#endif + pt_insn insn; + status = pt_insn_next (decoder, &insn, sizeof (insn)); + if (status < 0) + return status; + + /* Handle events indicated by flags in INSN. */ + handle_pt_insn_event_flags (btinfo, decoder, insn, gaps); + + btrace_function *bfun + = ftrace_update_function (btinfo, + std::make_optional (insn.ip)); + + /* Maintain the function level offset. */ + *plevel = std::min (*plevel, bfun->level); + + ftrace_update_insns (bfun, pt_btrace_insn (insn)); + } +} + /* Add function branch trace to BTINFO using DECODER. */ static void -ftrace_add_pt (struct btrace_thread_info *btinfo, - struct pt_insn_decoder *decoder, +ftrace_add_pt (btrace_thread_info *btinfo, + pt_insn_decoder *decoder, int *plevel, std::vector &gaps) { - struct btrace_function *bfun; - uint64_t offset; - int status; - /* Register the ptwrite filter. */ apply_ext_lang_ptwrite_filter (btinfo); for (;;) { - struct pt_insn insn; - - status = pt_insn_sync_forward (decoder); + int status = pt_insn_sync_forward (decoder); if (status < 0) { if (status != -pte_eos) @@ -1738,44 +1795,13 @@ ftrace_add_pt (struct btrace_thread_info *btinfo, break; } - for (;;) - { -#if defined (HAVE_PT_INSN_EVENT) - /* Handle events from the previous iteration or synchronization. */ - while ((status != 0) && (status & pts_event_pending)) - status = handle_pt_insn_event (btinfo, decoder, gaps); -#endif - if (status < 0) - break; - - status = pt_insn_next (decoder, &insn, sizeof(insn)); - if (status < 0) - break; - - /* Handle events indicated by flags in INSN. */ - handle_pt_insn_event_flags (btinfo, decoder, insn, gaps); - - bfun - = ftrace_update_function (btinfo, - std::make_optional (insn.ip)); - - /* Maintain the function level offset. */ - *plevel = std::min (*plevel, bfun->level); - - ftrace_update_insns (bfun, pt_btrace_insn (insn)); - } - + status = ftrace_decode_pt (btinfo, decoder, plevel, gaps, status); if (status == -pte_eos) break; /* Indicate the gap in the trace. */ - bfun = ftrace_new_gap (btinfo, status, gaps); - - pt_insn_get_offset (decoder, &offset); - - warning (_("Decode error (%d) at instruction %u (offset = 0x%" PRIx64 - ", pc = 0x%" PRIx64 "): %s."), status, bfun->insn_offset - 1, - offset, insn.ip, pt_errstr (pt_errcode (status))); + btrace_function *bfun = ftrace_new_gap (btinfo, status, gaps); + ftrace_warn_pt (btinfo, decoder, bfun, status); } } -- 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.