]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
python: Add clear() to gdb.Record.
authorFelix Willgerodt <felix.willgerodt@intel.com>
Mon, 25 Feb 2019 14:30:29 +0000 (15:30 +0100)
committerFelix Willgerodt <felix.willgerodt@intel.com>
Wed, 14 Aug 2024 09:20:56 +0000 (11:20 +0200)
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>
Approved-By: Markus Metzger <markus.t.metzger@intel.com>
gdb/NEWS
gdb/doc/python.texi
gdb/python/py-record-btrace.c
gdb/python/py-record-btrace.h
gdb/python/py-record.c
gdb/testsuite/gdb.python/py-record-btrace.exp

index c656ea78c5618e889bd7153be0af668563256c0c..dfcabb1677e11dd027065907525c60f3e99522ba 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,11 @@
 
 *** Changes since GDB 15
 
+* Python API
+
+  ** Added gdb.record.clear.  Clears the trace data of the current recording.
+     This forces re-decoding of the trace for successive commands.
+
 * Debugger Adapter Protocol changes
 
   ** The "scopes" request will now return a scope holding global
index 05e50591d9946d059a88aefb2361a4065e1abbc4..83e8c6037eaee92968e4c58d6e56ee7b3c759d60 100644 (file)
@@ -4314,6 +4314,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:
 
index 0ff2708801be19abd3f355b6a16741fbaf93a0f4..49b6c741dcf74cc793d746e5ffadd823faf4fa79 100644 (file)
@@ -847,6 +847,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[] =
index 5010cb3f95dd7ad5400ff8683831dab8d5c96e51..3be5860d2c460338b1a98d2faae1ef467c315482 100644 (file)
@@ -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);
 
index 0efd631200b79e5b90f28f651931dcf4c2e6a09d..2e0834c15ac137b4ffa109b36362ae32919ecee5 100644 (file)
@@ -114,6 +114,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 *
@@ -522,6 +535,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 }
 };
 
index fba0b98f79428ff3f87e5c6d87f4aac75de581e0..0731af1b0f8ec1ec1d9d85e5aa2e9da1384b5cb9 100644 (file)
@@ -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" "size after clear"
 }
 
 with_test_prefix "function call" {