[06/10] python: Add clear_trace() to gdb.Record.
Commit Message
From: Felix Willgerodt <felix.willgerodt@intel.com>
This function allows to clear the trace data from python, forcing to
re-decode the trace for successive commands.
2019-05-29 Felix Willgerodt <felix.willgerodt@intel.com>
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(-)
Comments
> From: felix.willgerodt@intel.com
> Cc: markus.t.metzger@intel.com, Felix Willgerodt <felix.willgerodt@intel.com>
> Date: Wed, 29 May 2019 10:47:49 +0200
>
> gdb/doc/ChangeLog:
> * python.texi (gdb.Record): Document btrace_clear().
OK for this part.
Hello Felix,
> 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. */
This does not match the documentation, which uses 'clear_trace'. More
instances below.
Personally, I like 'clear' better since it is shorter and the context should be
clear enough given that it is a Record method.
> @@ -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)
Comment and function name don't match.
> 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()"
Why are we not using 'r' as we do below?
I wonder what would happen if we accessed 'i', 'c', 'insn', or 'call' here.
> + 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.20.1
Thanks,
Markus.
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
@@ -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:
@@ -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[] =
@@ -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);
@@ -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 }
};
@@ -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" {