diff options
Diffstat (limited to 'gdb/python/py-record.c')
-rw-r--r-- | gdb/python/py-record.c | 95 |
1 files changed, 82 insertions, 13 deletions
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c index d489126..7e7904b 100644 --- a/gdb/python/py-record.c +++ b/gdb/python/py-record.c @@ -1,6 +1,6 @@ /* Python interface to record targets. - Copyright 2016-2024 Free Software Foundation, Inc. + Copyright 2016-2025 Free Software Foundation, Inc. This file is part of GDB. @@ -48,6 +48,12 @@ static PyTypeObject recpy_gap_type = { PyVarObject_HEAD_INIT (NULL, 0) }; +/* Python RecordAuxiliary type. */ + +PyTypeObject recpy_aux_type = { + PyVarObject_HEAD_INIT (nullptr, 0) +}; + /* Python RecordGap object. */ struct recpy_gap_object { @@ -108,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 * @@ -389,8 +408,8 @@ recpy_element_hash (PyObject *self) return obj->number; } -/* Implementation of operator == and != of RecordInstruction and - RecordFunctionSegment. */ +/* Implementation of operator == and != of RecordInstruction, + RecordFunctionSegment and RecordAuxiliary. */ static PyObject * recpy_element_richcompare (PyObject *self, PyObject *other, int op) @@ -478,12 +497,47 @@ recpy_gap_reason_string (PyObject *self, void *closure) return PyUnicode_FromString (obj->reason_string); } +/* Create a new gdb.Auxiliary object. */ + +PyObject * +recpy_aux_new (thread_info *thread, enum record_method method, + Py_ssize_t number) +{ + recpy_element_object * const obj = PyObject_New (recpy_element_object, + &recpy_aux_type); + + if (obj == NULL) + return NULL; + + obj->thread = thread; + obj->method = method; + obj->number = number; + + return (PyObject *) obj; +} + +/* Implementation of Auxiliary.data [buffer]. */ + +static PyObject * +recpy_aux_data (PyObject *self, void *closure) +{ + const recpy_element_object * const obj = (recpy_element_object *) self; + + if (obj->method == RECORD_METHOD_BTRACE) + return recpy_bt_aux_data (self, closure); + + return PyErr_Format (PyExc_NotImplementedError, _("Not implemented.")); +} + /* Record method list. */ 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 } }; @@ -543,6 +597,14 @@ static gdb_PyGetSetDef recpy_gap_getset[] = { { NULL } }; +/* RecordAuxiliary member list. */ + +static gdb_PyGetSetDef recpy_aux_getset[] = { + { "number", recpy_element_number, nullptr, "element number", nullptr}, + { "data", recpy_aux_data, nullptr, "data", nullptr}, + { nullptr } +}; + /* Sets up the record API in the gdb module. */ static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION @@ -582,10 +644,20 @@ gdbpy_initialize_record (void) recpy_gap_type.tp_doc = "GDB recorded gap object"; recpy_gap_type.tp_getset = recpy_gap_getset; - if (PyType_Ready (&recpy_record_type) < 0 - || PyType_Ready (&recpy_insn_type) < 0 - || PyType_Ready (&recpy_func_type) < 0 - || PyType_Ready (&recpy_gap_type) < 0) + recpy_aux_type.tp_new = PyType_GenericNew; + recpy_aux_type.tp_flags = Py_TPFLAGS_DEFAULT; + recpy_aux_type.tp_basicsize = sizeof (recpy_element_object); + recpy_aux_type.tp_name = "gdb.RecordAuxiliary"; + recpy_aux_type.tp_doc = "GDB recorded auxiliary object"; + recpy_aux_type.tp_getset = recpy_aux_getset; + recpy_aux_type.tp_richcompare = recpy_element_richcompare; + recpy_aux_type.tp_hash = recpy_element_hash; + + if (gdbpy_type_ready (&recpy_record_type) < 0 + || gdbpy_type_ready (&recpy_insn_type) < 0 + || gdbpy_type_ready (&recpy_func_type) < 0 + || gdbpy_type_ready (&recpy_gap_type) < 0 + || gdbpy_type_ready (&recpy_aux_type) < 0) return -1; else return 0; @@ -598,7 +670,6 @@ gdbpy_start_recording (PyObject *self, PyObject *args) { const char *method = NULL; const char *format = NULL; - PyObject *ret = NULL; if (!PyArg_ParseTuple (args, "|ss", &method, &format)) return NULL; @@ -606,14 +677,12 @@ gdbpy_start_recording (PyObject *self, PyObject *args) try { record_start (method, format, 0); - ret = gdbpy_current_recording (self, args); + return gdbpy_current_recording (self, args); } catch (const gdb_exception &except) { - gdbpy_convert_exception (except); + return gdbpy_handle_gdb_exception (nullptr, except); } - - return ret; } /* Implementation of gdb.current_recording (self) -> gdb.Record. */ @@ -644,7 +713,7 @@ gdbpy_stop_recording (PyObject *self, PyObject *args) } catch (const gdb_exception &except) { - GDB_PY_HANDLE_EXCEPTION (except); + return gdbpy_handle_gdb_exception (nullptr, except); } Py_RETURN_NONE; |