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 557283856DC0 for ; Fri, 21 Oct 2022 12:02:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 557283856DC0 X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="305723559" X-IronPort-AV: E=Sophos;i="5.95,200,1661842800"; d="scan'208";a="305723559" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2022 05:02:43 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="773013231" X-IronPort-AV: E=Sophos;i="5.95,200,1661842800"; d="scan'208";a="773013231" Received: from mulvlfelix.iul.intel.com (HELO localhost) ([172.28.48.92]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2022 05:02:41 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org, markus.t.metzger@intel.com Subject: [PATCH v7 06/10] python: Add clear() to gdb.Record. Date: Fri, 21 Oct 2022 13:59:43 +0200 Message-Id: <20221021115947.359223-7-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20221021115947.359223-1-felix.willgerodt@intel.com> References: <20221021115947.359223-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.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 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Oct 2022 12:04:45 -0000 This function allows to clear the trace data from python, forcing to re-decode the trace for successive commands. --- 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 | 6 +++++- 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 8561bb6c8f1..2820e4d56e3 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3836,6 +3836,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 1dab097335b..c09ba6271b5 100644 --- a/gdb/python/py-record-btrace.c +++ b/gdb/python/py-record-btrace.c @@ -802,6 +802,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 8ef26c860db..b25b121d255 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 a7e091f3770..a908083a813 100644 --- a/gdb/python/py-record.c +++ b/gdb/python/py-record.c @@ -127,6 +127,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 * @@ -538,6 +551,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 e9fdd06154e..82d887dbd18 100644 --- a/gdb/testsuite/gdb.python/py-record-btrace.exp +++ b/gdb/testsuite/gdb.python/py-record-btrace.exp @@ -88,7 +88,11 @@ with_test_prefix "instruction " { gdb_test "python print(repr(i.data))" "" gdb_test "python print(i.decoded)" ".*" gdb_test "python print(i.size)" "$decimal" - gdb_test "python print(i.is_speculative)" "False" + 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.3 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 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 557283856DC0 for ; Fri, 21 Oct 2022 12:02:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 557283856DC0 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=1666353766; x=1697889766; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ECC/ZCq1p4Qj3QI1WaE92YZ08Ywp6Y5ya9eDPNzu2lE=; b=hhEAkzv8THx/CeOR4Q228mxFi/mUt//omiod7L5U756lfRU/YmsnMzz8 0tx9tBjApAPrnKyy4H36hUOq9Gu/S5Lc/ll+0lWEizsn3DqIS4jtSjkxP m2RXCDpI+G/Ks4afoqXCx8uR3bFmB6uIkPEvanqv7nQ/7hW9yBjwa40tD axz+SHQSfzF5OHFw01sFkN0gMpDKTV+MjolQTtOj91HF9FW1rlQwbyNG/ rvumKe/jn3AtS7zIqb0LnxGe2bj71T1Z7TK8LXElJLL/vzGAVD4HOPKX2 01JQx8ns9n70o193hVcN4rB4jQjfwEOU3q1p8YshJwuyrplAhSxfhk4yL A==; X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="305723559" X-IronPort-AV: E=Sophos;i="5.95,200,1661842800"; d="scan'208";a="305723559" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2022 05:02:43 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="773013231" X-IronPort-AV: E=Sophos;i="5.95,200,1661842800"; d="scan'208";a="773013231" Received: from mulvlfelix.iul.intel.com (HELO localhost) ([172.28.48.92]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2022 05:02:41 -0700 From: Felix Willgerodt To: gdb-patches@sourceware.org, markus.t.metzger@intel.com Cc: Felix Willgerodt Subject: [PATCH v7 06/10] python: Add clear() to gdb.Record. Date: Fri, 21 Oct 2022 13:59:43 +0200 Message-ID: <20221021115947.359223-7-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20221021115947.359223-1-felix.willgerodt@intel.com> References: <20221021115947.359223-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.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 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: Message-ID: <20221021115943.SCsaejfoQf5O5yWUh-qi4sxidp0iF4QTd2XwSjF03k0@z> This function allows to clear the trace data from python, forcing to re-decode the trace for successive commands. --- 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 | 6 +++++- 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 8561bb6c8f1..2820e4d56e3 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3836,6 +3836,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 1dab097335b..c09ba6271b5 100644 --- a/gdb/python/py-record-btrace.c +++ b/gdb/python/py-record-btrace.c @@ -802,6 +802,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 8ef26c860db..b25b121d255 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 a7e091f3770..a908083a813 100644 --- a/gdb/python/py-record.c +++ b/gdb/python/py-record.c @@ -127,6 +127,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 * @@ -538,6 +551,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 e9fdd06154e..82d887dbd18 100644 --- a/gdb/testsuite/gdb.python/py-record-btrace.exp +++ b/gdb/testsuite/gdb.python/py-record-btrace.exp @@ -88,7 +88,11 @@ with_test_prefix "instruction " { gdb_test "python print(repr(i.data))" "" gdb_test "python print(i.decoded)" ".*" gdb_test "python print(i.size)" "$decimal" - gdb_test "python print(i.is_speculative)" "False" + 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.3 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