From patchwork Wed May 29 08:47:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Willgerodt, Felix" X-Patchwork-Id: 32884 Received: (qmail 11082 invoked by alias); 29 May 2019 08:48:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 10883 invoked by uid 89); 29 May 2019 08:48:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=H*r:LOCAL, forcing X-HELO: mga01.intel.com Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 May 2019 08:48:15 +0000 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 May 2019 01:48:13 -0700 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga004.jf.intel.com with ESMTP; 29 May 2019 01:48:12 -0700 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id x4T8mBFd007662; Wed, 29 May 2019 09:48:11 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id x4T8mBdL030805; Wed, 29 May 2019 10:48:11 +0200 Received: (from fwillger@localhost) by ulvlx001.iul.intel.com with LOCAL id x4T8mB1A030801; Wed, 29 May 2019 10:48:11 +0200 From: felix.willgerodt@intel.com To: gdb-patches@sourceware.org Cc: markus.t.metzger@intel.com, Felix Willgerodt Subject: [PATCH 06/10] python: Add clear_trace() to gdb.Record. Date: Wed, 29 May 2019 10:47:49 +0200 Message-Id: <1559119673-30516-7-git-send-email-felix.willgerodt@intel.com> In-Reply-To: <1559119673-30516-1-git-send-email-felix.willgerodt@intel.com> References: <1559119673-30516-1-git-send-email-felix.willgerodt@intel.com> X-IsSubscribed: yes From: Felix Willgerodt This function allows to clear the trace data from python, forcing to re-decode the trace for successive commands. 2019-05-29 Felix Willgerodt gdb/ChangeLog: * py-record-btrace.c (recpy_bt_clear): New function. * py-record-btrace.h (recpy_bt_clear): New export. * py-record.c (recpy_clear): New function. (recpy_record_methods): Add clear_trace. testsuite/ChangeLog: * gdb.python/py-record-btrace.exp: Add tests for btrace_clear. gdb/doc/ChangeLog: * python.texi (gdb.Record): Document btrace_clear(). --- 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 d4149f364e1..e892caf9e18 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3439,6 +3439,11 @@ A @code{gdb.Record} object has the following methods: Move the replay position to the given @var{instruction}. @end defun +@defun Record.clear_trace () +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 81e43a00516..2a4af551146 100644 --- a/gdb/python/py-record-btrace.c +++ b/gdb/python/py-record-btrace.c @@ -811,6 +811,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. */ struct PyMethodDef btpy_list_methods[] = diff --git a/gdb/python/py-record-btrace.h b/gdb/python/py-record-btrace.h index 1d8560dace3..8056a5b75cb 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 8b1b3c4e651..855b4089d87 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_trace () -> 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_trace", recpy_clear, METH_VARARGS, + "clear_trace () -> 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 f6267d664a4..72bb69d5908 100644 --- a/gdb/testsuite/gdb.python/py-record-btrace.exp +++ b/gdb/testsuite/gdb.python/py-record-btrace.exp @@ -90,7 +90,11 @@ 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 "python print(i.is_speculative)" "False" + gdb_test_no_output "python gdb.current_recording().clear_trace()" + 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" {