From patchwork Mon Sep 2 11:49:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Willgerodt X-Patchwork-Id: 96896 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CFA5D384CBA1 for ; Mon, 2 Sep 2024 11:51:11 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by sourceware.org (Postfix) with ESMTPS id 0E1EB3858404 for ; Mon, 2 Sep 2024 11:50:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E1EB3858404 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 0E1EB3858404 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277846; cv=none; b=HJqPMHNyVVfF59ks6oRphIH5/niuFdxFxCBZXLMMNF6XyCommjYG8PNAtS+uUg0tZeyeuI5K45AYE7bWMmbrVZAtvUBYJpqxU4Up6YWKTfWXxshYog2hMeYq3VgSFnyEWSfi/PiDiX9hY2Qx35pITjbtuD3b8r21j9fuK/0j3as= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277846; c=relaxed/simple; bh=g2viuycLCq/aVY1Psqdp5hOyfh8spuI1eZHYaCrO2XM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=mK8Utxh908o2aRw1gxBxysoSQ31MQjE82wClV3fbigG9oHZEJF0cEdvEeUYeCvtFofAiKdSVYB6Ko5IcdBFjzpvvCzpK7xMLFesycv4DnQTh9hR38YlFNkmdmwSAxdTXBQY4VIo2qT5Wfunao0sJ846jJQLzfK4+55FWXAdwklU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725277844; x=1756813844; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=g2viuycLCq/aVY1Psqdp5hOyfh8spuI1eZHYaCrO2XM=; b=VOCxcO3NJUYTMHas8g6jE1YMYIIlG4MsLaAw+//RVMKP+C55tCeDJ8ib mfe8rc/dFgqjdy8A3E1aKwZ+4wzE5TqXjDcaZA2BsppNRvp9Ups674gI/ 8Ir+G+i1ZaaoqjhOrxUfVU0pmO3c2Cn7fu+KUFx1JRppBDnMA+QCfwfYJ Ql3oWsKLNbVwzv3BIswnhWgTJ/1rk42waveHItje5gDHRHXwn+cTG4AAT f9TZZYKrqIKrA/EkkKHEswtIcH8DYeNLHcXNt62Uov21Ft9M/Ec8OEqQs 9q3BlZMf37bilBccWlyYSwCejtodA9MMtOWasdotsN4vD1ItWQ7WxWL4L Q==; X-CSE-ConnectionGUID: H6sD0AkVRhG813zwnQtUBQ== X-CSE-MsgGUID: FNy21OK7QcelhWyRMaPjvQ== X-IronPort-AV: E=McAfee;i="6700,10204,11182"; a="41330862" X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="41330862" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:50:43 -0700 X-CSE-ConnectionGUID: xnoRPfJ4QoqM3z0olHMFiA== X-CSE-MsgGUID: Dqah+ec4Q6O9tjErSExV9A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="87821422" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:50:42 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org, markus.t.metzger@intel.com Subject: [PATCH 1/7] btrace: Print "non-contiguous" for gaps. Date: Mon, 2 Sep 2024 13:49:43 +0200 Message-Id: <20240902114949.918485-2-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240902114949.918485-1-felix.willgerodt@intel.com> References: <20240902114949.918485-1-felix.willgerodt@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org So far we printed "disabled" for gaps, when we saw a ptev_enabled event that doesn't have the resumed flag set. This is wrong, as the actual disabling happens with ptev_disabled. So far this didn't matter, but once we have event tracing, there can be events between a ptev_disabled and a ptev_enabled. This patch is in preparation for that, and removes the disabled reason in favour of a more accurate non-contiguous reason, and adjusts the string we print accordingly. --- gdb/btrace.c | 8 ++++---- gdb/btrace.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gdb/btrace.c b/gdb/btrace.c index ff9612dd664..9dc0c5cc930 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -1255,7 +1255,7 @@ handle_pt_insn_events (struct btrace_thread_info *btinfo, && !btinfo->functions.empty ()) { struct btrace_function *bfun - = ftrace_new_gap (btinfo, BDE_PT_DISABLED, gaps); + = ftrace_new_gap (btinfo, BDE_PT_NON_CONTIGUOUS, gaps); pt_insn_get_offset (decoder, &offset); @@ -1359,7 +1359,7 @@ handle_pt_insn_event_flags (struct btrace_thread_info *btinfo, struct btrace_function *bfun; uint64_t offset; - bfun = ftrace_new_gap (btinfo, BDE_PT_DISABLED, gaps); + bfun = ftrace_new_gap (btinfo, BDE_PT_NON_CONTIGUOUS, gaps); pt_insn_get_offset (decoder, &offset); @@ -1966,8 +1966,8 @@ btrace_decode_error (enum btrace_format format, int errcode) case BDE_PT_USER_QUIT: return _("trace decode cancelled"); - case BDE_PT_DISABLED: - return _("disabled"); + case BDE_PT_NON_CONTIGUOUS: + return _("non-contiguous"); case BDE_PT_OVERFLOW: return _("overflow"); diff --git a/gdb/btrace.h b/gdb/btrace.h index 34f8d2be5ce..542bf2c595a 100644 --- a/gdb/btrace.h +++ b/gdb/btrace.h @@ -131,7 +131,7 @@ enum btrace_pt_error BDE_PT_USER_QUIT = 1, /* Tracing was temporarily disabled. */ - BDE_PT_DISABLED, + BDE_PT_NON_CONTIGUOUS, /* Trace recording overflowed. */ BDE_PT_OVERFLOW From patchwork Mon Sep 2 11:49:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Willgerodt X-Patchwork-Id: 96899 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 092C2385E458 for ; Mon, 2 Sep 2024 11:51:54 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by sourceware.org (Postfix) with ESMTPS id B6938384DEC2 for ; Mon, 2 Sep 2024 11:50:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B6938384DEC2 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 B6938384DEC2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277854; cv=none; b=oFPdwyRn/PuKDP486KAtsgE27GiYqV0OQU127TxFRo06od8k9nLHPRvpW4EX6ekG1Bw5Hb46Vp6MpqZVgLWduq9rSmQvJxoQN5xDhiii8EnhUebAaM2TTDIZbUQvqIz/cIr+C/9kRDCUwUJQd1RoGMUbd+BvGcQfqQgLt4MwBH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277854; c=relaxed/simple; bh=9mNXwVVXiApxADdEK1FM8EhtguUu1MLmoramVrC4dF4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=aViAHQ4S9MQxbMqdKhzbqZktJSktQws8ti8M7JBhd0MojIksrynDKbX1z9sK1Bkn2nk0dDO+IHhnNevGEStjdoUdvqgChDVVo89UWMXH89kWdoIm9xtf6DBnYlFgUdlBvI7/ik6Nd69PwNfP8tl2xH146X85mJK8fhnBRFU50No= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725277853; x=1756813853; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=9mNXwVVXiApxADdEK1FM8EhtguUu1MLmoramVrC4dF4=; b=QsTL/ezq253VuDK89aE0A1etBt8IjZs5y/OLbhooDGKkgcjnodkMI9XR m/5GjrL19vXm9zYYY/dYQBA6KH18by1aBtmRJcfyrGDQh0S/38tJ6NPR3 LKCFwsH/Jr+hqlp0ZMaD9iFoObPdtQl9vkZ8b8c+HsDvLXDC0Rk4/dTpD E3T6nOcUVdeNABJTLtEDJDIV7FIrHrPcZgQasijL1YfAVeYztMB8Gxsro VFknZJ/fDhWSYzspxueSbEl2Sc4A1P8C4q8bPCxBEYlA8jeLlIdO0tCHK Oqb07lSeyLYVMTwQKFqDF32otq4KxmjuihfgzRWg7JC01EZAVgvKDAqov w==; X-CSE-ConnectionGUID: RqtQ0NsBQF6OYNxdLboTBA== X-CSE-MsgGUID: Kil/RoyaQVaODkB1QTht5g== X-IronPort-AV: E=McAfee;i="6700,10204,11182"; a="41330877" X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="41330877" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:50:51 -0700 X-CSE-ConnectionGUID: mwYOVmxVTOS+iAFoxlpggA== X-CSE-MsgGUID: Bl+94c24R6mmkqrvT1lIRg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="87821477" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:50:50 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org, markus.t.metzger@intel.com Subject: [PATCH 2/7] btrace: Add printing support for cfe and evd packets. Date: Mon, 2 Sep 2024 13:49:44 +0200 Message-Id: <20240902114949.918485-3-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240902114949.918485-1-felix.willgerodt@intel.com> References: <20240902114949.918485-1-felix.willgerodt@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org --- gdb/btrace.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gdb/btrace.c b/gdb/btrace.c index 9dc0c5cc930..649e0ad59d7 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -2746,6 +2746,19 @@ pt_print_packet (const struct pt_packet *packet) packet->payload.ptw.ip ? (" ip") : ("")); break; #endif /* defined (LIBIPT_VERSION >= 0x200) */ + +#if (LIBIPT_VERSION >= 0x201) + case ppt_cfe: + gdb_printf (("cfe %u: 0x%x%s"), packet->payload.cfe.type, + packet->payload.cfe.vector, + packet->payload.cfe.ip ? (" ip") : ("")); + break; + + case ppt_evd: + gdb_printf (("evd %u: 0x%" PRIx64 ""), packet->payload.evd.type, + packet->payload.evd.payload); + break; +#endif /* defined (LIBIPT_VERSION >= 0x201) */ } } From patchwork Mon Sep 2 11:49:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Willgerodt X-Patchwork-Id: 96897 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01AC0385DDD3 for ; Mon, 2 Sep 2024 11:51:35 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by sourceware.org (Postfix) with ESMTPS id DB2CE385DDC7 for ; Mon, 2 Sep 2024 11:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB2CE385DDC7 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 DB2CE385DDC7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277864; cv=none; b=kUVvLnU/cvMT5E3NHu/z6lVLg53SrOea9Rtn17YTAtV7x70qhywy2FbK1gsNfGveZNftRxunGFoOX9zCpJZZHr+kVBRtp9eLNBnhc1g+OaH2zHnDaHPmlYIEExV6gYZRPaaEVSNx2YF17ku+jg14Rew4qCfJD/XC8VTS36IfSmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277864; c=relaxed/simple; bh=G5f8IHsRf8WyKBtb8sVMaeg+Em1zmXXYM3NKnhXAOSs=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=LRdc18PTrbrg0KpM1T2DnRN6lxh5skSOQReO8gG2zXlJPjdxNTCG0ByTZSDI5U73g8pVMO1LgWZ/CLLUQtIOrGyq/mwpLLOPi1HbQZ5FxySBQKKoFnufzssgz3EE8bc43ZfCTJnkC1rm71//SL3tpxWHxEurI/N0QDXfqfC4F9c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725277859; x=1756813859; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=G5f8IHsRf8WyKBtb8sVMaeg+Em1zmXXYM3NKnhXAOSs=; b=eSlp7wPL/pda72JRmnsG+B0RB9Qa3aBAFmxiWpwxrQWeJ5BieRjNN3ZV fYyD0lJNMTwZPlch5tTn1hUFhmvj/rHeXUC1lO9yuVMRJoYfe6NqmMrdf vkxD0BL1MWxkoGeXBjp+VbZ7JpeFqh/H/Ek/lsBDWerDnolWybSUjmC3d PchEyKn76sr3INCo7eX3luSMHVcd8hTKlZLzfrr7gS8IzBTPprOkuSiBv kirR0mOMTGUuWUOVJQLRGZ+cxcSAHz9oVTD8adeHctMhzBahOq/X1ynKu dgZpSPYBGQCl47fakbCj+k9w/kkfFpCbwkKDSGCfmlcYdR1gHvJhEp4qt Q==; X-CSE-ConnectionGUID: ciPkxwOJTqGvus9X5deYpA== X-CSE-MsgGUID: ibklbXduS+aBK3hgDnCcPA== X-IronPort-AV: E=McAfee;i="6700,10204,11182"; a="41330898" X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="41330898" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:50:58 -0700 X-CSE-ConnectionGUID: OmcMW+JmQTuV1Mzb1LPjwQ== X-CSE-MsgGUID: hctOxf5mQXGC/2LoKS7ibA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="87821523" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:50:57 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org, markus.t.metzger@intel.com Subject: [PATCH 3/7] btrace: Enable event tracing on Linux for Intel PT. Date: Mon, 2 Sep 2024 13:49:45 +0200 Message-Id: <20240902114949.918485-4-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240902114949.918485-1-felix.willgerodt@intel.com> References: <20240902114949.918485-1-felix.willgerodt@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org 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. Reviewed-By: Eli Zaretskii --- 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(-) 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 - - + + - + - - + + + @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 @@ + 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 &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. From patchwork Mon Sep 2 11:49:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Willgerodt X-Patchwork-Id: 96898 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 423723857011 for ; Mon, 2 Sep 2024 11:51:42 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by sourceware.org (Postfix) with ESMTPS id BA57E3860008 for ; Mon, 2 Sep 2024 11:51:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BA57E3860008 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 BA57E3860008 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277869; cv=none; b=k7FQ2PtUaBDRgHgPPJmOyYsfDYthm6FsVCjm+w7LyBdqI4O4pNuTgzNr4eBKTkWEvvPSEnfdRqvqOPIUXYRI1Fgp8aN9UtQJsci3vz1y8t2tjjYJ4Lvgk/VPG+Hqf7BU/yt1oar4lUokQSNgzBADYzx14xFlm4bq99vBIo6We10= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277869; c=relaxed/simple; bh=+tKQf4rNjAOFck8shEJ6lhMpSRhMLbYaNgIQ1Xs8wXY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=iXnn4OaG/b/YP6A7AVqrsiyaVGqw8uPiG8dLuAtUbhGUwSM4fPIHXmR5uRExGTX+rlx21Wdb9BcEuws1uGf8hpG15liOOSTa4Xg6y2mVJsYeaSfYHWLKhktny6854rek0q6WpdDKgJwM4YePiwNNvFg7NZ/ok3gSErw5Xm4rVYY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725277866; x=1756813866; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=+tKQf4rNjAOFck8shEJ6lhMpSRhMLbYaNgIQ1Xs8wXY=; b=SxCoNpfjR7+Enr9Pnuh8m1vDDocXiMSNR1tn6xYUBCX021m8yRpznrld 1BJY8fNTpFsoMPJ7JhGdPE0PeJUzQprtX4W+G7SIiOBxgxp60IYYRBiCu fdVWCab+jc7okxTZP3e1SYYryQxKd+Gn1V8SJB7dJhxMk53tQXhXMKWJo 46bDZs23FsqtdhPFGI+KoKNYu/F0hsBY+OSGY788GsfmV0nHq3Gfjk9KS BM7gfzBj0B4c2NNBYG2tNDmu1K3gerbUW/rkXtzelbcIBXGOT/VWrT/bM m4Qk6MCvBr90ZXgS78nYLwuVtibIYVmPUx/s81BhDRn1EAYqwFvAjww0r g==; X-CSE-ConnectionGUID: f3bc4utYTXeNFeOBsYNXUA== X-CSE-MsgGUID: TxocCV3MSh6jucGOLfjnGw== X-IronPort-AV: E=McAfee;i="6700,10204,11182"; a="41330911" X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="41330911" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:51:05 -0700 X-CSE-ConnectionGUID: 3fCX7YzZREi2302lAI5+JQ== X-CSE-MsgGUID: AIKm0iqXS/mi75vw9c+5sA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="87821558" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:51:04 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org, markus.t.metzger@intel.com Subject: [PATCH 4/7] btrace: Add support for interrupt events. Date: Mon, 2 Sep 2024 13:49:46 +0200 Message-Id: <20240902114949.918485-5-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240902114949.918485-1-felix.willgerodt@intel.com> References: <20240902114949.918485-1-felix.willgerodt@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org Newer Intel CPUs support recording asynchronous events in the PT trace. Libipt also recently added support for decoding these. This patch adds support for interrupt events, based on the existing aux infrastructure. GDB can now display such events during the record instruction-history and function-call-history commands. Subsequent patches will add the rest of the events currently supported. --- gdb/btrace.c | 84 ++++++++++++++++++- gdb/btrace.h | 6 +- gdb/testsuite/gdb.btrace/event-tracing-gap.c | 34 ++++++++ .../gdb.btrace/event-tracing-gap.exp | 73 ++++++++++++++++ gdb/testsuite/gdb.btrace/event-tracing.exp | 55 ++++++++++++ gdb/testsuite/gdb.btrace/null-deref.c | 34 ++++++++ gdb/testsuite/lib/gdb.exp | 55 ++++++++++++ 7 files changed, 338 insertions(+), 3 deletions(-) create mode 100644 gdb/testsuite/gdb.btrace/event-tracing-gap.c create mode 100644 gdb/testsuite/gdb.btrace/event-tracing-gap.exp create mode 100644 gdb/testsuite/gdb.btrace/event-tracing.exp create mode 100644 gdb/testsuite/gdb.btrace/null-deref.c diff --git a/gdb/btrace.c b/gdb/btrace.c index 649e0ad59d7..4b182a67c64 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -642,6 +642,18 @@ ftrace_update_function (struct btrace_thread_info *btinfo, CORE_ADDR pc) break; } + + case BTRACE_INSN_AUX: + /* An aux insn couldn't have switched the function. But the + segment might not have had a symbol name resolved yet, as events + might not have an IP. Use the current IP in that case and update + the name. */ + if (bfun->sym == nullptr && bfun->msym == nullptr) + { + bfun->sym = fun; + bfun->msym = mfun; + } + return bfun; } } @@ -668,6 +680,8 @@ ftrace_update_insns (struct btrace_function *bfun, const btrace_insn &insn) if (insn.iclass == BTRACE_INSN_AUX) bfun->flags |= BFUN_CONTAINS_AUX; + else + bfun->flags |= BFUN_CONTAINS_NON_AUX; if (record_debug > 1) ftrace_debug (bfun, "update insn"); @@ -1222,8 +1236,38 @@ handle_pt_aux_insn (btrace_thread_info *btinfo, std::string &aux_str, ftrace_update_insns (bfun, insn); } +/* Check if the last function segment contains real instructions, and not + only auxiliary instructions. */ + +static bool +ftrace_last_bfun_contains_non_aux (btrace_thread_info *btinfo) +{ + if (btinfo->functions.empty ()) + return false; + + return ((btinfo->functions.back ().flags & BFUN_CONTAINS_NON_AUX) != 0); +} #endif /* defined (HAVE_PT_INSN_EVENT) */ +#if (LIBIPT_VERSION >= 0x201) +/* Translate an interrupt vector to a mnemonic string as defined for x86. + Returns nullptr if there is none. */ + +static const char * +decode_interrupt_vector (const uint8_t vector) +{ + static const char *mnemonic[] + = { "#de", "#db", nullptr, "#bp", "#of", "#br", "#ud", "#nm", + "#df", "#mf", "#ts", "#np", "#ss", "#gp", "#pf", nullptr, + "#mf", "#ac", "#mc", "#xm", "#ve", "#cp" }; + + if (vector < (sizeof (mnemonic) / sizeof (mnemonic[0]))) + return mnemonic[vector]; + + return nullptr; +} +#endif /* defined (LIBIPT_VERSION >= 0x201) */ + /* Handle instruction decode events (libipt-v2). */ static int @@ -1236,6 +1280,7 @@ handle_pt_insn_events (struct btrace_thread_info *btinfo, { struct pt_event event; uint64_t offset; + CORE_ADDR pc = 0; status = pt_insn_event (decoder, &event, sizeof (event)); if (status < 0) @@ -1251,8 +1296,16 @@ handle_pt_insn_events (struct btrace_thread_info *btinfo, if (event.status_update != 0) break; + /* Only create a new gap if the last function segment contains + non-aux instructions. We could be at the beginning of the + recording and could already have handled one or more events, + like ptev_iret, that created aux insns. In that case we don't + want to create a gap or print a warning. Note that if the last + function segment contains only aux insns, we are guaranteed + to be at the beginning of a recording or after a gap. See + handle_pt_aux_insn (). */ if (event.variant.enabled.resumed == 0 - && !btinfo->functions.empty ()) + && ftrace_last_bfun_contains_non_aux (btinfo)) { struct btrace_function *bfun = ftrace_new_gap (btinfo, BDE_PT_NON_CONTIGUOUS, gaps); @@ -1282,7 +1335,6 @@ handle_pt_insn_events (struct btrace_thread_info *btinfo, #if defined (HAVE_STRUCT_PT_EVENT_VARIANT_PTWRITE) case ptev_ptwrite: { - uint64_t pc = 0; std::optional ptw_string; /* Lookup the PC if available. The event often doesn't provide @@ -1333,6 +1385,34 @@ handle_pt_insn_events (struct btrace_thread_info *btinfo, break; } #endif /* defined (HAVE_STRUCT_PT_EVENT_VARIANT_PTWRITE) */ + +#if (LIBIPT_VERSION >= 0x201) + case ptev_interrupt: + { + std::string aux_string = std::string (_("interrupt: vector = ")) + + hex_string (event.variant.interrupt.vector); + + const char *decoded + = decode_interrupt_vector (event.variant.interrupt.vector); + if (decoded != nullptr) + aux_string += std::string (" (") + decoded + ")"; + + if (event.variant.interrupt.has_cr2 != 0) + { + aux_string += std::string (", cr2 = ") + + hex_string (event.variant.interrupt.cr2); + } + + if (event.ip_suppressed == 0) + { + pc = event.variant.interrupt.ip; + aux_string += std::string (", ip = ") + hex_string (pc); + } + + handle_pt_aux_insn (btinfo, aux_string, pc); + break; + } +#endif /* defined (LIBIPT_VERSION >= 0x201) */ } } #endif /* defined (HAVE_PT_INSN_EVENT) */ diff --git a/gdb/btrace.h b/gdb/btrace.h index 542bf2c595a..0ca56846ba0 100644 --- a/gdb/btrace.h +++ b/gdb/btrace.h @@ -110,7 +110,11 @@ enum btrace_function_flag /* Indicates that at least one auxiliary instruction is in the current function segment. */ - BFUN_CONTAINS_AUX = (1 << 2) + BFUN_CONTAINS_AUX = (1 << 2), + + /* Indicates that at least one instruction not of type BTRACE_INSN_AUX + is in the current function segment. */ + BFUN_CONTAINS_NON_AUX = (1 << 3) }; DEF_ENUM_FLAGS_TYPE (enum btrace_function_flag, btrace_function_flags); diff --git a/gdb/testsuite/gdb.btrace/event-tracing-gap.c b/gdb/testsuite/gdb.btrace/event-tracing-gap.c new file mode 100644 index 00000000000..960447d458a --- /dev/null +++ b/gdb/testsuite/gdb.btrace/event-tracing-gap.c @@ -0,0 +1,34 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2024 Free Software Foundation, Inc. + + Contributed by Intel Corp. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +static int +square (int num) +{ + return num * num; /* bp1. */ +} + +int +main (void) +{ + int a = 2; + int ans = 0; + + ans = square (a); + return 0; /* bp2. */ +} diff --git a/gdb/testsuite/gdb.btrace/event-tracing-gap.exp b/gdb/testsuite/gdb.btrace/event-tracing-gap.exp new file mode 100644 index 00000000000..5d470bb9d62 --- /dev/null +++ b/gdb/testsuite/gdb.btrace/event-tracing-gap.exp @@ -0,0 +1,73 @@ +# This testcase is part of GDB, the GNU debugger. +# +# Copyright 2024 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test event tracing with gaps. + +require allow_btrace_tests allow_btrace_event_trace_tests + +standard_testfile + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} { + return -1 +} + +if {![runto_main]} { + return -1 +} + +gdb_test_no_output "set record btrace pt event-tracing on" +gdb_test_no_output "record btrace pt" + +set bp_1 [gdb_get_line_number "bp1"] +set bp_2 [gdb_get_line_number "bp2"] +gdb_breakpoint $bp_1 +gdb_breakpoint $bp_2 + +gdb_test "next" + +gdb_test "call square (3)" [multi_line \ + "" \ + "Breakpoint $decimal, square \\(num=3\\) at \[^\r\n\]+:$bp_1" \ + "$decimal.*bp1.*" \ + "The program being debugged stopped while in a function called from GDB\\." \ + "Evaluation of the expression containing the function" \ + "\\(square\\) will be abandoned\\." \ + "When the function is done executing, GDB will silently stop\\."] + +gdb_test "return 9" "0.*main.*" \ + "return" \ + "Make.*return now\\? \\(y or n\\) " "y" + +gdb_continue_to_breakpoint "break at bp_1" ".*$srcfile:$bp_1.*" +gdb_continue_to_breakpoint "break at bp_2" ".*$srcfile:$bp_2.*" + +# Inferior calls and return commands will create gaps in the recording. +# We should have 2 gaps and events for each breakpoint we hit. +# Note that due to the asynchronous nature of certain events, we use +# gdb_test_sequence and check only for events that we can control. +gdb_test_sequence "record function-call-history" "function-call-history" { + "\[0-9\]+\tmain" + "\\\[interrupt: vector = 0x1 \\\(#db\\\)(, ip = 0x\[0-9a-fA-F\]+)?\\\]" + "\[0-9\]+\t\\\[non-contiguous\\\]" + "\[0-9\]+\tsquare" + "\\\[interrupt: vector = 0x3 \\\(#bp\\\)(, ip = 0x\[0-9a-fA-F\]+)?\\\]" + "\[0-9\]+\t\\\[non-contiguous\\\]" + "\[0-9\]+\tmain" + "\[0-9\]+\tsquare" + "\\\[interrupt: vector = 0x3 \\\(#bp\\\)(, ip = 0x\[0-9a-fA-F\]+)?\\\]" + "\[0-9\]+\tmain" +} diff --git a/gdb/testsuite/gdb.btrace/event-tracing.exp b/gdb/testsuite/gdb.btrace/event-tracing.exp new file mode 100644 index 00000000000..1ac5d27fa81 --- /dev/null +++ b/gdb/testsuite/gdb.btrace/event-tracing.exp @@ -0,0 +1,55 @@ +# This testcase is part of GDB, the GNU debugger. +# +# Copyright 2024 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test basic Intel PT event tracing + +require allow_btrace_tests allow_btrace_event_trace_tests + +standard_testfile null-deref.c + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} { + return -1 +} + +if {![runto_main]} { + return -1 +} + +gdb_test_no_output "set record btrace pt event-tracing on" +gdb_test_no_output "record btrace pt" + +gdb_test "continue" "Program received signal SIGSEGV, Segmentation fault.*" + +# Test printing of at least one INTERRUPT event. +gdb_test "record function-call-history" [multi_line \ + "$decimal\tmain" \ + "\t \\\[interrupt: vector = 0x1 \\\(#db\\\), ip = $hex\\\]" \ + "$decimal\tcall1" \ + "$decimal\tmain" \ + "\t \\\[interrupt: vector = 0xe \\\(#pf\\\), cr2 = 0x0, ip = $hex\\\]" + ] + +# Test the instruction-history. Assembly can differ between compilers, to +# avoid creating a .S file for this test we just check the last two lines. +gdb_test "record instruction-history" [multi_line \ + "$decimal\t $hex .*" \ + "$decimal\t \\\[interrupt: vector = 0xe \\\(#pf\\\), cr2 = 0x0, ip = $hex\\\]" + ] + +# Test reverse stepping and replay stepping +gdb_test "reverse-stepi" "\\\[interrupt: vector = 0xe \\\(#pf\\\), cr2 = 0x0, ip = $hex\\\].*" +gdb_test "stepi" "\\\[interrupt: vector = 0xe \\\(#pf\\\), cr2 = 0x0, ip = $hex\\\].*" diff --git a/gdb/testsuite/gdb.btrace/null-deref.c b/gdb/testsuite/gdb.btrace/null-deref.c new file mode 100644 index 00000000000..fc17c3f9710 --- /dev/null +++ b/gdb/testsuite/gdb.btrace/null-deref.c @@ -0,0 +1,34 @@ +/* Copyright 2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* To have a function-call-history. */ +int +call1 (int a) +{ + return a; +} + +int +main () +{ + int a = call1 (34); + int *b = &a; + b = NULL; + + a = *b; /* BP1. */ + return 0; +} diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index d4d4acb2313..c3acc16f891 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4426,6 +4426,61 @@ gdb_caching_proc allow_btrace_ptw_tests {} { } +# Run a test on the target to see if GDB supports event tracing on it. +# Return 1 if so, 0 if it does not. + +gdb_caching_proc allow_btrace_event_trace_tests {} { + global srcdir subdir gdb_prompt inferior_exited_re decimal + set me "allow_event_trace_tests" + + set src { + int + main () + { + return 0; + } + } + + if {![gdb_simple_compile $me $src executable]} { + return 0 + } + + gdb_exit + gdb_start + gdb_reinitialize_dir $srcdir/$subdir + gdb_load "$obj" + if ![runto_main] { + return 0 + } + + set allow_event_trace_tests 0 + gdb_test_multiple "set record btrace pt event-tracing on" "$me: first check" { + -re -wrap "Event-tracing support was disabled at compile time." { + } + -re -wrap "" { + set allow_event_trace_tests 1 + } + } + + if { $allow_event_trace_tests == 1 } { + gdb_test_multiple "record btrace pt" "$me: check OS support" { + -re -wrap "^" { + } + -re -wrap "" { + verbose -log "$me: Target doesn't support event tracing." + set allow_event_trace_tests 0 + } + } + } + + gdb_exit + remote_file build delete $obj + + verbose "$me: returning $allow_event_trace_tests" 2 + return $allow_event_trace_tests +} + + # Run a test on the target to see if it supports Aarch64 SVE hardware. # Return 1 if so, 0 if it does not. Note this causes a restart of GDB. From patchwork Mon Sep 2 11:49:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Willgerodt X-Patchwork-Id: 96900 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B0D6384DD04 for ; Mon, 2 Sep 2024 11:51:58 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by sourceware.org (Postfix) with ESMTPS id 1B83D3858404 for ; Mon, 2 Sep 2024 11:51:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B83D3858404 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 1B83D3858404 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277875; cv=none; b=TtIl7ipCsxieibdOOGprTaUPk3CHE8oxG5/l9iNtSck+L/AIH1LiQ6JQ+EkmMunvd8IMq1p9ZUZ0HmipG3j5kAWIsmeqPLF5bUSKd2Zks+yGhyEr47PV6pJ5C6sWT4YGsN02IbPzipEM0xc7dIbIU4RiGt0cRwY522b+XVZH0pM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277875; c=relaxed/simple; bh=A8+ayyAYRkVfM2DJy5b2YB4T3tAy9rnh8NqB2QOLld8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=VRvxCYD0Rd+NJ4U7XtVrTvKjueoem34bAguCpzn1fZ7O1bP/buV7RyKYnHX2XNRK/JmR7pD2Bst3yZ3KXwsqOkADgMoJHC5291D3VG2zTQMTTrAfvJqTs+9ij7DHp67syOPtN6jdX0i1fR53cUxcf5yQriSLcmORl3Dg66CWhG8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725277873; x=1756813873; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=A8+ayyAYRkVfM2DJy5b2YB4T3tAy9rnh8NqB2QOLld8=; b=FXg+CaxhEpg5ZCuMAxka2wITYaGh/QXP86HykU+jn9+o05/CmBwI6fBF mEWayo+pAYQqp6JyFFZjbskEbKsTeZQq64xsMI4k0Uftz87copm0K+gTk yxzGpWzTixhf+RfATm0IjuxjMXKuDC/ABOtLOp5YVr0CeItIclRb4gF5V PtMhI7mAq74oMHIhhHx4CkspsboRDj8hOF3JJDioUK2NXhtaVGHpQR364 YoSCpmrcNi0S1WQFLu8VBOJhmiK2lTjxIK++k7Z5uFkmZoAffilHxD8a+ ASUO9+8/auvHTBjdnUJFTIFAkxvTzg8fvj+ryiwCue53QDQztiGbgyO8k g==; X-CSE-ConnectionGUID: tmsBoiW9THafuDIduPdNkA== X-CSE-MsgGUID: +4wqvk5iSIWctKUv/Ky5pQ== X-IronPort-AV: E=McAfee;i="6700,10204,11182"; a="41330920" X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="41330920" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:51:13 -0700 X-CSE-ConnectionGUID: hOPL/yRkRvigoKsrcpLs6g== X-CSE-MsgGUID: fSpin8TsRHCrizwk6WRkng== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="87821570" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:51:11 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org, markus.t.metzger@intel.com Subject: [PATCH 5/7] btrace: Add support for IRET events. Date: Mon, 2 Sep 2024 13:49:47 +0200 Message-Id: <20240902114949.918485-6-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240902114949.918485-1-felix.willgerodt@intel.com> References: <20240902114949.918485-1-felix.willgerodt@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org This is similar to the previous events that we added. --- gdb/btrace.c | 14 ++++++++++++++ gdb/testsuite/gdb.btrace/event-tracing-gap.exp | 4 ++++ gdb/testsuite/gdb.btrace/event-tracing.exp | 2 ++ 3 files changed, 20 insertions(+) diff --git a/gdb/btrace.c b/gdb/btrace.c index 4b182a67c64..bcfa11444e7 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -1412,6 +1412,20 @@ handle_pt_insn_events (struct btrace_thread_info *btinfo, handle_pt_aux_insn (btinfo, aux_string, pc); break; } + + case ptev_iret: + { + std::string aux_string = std::string (_("iret")); + + if (event.ip_suppressed == 0) + { + pc = event.variant.iret.ip; + aux_string += std::string (": ip = ") + hex_string (pc); + } + + handle_pt_aux_insn (btinfo, aux_string, pc); + break; + } #endif /* defined (LIBIPT_VERSION >= 0x201) */ } } diff --git a/gdb/testsuite/gdb.btrace/event-tracing-gap.exp b/gdb/testsuite/gdb.btrace/event-tracing-gap.exp index 5d470bb9d62..57e0e6d438d 100644 --- a/gdb/testsuite/gdb.btrace/event-tracing-gap.exp +++ b/gdb/testsuite/gdb.btrace/event-tracing-gap.exp @@ -61,13 +61,17 @@ gdb_continue_to_breakpoint "break at bp_2" ".*$srcfile:$bp_2.*" # gdb_test_sequence and check only for events that we can control. gdb_test_sequence "record function-call-history" "function-call-history" { "\[0-9\]+\tmain" + "\\\[iret(: ip = $hex)?\\\]" "\\\[interrupt: vector = 0x1 \\\(#db\\\)(, ip = 0x\[0-9a-fA-F\]+)?\\\]" + "\\\[iret(: ip = $hex)?\\\]" "\[0-9\]+\t\\\[non-contiguous\\\]" "\[0-9\]+\tsquare" "\\\[interrupt: vector = 0x3 \\\(#bp\\\)(, ip = 0x\[0-9a-fA-F\]+)?\\\]" + "\\\[iret(: ip = $hex)?\\\]" "\[0-9\]+\t\\\[non-contiguous\\\]" "\[0-9\]+\tmain" "\[0-9\]+\tsquare" "\\\[interrupt: vector = 0x3 \\\(#bp\\\)(, ip = 0x\[0-9a-fA-F\]+)?\\\]" + "\\\[iret(: ip = $hex)?\\\]" "\[0-9\]+\tmain" } diff --git a/gdb/testsuite/gdb.btrace/event-tracing.exp b/gdb/testsuite/gdb.btrace/event-tracing.exp index 1ac5d27fa81..ee3a05421cc 100644 --- a/gdb/testsuite/gdb.btrace/event-tracing.exp +++ b/gdb/testsuite/gdb.btrace/event-tracing.exp @@ -37,7 +37,9 @@ gdb_test "continue" "Program received signal SIGSEGV, Segmentation fault.*" # Test printing of at least one INTERRUPT event. gdb_test "record function-call-history" [multi_line \ "$decimal\tmain" \ + "\t \\\[iret(: ip = $hex)?\\\]" \ "\t \\\[interrupt: vector = 0x1 \\\(#db\\\), ip = $hex\\\]" \ + "\t \\\[iret(: ip = $hex)?\\\]" \ "$decimal\tcall1" \ "$decimal\tmain" \ "\t \\\[interrupt: vector = 0xe \\\(#pf\\\), cr2 = 0x0, ip = $hex\\\]" From patchwork Mon Sep 2 11:49:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Willgerodt X-Patchwork-Id: 96901 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1DF6C384DEE6 for ; Mon, 2 Sep 2024 11:52:22 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by sourceware.org (Postfix) with ESMTPS id 8CB1E385DC3C for ; Mon, 2 Sep 2024 11:51:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8CB1E385DC3C 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 8CB1E385DC3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277881; cv=none; b=xYQ9Wj+wBQLT8Y9BikQvo3cqwXeu4WjYzQIQK691ytq9mXyN5v3mknrLIxr7IMV0Ze4yZSlsL58jlJYCwUAA/12vc+cNbVYGX3jgMfBKOUdlJF7p/7wOnXYHBQneNHNrZMM9XzFAVuQrLoTRsJVsmpScWFCCJgzQCMw1kuWCGY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277881; c=relaxed/simple; bh=TpzwYXn9LAi1uyTX3PvV+xtKc1Xobo14n+xRquKAVbY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=t0S46oXOz/zURnvcALQwuJC0iXmVDaAPZ8pYERd3s+NeqiDb7nTqWtpOsZAYapNjFMX1Wqi97QfCzyTHQYRV+BRhW8CAPhY0nzrFsOUn1XVBSfE1FZ8gmQxXxC0N3/pXaB6B8Lwg/vjQGC+f3CO8XM8jGef69esva/AL/YITaF8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725277879; x=1756813879; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=TpzwYXn9LAi1uyTX3PvV+xtKc1Xobo14n+xRquKAVbY=; b=MHKTAqUQfYTEnw0naCUxLd+nR+GF139n8u1uHPgPO9MUsmCKn5PwBURU La0Q/ZoUptZTAqYI9S6qe8cZFnb6YIuUxe8TqhjjgLutNs/4lN+xmhUzJ Pgf8Pr/mQ61ELshmztUFupXUvMoBJZmFIrq3lx0//kKVJdErdu3Bm02Wr tQYwtlmIvxp3xYMd4inz5cSaMt4s2FMKufiUzu/0EFwuBz/raspTDL8Ly S+bUjVF2DqjkIeWKURsAo7bSoJ/5axSMP0kQuUiVg6rQNqnsx8WGlhcDr qTdLU87Ku/C3M9pjKcrq0+c0DBqGVZBJdIGJH8WZkIzsMymJ29/rUniVq Q==; X-CSE-ConnectionGUID: 0rJBHlQfSGeoCl82pEWVvA== X-CSE-MsgGUID: SweYh90zSZicL4GrOM6jew== X-IronPort-AV: E=McAfee;i="6700,10204,11182"; a="41330934" X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="41330934" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:51:19 -0700 X-CSE-ConnectionGUID: i86dORhiSZKXq4JfMfiPBw== X-CSE-MsgGUID: p7gI1qLiQJC0xQXLInItlA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="87821589" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:51:18 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org, markus.t.metzger@intel.com Subject: [PATCH 6/7] btrace: Add support for further events. Date: Mon, 2 Sep 2024 13:49:48 +0200 Message-Id: <20240902114949.918485-7-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240902114949.918485-1-felix.willgerodt@intel.com> References: <20240902114949.918485-1-felix.willgerodt@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org This is similar to the previous events that we added, and adds support for SMI, RSM, SIPI, INIT, VMENTRY, VMEXIT, SHUTDOWN. Though since these are mainly mechanical and not really possible to test, they are bundled in one commit. --- gdb/btrace.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/gdb/btrace.c b/gdb/btrace.c index bcfa11444e7..9d2a9aaa1e9 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -1426,6 +1426,132 @@ handle_pt_insn_events (struct btrace_thread_info *btinfo, handle_pt_aux_insn (btinfo, aux_string, pc); break; } + + case ptev_smi: + { + std::string aux_string = std::string (_("smi")); + + if (event.ip_suppressed == 0) + { + pc = event.variant.smi.ip; + aux_string += std::string (": ip = ") + hex_string (pc); + } + + handle_pt_aux_insn (btinfo, aux_string, pc); + break; + } + + case ptev_rsm: + { + std::string aux_string = std::string (_("rsm")); + + if (event.ip_suppressed == 0) + { + pc = event.variant.rsm.ip; + aux_string += std::string (": ip = ") + hex_string (pc); + } + + handle_pt_aux_insn (btinfo, aux_string, pc); + break; + } + + case ptev_sipi: + { + std::string aux_string = std::string (_("sipi: vector = ")) + + hex_string (event.variant.sipi.vector); + + handle_pt_aux_insn (btinfo, aux_string, pc); + break; + } + + case ptev_init: + { + std::string aux_string = std::string (_("init")); + + if (event.ip_suppressed == 0) + { + pc = event.variant.init.ip; + aux_string += std::string (": ip = ") + hex_string (pc); + } + + handle_pt_aux_insn (btinfo, aux_string, pc); + break; + } + + case ptev_vmentry: + { + std::string aux_string = std::string (_("vmentry")); + + if (event.ip_suppressed == 0) + { + pc = event.variant.vmentry.ip; + aux_string += std::string (": ip = ") + hex_string (pc); + } + + handle_pt_aux_insn (btinfo, aux_string, pc); + break; + } + + case ptev_vmexit: + { + std::string aux_string = std::string (_("vmexit")); + + if (event.variant.vmexit.has_vector != 0 + || event.variant.vmexit.has_vmxr != 0 + || event.variant.vmexit.has_vmxq != 0 + || event.ip_suppressed != 0) + aux_string += std::string (":"); + + if (event.variant.vmexit.has_vector != 0) + { + aux_string += std::string (_(" vector = ")) + + hex_string (event.variant.vmexit.vector); + + const char* decoded = decode_interrupt_vector + (event.variant.vmexit.vector); + if (decoded != nullptr) + aux_string += std::string (" (") + decoded + ")"; + } + + if (event.variant.vmexit.has_vmxr != 0) + { + std::string seperator = aux_string.back () == ':' ? "" : ","; + aux_string += seperator + std::string (" vmxr = ") + + hex_string (event.variant.vmexit.vmxr); + } + + if (event.variant.vmexit.has_vmxq != 0) + { + std::string seperator = aux_string.back () == ':' ? "" : ","; + aux_string += seperator + std::string (" vmxq = ") + + hex_string (event.variant.vmexit.vmxq); + } + + if (event.ip_suppressed == 0) + { + pc = event.variant.vmexit.ip; + std::string seperator = aux_string.back () == ':' ? "" : ","; + aux_string += seperator + std::string (" ip = ") + + hex_string (pc); + } + + handle_pt_aux_insn (btinfo, aux_string, pc); + break; + } + + case ptev_shutdown: + { + std::string aux_string = std::string (_("shutdown")); + + if (event.ip_suppressed == 0) + { + pc = event.variant.shutdown.ip; + aux_string += std::string (": ip = ") + hex_string (pc); + } + + handle_pt_aux_insn (btinfo, aux_string, pc); + break; + } #endif /* defined (LIBIPT_VERSION >= 0x201) */ } } From patchwork Mon Sep 2 11:49:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Willgerodt X-Patchwork-Id: 96902 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 582AE385DDE5 for ; Mon, 2 Sep 2024 11:52:34 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) by sourceware.org (Postfix) with ESMTPS id CB87E385ED72 for ; Mon, 2 Sep 2024 11:51:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB87E385ED72 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 CB87E385ED72 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277890; cv=none; b=v22u6taVlv5COQGLw53t+ehLD8QKfPZcsM3+FtC7cFUmq6mg1DwWALrx3EwiLVtLAn2HyhP/BU9lKwNuthdsPQXVLVggwNKwGuzp2Ks8/zOYJU8iflXqYCn8AdUHzz9vaeiuSf8KSdAiMPyqYNWhfte4TKEmcHk34r7yOU4qTnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725277890; c=relaxed/simple; bh=qaJbxezt6vNlcYjJryWCjL03zqS6E5HHrg7MxDWHwxM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=l/J3bnmPSmPp7lpEIgYLPg3atfXnGGMZwRoAkTDuV/pIQ6y/wyztSQ2orPp6fjhM8SMnokqnq4ehQZQGRwO58LQvJKk87vhQJTxDHfYOR3tZ9eqHdGMC+R1/HP9ubLaMuZCAbmm+esI9cEpwTeDRIY23I5Lx8ydoWmM8dtkDamI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725277887; x=1756813887; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=qaJbxezt6vNlcYjJryWCjL03zqS6E5HHrg7MxDWHwxM=; b=BPBuhYEmaMko6EvkK3hlgnYJ/GTHgjYCIkYu79lSkh9ByBhO4yZ1LpXV iDJ/DsIX/4i0G2xf6wnWSkorZw5sQ5aNuoIv1kMjDI4Xon892IC/4NYtu jlpIqv1a/78UXi1NG9CEKavyib53SLnGJDARcgDI8OWLXiXiz8bj/DIIs 0ed1FUBR/SFqnR5r2ohfZMo1RnEpRSbRvwTVBRHTwH8Eo6eEXZ3YruXzR dDraPCzV2Rv4gxRd1RJgigf3U8TcEcZCNGTOwrMAlw/NoYCjRpre1EWCw o6X9qire8XzJCVxBQt1tsq07BHEjwjjlM+xOGcDF3PYDH39vmNILzTbFq Q==; X-CSE-ConnectionGUID: lsEpYFzfT4Oze7J7p9lO6A== X-CSE-MsgGUID: oeH+hMRUSnKBDjZo8Rk61Q== X-IronPort-AV: E=McAfee;i="6700,10204,11182"; a="23425056" X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="23425056" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:51:26 -0700 X-CSE-ConnectionGUID: 6AbK8O57QVe1qO+Dm0besQ== X-CSE-MsgGUID: zfNroPyqRM+wgeZ8Dy20rQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,195,1719903600"; d="scan'208";a="64627528" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 04:51:25 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org, markus.t.metzger@intel.com Subject: [PATCH 7/7] btrace: Add support for UINTR and UIRET events. Date: Mon, 2 Sep 2024 13:49:49 +0200 Message-Id: <20240902114949.918485-8-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240902114949.918485-1-felix.willgerodt@intel.com> References: <20240902114949.918485-1-felix.willgerodt@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org This is similar to the previous events that we added. --- gdb/btrace.c | 29 ++++++ gdb/testsuite/gdb.btrace/uli.c | 132 ++++++++++++++++++++++++ gdb/testsuite/gdb.btrace/uli_events.exp | 51 +++++++++ 3 files changed, 212 insertions(+) create mode 100644 gdb/testsuite/gdb.btrace/uli.c create mode 100644 gdb/testsuite/gdb.btrace/uli_events.exp diff --git a/gdb/btrace.c b/gdb/btrace.c index 9d2a9aaa1e9..2fc9d62a894 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -1552,6 +1552,35 @@ handle_pt_insn_events (struct btrace_thread_info *btinfo, handle_pt_aux_insn (btinfo, aux_string, pc); break; } + + case ptev_uintr: + { + std::string aux_string = std::string (_("uintr: vector = ")) + + hex_string (event.variant.uintr.vector); + + if (event.ip_suppressed == 0) + { + pc = event.variant.uintr.ip; + aux_string += std::string (", ip = ") + hex_string (pc); + } + + handle_pt_aux_insn (btinfo, aux_string, pc); + break; + } + + case ptev_uiret: + { + std::string aux_string = std::string (_("uiret")); + + if (event.ip_suppressed == 0) + { + pc = event.variant.uiret.ip; + aux_string += std::string (": ip = ") + hex_string (pc); + } + + handle_pt_aux_insn (btinfo, aux_string, pc); + break; + } #endif /* defined (LIBIPT_VERSION >= 0x201) */ } } diff --git a/gdb/testsuite/gdb.btrace/uli.c b/gdb/testsuite/gdb.btrace/uli.c new file mode 100644 index 00000000000..fd4d601f2ab --- /dev/null +++ b/gdb/testsuite/gdb.btrace/uli.c @@ -0,0 +1,132 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2021-2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include +#include +#include +#include +#include +#include + +#define UINTR_HANDLER_REG_SYSCALL 471 +#define UINTR_HANDLER_UNREG_SYSCALL 472 +#define UINTR_CREATE_FD_SYSCALL 473 +#define UINTR_SEND_REG_SYSCALL 474 +#define UINTR_SEND_UNREG_SYSCALL 475 + +unsigned long uintr_received; +unsigned int uintr_fd; + +int +uintr_register_handler (void *ui_handler, unsigned int flags) +{ + return syscall (UINTR_HANDLER_REG_SYSCALL, ui_handler, flags); +} + +int +uintr_unregister_handler (unsigned int flags) +{ + return syscall (UINTR_HANDLER_UNREG_SYSCALL, flags); +} + +int +uintr_create_fd (int vector, unsigned int flags) +{ + return syscall (UINTR_CREATE_FD_SYSCALL, vector, flags); +} + +int +uintr_register_sender (int uintr_fd, unsigned int flags) +{ + return syscall (UINTR_SEND_REG_SYSCALL, uintr_fd, flags); +} + +int +uintr_unregister_sender (int uintr_fd, unsigned int flags) +{ + return syscall (UINTR_SEND_UNREG_SYSCALL, uintr_fd, flags); +} + +void __attribute__ ((interrupt)) +ui_handler (struct __uintr_frame *ui_frame, unsigned long long vector) +{ + static const char print[] = "\t-- User Interrupt handler --\n"; + + write (STDOUT_FILENO, print, sizeof (print) - 1); /* bp4 */ + uintr_received = 1; +} + +void * +sender_thread (void *arg) +{ + int uipi_index; + + uipi_index = uintr_register_sender (uintr_fd, 0); + if (uipi_index < 0) + { + printf ("Sender register error\n"); + exit (EXIT_FAILURE); + } + + printf ("Sending IPI from sender thread\n"); + _senduipi (uipi_index); /* bp2 */ + + uintr_unregister_sender (uintr_fd, 0); + + return NULL; +} + +int +main () +{ + pthread_t pt; + int ret; + + if (uintr_register_handler (ui_handler, 0)) + { + printf ("Interrupt handler register error\n"); + exit (EXIT_FAILURE); + } + + ret = uintr_create_fd (0, 0); + if (ret < 0) + { + printf ("Interrupt vector allocation error\n"); + exit (EXIT_FAILURE); + } + + uintr_fd = ret; + + _stui (); + printf ("Receiver enabled interrupts\n"); + + if (pthread_create (&pt, NULL, &sender_thread, NULL)) + { + printf ("Error creating sender thread\n"); + exit (EXIT_FAILURE); + } + + /* Do some other work */ + while (!uintr_received); /* bp3 */ + + pthread_join (pt, NULL); /* bp1 */ + close (uintr_fd); + uintr_unregister_handler (0); + + printf ("Success\n"); + exit (EXIT_SUCCESS); +} diff --git a/gdb/testsuite/gdb.btrace/uli_events.exp b/gdb/testsuite/gdb.btrace/uli_events.exp new file mode 100644 index 00000000000..b8e86844c82 --- /dev/null +++ b/gdb/testsuite/gdb.btrace/uli_events.exp @@ -0,0 +1,51 @@ +# This testcase is part of GDB, the GNU debugger. +# +# Copyright 2024 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test UIRET and UINTR events. + +require allow_btrace_tests allow_btrace_event_trace_tests + +set opts [list debug "additional_flags=-muintr -mgeneral-regs-only -minline-all-stringops"] + +standard_testfile uli.c +if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable $opts] != ""} { + return -1 +} +clean_restart $testfile + +if ![runto_main] { + untested "failed to run to main" + return -1 +} + +set bp_1 [gdb_get_line_number "bp1"] + +gdb_breakpoint $bp_1 + +gdb_test_no_output "set record function-call-history-size unlimited" +gdb_test_no_output "set record btrace pt event-tracing on" +gdb_test_no_output "record btrace pt" +gdb_continue_to_breakpoint "break at bp_1" ".*$srcfile:$bp_1.*" + +# Test function call history. +# ui_handler can be preceded by any function depending on the scheduling. +gdb_test_sequence "record function-call-history" "function-call-history" { + "\\\[uintr: vector = 0x\[0-9a-fA-F\]+( \\\(#\[a-z\]+\\\))?, ip = 0x\[0-9a-fA-F\]+\\\]" + "\[0-9\]+\tui_handler" + "\\\[uiret(: ip = 0x\[0-9a-fA-F\]+)?\\\]" + "\[0-9\]+\tmain" +}