1 /* Python interface to record targets.
3 Copyright 2016-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "py-record.h"
22 #include "py-record-btrace.h"
23 #include "py-record-full.h"
26 /* Python Record type. */
28 static PyTypeObject recpy_record_type
= {
29 PyVarObject_HEAD_INIT (NULL
, 0)
32 /* Implementation of record.method. */
35 recpy_method (PyObject
*self
, void* closure
)
37 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
39 if (obj
->method
== RECORD_METHOD_FULL
)
40 return recpy_full_method (self
, closure
);
42 if (obj
->method
== RECORD_METHOD_BTRACE
)
43 return recpy_bt_method (self
, closure
);
45 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
48 /* Implementation of record.format. */
51 recpy_format (PyObject
*self
, void* closure
)
53 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
55 if (obj
->method
== RECORD_METHOD_FULL
)
56 return recpy_full_format (self
, closure
);
58 if (obj
->method
== RECORD_METHOD_BTRACE
)
59 return recpy_bt_format (self
, closure
);
61 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
64 /* Implementation of record.goto (instruction) -> None. */
67 recpy_goto (PyObject
*self
, PyObject
*value
)
69 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
71 if (obj
->method
== RECORD_METHOD_BTRACE
)
72 return recpy_bt_goto (self
, value
);
74 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
77 /* Implementation of record.replay_position [instruction] */
80 recpy_replay_position (PyObject
*self
, void *closure
)
82 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
84 if (obj
->method
== RECORD_METHOD_BTRACE
)
85 return recpy_bt_replay_position (self
, closure
);
87 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
90 /* Implementation of record.instruction_history [list]. */
93 recpy_instruction_history (PyObject
*self
, void* closure
)
95 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
97 if (obj
->method
== RECORD_METHOD_BTRACE
)
98 return recpy_bt_instruction_history (self
, closure
);
100 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
103 /* Implementation of record.function_call_history [list]. */
106 recpy_function_call_history (PyObject
*self
, void* closure
)
108 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
110 if (obj
->method
== RECORD_METHOD_BTRACE
)
111 return recpy_bt_function_call_history (self
, closure
);
113 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
116 /* Implementation of record.begin [instruction]. */
119 recpy_begin (PyObject
*self
, void* closure
)
121 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
123 if (obj
->method
== RECORD_METHOD_BTRACE
)
124 return recpy_bt_begin (self
, closure
);
126 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
129 /* Implementation of record.end [instruction]. */
132 recpy_end (PyObject
*self
, void* closure
)
134 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
136 if (obj
->method
== RECORD_METHOD_BTRACE
)
137 return recpy_bt_end (self
, closure
);
139 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
142 /* Record method list. */
144 static PyMethodDef recpy_record_methods
[] = {
145 { "goto", recpy_goto
, METH_VARARGS
,
146 "goto (instruction|function_call) -> None.\n\
147 Rewind to given location."},
151 /* Record member list. */
153 static gdb_PyGetSetDef recpy_record_getset
[] = {
154 { "method", recpy_method
, NULL
, "Current recording method.", NULL
},
155 { "format", recpy_format
, NULL
, "Current recording format.", NULL
},
156 { "replay_position", recpy_replay_position
, NULL
, "Current replay position.",
158 { "instruction_history", recpy_instruction_history
, NULL
,
159 "List of instructions in current recording.", NULL
},
160 { "function_call_history", recpy_function_call_history
, NULL
,
161 "List of function calls in current recording.", NULL
},
162 { "begin", recpy_begin
, NULL
,
163 "First instruction in current recording.", NULL
},
164 { "end", recpy_end
, NULL
,
165 "One past the last instruction in current recording. This is typically \
166 the current instruction and is used for e.g. record.goto (record.end).", NULL
},
170 /* Sets up the record API in the gdb module. */
173 gdbpy_initialize_record (void)
175 recpy_record_type
.tp_new
= PyType_GenericNew
;
176 recpy_record_type
.tp_flags
= Py_TPFLAGS_DEFAULT
;
177 recpy_record_type
.tp_basicsize
= sizeof (recpy_record_object
);
178 recpy_record_type
.tp_name
= "gdb.Record";
179 recpy_record_type
.tp_doc
= "GDB record object";
180 recpy_record_type
.tp_methods
= recpy_record_methods
;
181 recpy_record_type
.tp_getset
= recpy_record_getset
;
183 return PyType_Ready (&recpy_record_type
);
186 /* Implementation of gdb.start_recording (method) -> gdb.Record. */
189 gdbpy_start_recording (PyObject
*self
, PyObject
*args
)
191 const char *method
= NULL
;
192 const char *format
= NULL
;
193 PyObject
*ret
= NULL
;
195 if (!PyArg_ParseTuple (args
, "|ss", &method
, &format
))
200 record_start (method
, format
, 0);
201 ret
= gdbpy_current_recording (self
, args
);
203 CATCH (except
, RETURN_MASK_ALL
)
205 gdbpy_convert_exception (except
);
212 /* Implementation of gdb.current_recording (self) -> gdb.Record. */
215 gdbpy_current_recording (PyObject
*self
, PyObject
*args
)
217 recpy_record_object
*ret
= NULL
;
219 if (find_record_target () == NULL
)
222 ret
= PyObject_New (recpy_record_object
, &recpy_record_type
);
223 ret
->ptid
= inferior_ptid
;
224 ret
->method
= target_record_method (inferior_ptid
);
226 return (PyObject
*) ret
;
229 /* Implementation of gdb.stop_recording (self) -> None. */
232 gdbpy_stop_recording (PyObject
*self
, PyObject
*args
)
234 PyObject
*ret
= NULL
;
242 CATCH (except
, RETURN_MASK_ALL
)
244 gdbpy_convert_exception (except
);