[v10,06/10] python: Add clear() to gdb.Record.
Commit Message
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.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
---
gdb/NEWS | 3 +++
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 ++++
6 files changed, 44 insertions(+)
Comments
> Date: Tue, 18 Jul 2023 13:56:33 +0200
> From: Felix Willgerodt via Gdb-patches <gdb-patches@sourceware.org>
>
> 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.
>
> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
> ---
> gdb/NEWS | 3 +++
> 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 ++++
> 6 files changed, 44 insertions(+)
The NEWS part (which AFAIU is the only change in v10,
documentation-wise) is OK. Thanks.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
@@ -157,6 +157,9 @@ info main
* Python API
+ ** Added gdb.record.clear(). Clears the trace data of the current recording.
+ This forces re-decoding of the trace for successive commands.
+
** gdb.ThreadExitedEvent added. Emits a ThreadEvent.
** The gdb.unwinder.Unwinder.name attribute is now read-only.
@@ -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:
@@ -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[] =
@@ -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);
@@ -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 }
};
@@ -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" {