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/>. */
23 #include "python-internal.h"
24 #include "py-record-btrace.h"
25 #include "py-record-full.h"
28 /* Python Record object. */
34 /* The ptid this object refers to. */
37 /* The current recording method. */
38 enum record_method method
;
39 } recpy_record_object
;
41 /* Python Record type. */
43 static PyTypeObject recpy_record_type
= {
44 PyVarObject_HEAD_INIT (NULL
, 0)
47 /* Implementation of record.ptid. */
50 recpy_ptid (PyObject
*self
, void* closure
)
52 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
54 return gdbpy_create_ptid_object (obj
->ptid
);
57 /* Implementation of record.method. */
60 recpy_method (PyObject
*self
, void* closure
)
62 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
64 if (obj
->method
== RECORD_METHOD_FULL
)
65 return recpy_full_method (self
, closure
);
67 if (obj
->method
== RECORD_METHOD_BTRACE
)
68 return recpy_bt_method (self
, closure
);
70 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
73 /* Implementation of record.format. */
76 recpy_format (PyObject
*self
, void* closure
)
78 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
80 if (obj
->method
== RECORD_METHOD_FULL
)
81 return recpy_full_format (self
, closure
);
83 if (obj
->method
== RECORD_METHOD_BTRACE
)
84 return recpy_bt_format (self
, closure
);
86 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
89 /* Implementation of record.goto (instruction) -> None. */
92 recpy_goto (PyObject
*self
, PyObject
*value
)
94 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
96 if (obj
->method
== RECORD_METHOD_BTRACE
)
97 return recpy_bt_goto (self
, value
);
99 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
102 /* Implementation of record.replay_position [instruction] */
105 recpy_replay_position (PyObject
*self
, void *closure
)
107 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
109 if (obj
->method
== RECORD_METHOD_BTRACE
)
110 return recpy_bt_replay_position (self
, closure
);
112 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
115 /* Implementation of record.instruction_history [list]. */
118 recpy_instruction_history (PyObject
*self
, void* closure
)
120 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
122 if (obj
->method
== RECORD_METHOD_BTRACE
)
123 return recpy_bt_instruction_history (self
, closure
);
125 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
128 /* Implementation of record.function_call_history [list]. */
131 recpy_function_call_history (PyObject
*self
, void* closure
)
133 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
135 if (obj
->method
== RECORD_METHOD_BTRACE
)
136 return recpy_bt_function_call_history (self
, closure
);
138 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
141 /* Implementation of record.begin [instruction]. */
144 recpy_begin (PyObject
*self
, void* closure
)
146 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
148 if (obj
->method
== RECORD_METHOD_BTRACE
)
149 return recpy_bt_begin (self
, closure
);
151 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
154 /* Implementation of record.end [instruction]. */
157 recpy_end (PyObject
*self
, void* closure
)
159 const recpy_record_object
* const obj
= (recpy_record_object
*) self
;
161 if (obj
->method
== RECORD_METHOD_BTRACE
)
162 return recpy_bt_end (self
, closure
);
164 return PyErr_Format (PyExc_NotImplementedError
, _("Not implemented."));
167 /* Record method list. */
169 static PyMethodDef recpy_record_methods
[] = {
170 { "goto", recpy_goto
, METH_VARARGS
,
171 "goto (instruction|function_call) -> None.\n\
172 Rewind to given location."},
176 /* Record member list. */
178 static gdb_PyGetSetDef recpy_record_getset
[] = {
179 { "ptid", recpy_ptid
, NULL
, "Current thread.", NULL
},
180 { "method", recpy_method
, NULL
, "Current recording method.", NULL
},
181 { "format", recpy_format
, NULL
, "Current recording format.", NULL
},
182 { "replay_position", recpy_replay_position
, NULL
, "Current replay position.",
184 { "instruction_history", recpy_instruction_history
, NULL
,
185 "List of instructions in current recording.", NULL
},
186 { "function_call_history", recpy_function_call_history
, NULL
,
187 "List of function calls in current recording.", NULL
},
188 { "begin", recpy_begin
, NULL
,
189 "First instruction in current recording.", NULL
},
190 { "end", recpy_end
, NULL
,
191 "One past the last instruction in current recording. This is typically \
192 the current instruction and is used for e.g. record.goto (record.end).", NULL
},
196 /* Sets up the record API in the gdb module. */
199 gdbpy_initialize_record (void)
201 recpy_record_type
.tp_new
= PyType_GenericNew
;
202 recpy_record_type
.tp_flags
= Py_TPFLAGS_DEFAULT
;
203 recpy_record_type
.tp_basicsize
= sizeof (recpy_record_object
);
204 recpy_record_type
.tp_name
= "gdb.Record";
205 recpy_record_type
.tp_doc
= "GDB record object";
206 recpy_record_type
.tp_methods
= recpy_record_methods
;
207 recpy_record_type
.tp_getset
= recpy_record_getset
;
209 return PyType_Ready (&recpy_record_type
);
212 /* Implementation of gdb.start_recording (method) -> gdb.Record. */
215 gdbpy_start_recording (PyObject
*self
, PyObject
*args
)
217 const char *method
= NULL
;
218 const char *format
= NULL
;
219 PyObject
*ret
= NULL
;
221 if (!PyArg_ParseTuple (args
, "|ss", &method
, &format
))
226 record_start (method
, format
, 0);
227 ret
= gdbpy_current_recording (self
, args
);
229 CATCH (except
, RETURN_MASK_ALL
)
231 gdbpy_convert_exception (except
);
238 /* Implementation of gdb.current_recording (self) -> gdb.Record. */
241 gdbpy_current_recording (PyObject
*self
, PyObject
*args
)
243 recpy_record_object
*ret
= NULL
;
245 if (find_record_target () == NULL
)
248 ret
= PyObject_New (recpy_record_object
, &recpy_record_type
);
249 ret
->ptid
= inferior_ptid
;
250 ret
->method
= target_record_method (inferior_ptid
);
252 return (PyObject
*) ret
;
255 /* Implementation of gdb.stop_recording (self) -> None. */
258 gdbpy_stop_recording (PyObject
*self
, PyObject
*args
)
260 PyObject
*ret
= NULL
;
268 CATCH (except
, RETURN_MASK_ALL
)
270 gdbpy_convert_exception (except
);