From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by sourceware.org (Postfix) with ESMTPS id DA0ED385772C for ; Tue, 4 Jul 2023 12:36:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA0ED385772C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1688474196; x=1720010196; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=noyyNLsC/5/0QU0olL2A9g2iaVwKO18qnspANUd35L8=; b=Y/86SWJWL7lVXtfpb6ny0qc4hGQChYf/+1OrNYomIfIoXmPBpVopMt58 wBCB+lrahe9wdZH38qXk6NAJkEGCWYT+6jKFpTnp8skkBw179kAlNNlfx 367DnRcIw6K7P5zNPIiTK/7Hb825IjGef4NVITccgPT8gUMnAtHpBbbjQ nh9cFsE9kPetwoPHfWnqXiUioJ1L22lqZTbXvkAQDR+HhYCYJKA7No0na cd0cbJHk1In5AFYSZIlIUarQpOo+wz5Nszue13Abi2oHHDjqy1+jCd6TT jOU7v9GA6CzRTZzWHPyrqqkYcU+Z09hlBpLtO/Ho7w4f8fnbQ/6vQio18 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10760"; a="361974926" X-IronPort-AV: E=Sophos;i="6.01,180,1684825200"; d="scan'208";a="361974926" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jul 2023 05:36:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10760"; a="808923593" X-IronPort-AV: E=Sophos;i="6.01,180,1684825200"; d="scan'208";a="808923593" Received: from unknown (HELO localhost) ([10.216.210.17]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jul 2023 05:36:35 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org, markus.t.metzger@intel.com, simark@simark.ca Cc: Felix Willgerodt Subject: [PATCH v9 06/10] python: Add clear() to gdb.Record. Date: Tue, 4 Jul 2023 14:35:56 +0200 Message-Id: <20230704123600.5944-7-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230704123600.5944-1-felix.willgerodt@intel.com> References: <20230704123600.5944-1-felix.willgerodt@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.4 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 List-Id: This function allows to clear the trace data from python, forcing to re-decode the trace for successive commands. This will be used in future ptwrite patches, to trigger re-decoding when the ptwrite filter changes. --- gdb/doc/python.texi | 5 +++++ gdb/python/py-record-btrace.c | 13 +++++++++++++ gdb/python/py-record-btrace.h | 3 +++ gdb/python/py-record.c | 16 ++++++++++++++++ gdb/testsuite/gdb.python/py-record-btrace.exp | 4 ++++ 5 files changed, 41 insertions(+) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index b2140b1b8ea..e0afa68541a 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -4051,6 +4051,11 @@ A @code{gdb.Record} object has the following methods: Move the replay position to the given @var{instruction}. @end defun +@defun Record.clear () +Clear the trace data of the current recording. This forces re-decoding of the +trace for successive commands. +@end defun + The common @code{gdb.Instruction} class that recording method specific instruction objects inherit from, has the following attributes: diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c index 4a2a61e9b91..7e5bd2c401e 100644 --- a/gdb/python/py-record-btrace.c +++ b/gdb/python/py-record-btrace.c @@ -845,6 +845,19 @@ recpy_bt_goto (PyObject *self, PyObject *args) Py_RETURN_NONE; } +/* Implementation of BtraceRecord.clear (self) -> None. */ + +PyObject * +recpy_bt_clear (PyObject *self, PyObject *args) +{ + const recpy_record_object * const record = (recpy_record_object *) self; + thread_info *const tinfo = record->thread; + + btrace_clear (tinfo); + + Py_RETURN_NONE; +} + /* BtraceList methods. */ static PyMethodDef btpy_list_methods[] = diff --git a/gdb/python/py-record-btrace.h b/gdb/python/py-record-btrace.h index 0ca3da8e86f..785999e29e3 100644 --- a/gdb/python/py-record-btrace.h +++ b/gdb/python/py-record-btrace.h @@ -31,6 +31,9 @@ extern PyObject *recpy_bt_format (PyObject *self, void *closure); /* Implementation of record.goto (instruction) -> None. */ extern PyObject *recpy_bt_goto (PyObject *self, PyObject *value); +/* Implementation of BtraceRecord.clear (self) -> None. */ +extern PyObject *recpy_bt_clear (PyObject *self, PyObject *args); + /* Implementation of record.instruction_history [list]. */ extern PyObject *recpy_bt_instruction_history (PyObject *self, void *closure); diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c index c093cdaf3d6..7824dd25953 100644 --- a/gdb/python/py-record.c +++ b/gdb/python/py-record.c @@ -115,6 +115,19 @@ recpy_goto (PyObject *self, PyObject *value) return PyErr_Format (PyExc_NotImplementedError, _("Not implemented.")); } +/* Implementation of record.clear () -> None. */ + +static PyObject * +recpy_clear (PyObject *self, PyObject *value) +{ + const recpy_record_object * const obj = (recpy_record_object *) self; + + if (obj->method == RECORD_METHOD_BTRACE) + return recpy_bt_clear (self, value); + + return PyErr_Format (PyExc_NotImplementedError, _("Not implemented.")); +} + /* Implementation of record.replay_position [instruction] */ static PyObject * @@ -523,6 +536,9 @@ static PyMethodDef recpy_record_methods[] = { { "goto", recpy_goto, METH_VARARGS, "goto (instruction|function_call) -> None.\n\ Rewind to given location."}, + { "clear", recpy_clear, METH_VARARGS, + "clear () -> None.\n\ +Clears the trace."}, { NULL } }; diff --git a/gdb/testsuite/gdb.python/py-record-btrace.exp b/gdb/testsuite/gdb.python/py-record-btrace.exp index bd397d3c974..fd45891fdfa 100644 --- a/gdb/testsuite/gdb.python/py-record-btrace.exp +++ b/gdb/testsuite/gdb.python/py-record-btrace.exp @@ -144,6 +144,10 @@ with_test_prefix "instruction " { gdb_test "python print(i.decoded)" ".*" gdb_test "python print(i.size)" "$decimal" gdb_test "python print(i.is_speculative)" "False" + gdb_test_no_output "python r.clear()" + gdb_test "python insn = r.instruction_history" + gdb_test_no_output "python i = insn\[0\]" + gdb_test "python print(i.size)" "$decimal" } with_test_prefix "function call" { -- 2.34.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928