python: Create Python bindings for record history.
[deliverable/binutils-gdb.git] / gdb / python / py-record.c
CommitLineData
4726b2d8
TW
1/* Python interface to record targets.
2
3 Copyright 2016-2017 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20#include "defs.h"
21#include "inferior.h"
22#include "record.h"
23#include "python-internal.h"
24#include "target.h"
25
26/* Python Record object. */
27
28typedef struct
29{
30 PyObject_HEAD
31
32 /* The ptid this object refers to. */
33 ptid_t ptid;
34
35 /* The current recording method. */
36 enum record_method method;
37} recpy_record_object;
38
39/* Python Record type. */
40
41static PyTypeObject recpy_record_type = {
42 PyVarObject_HEAD_INIT (NULL, 0)
43};
44
45/* Implementation of record.ptid. */
46
47static PyObject *
48recpy_ptid (PyObject *self, void* closure)
49{
50 const recpy_record_object * const obj = (recpy_record_object *) self;
51
52 return gdbpy_create_ptid_object (obj->ptid);
53}
54
55/* Implementation of record.method. */
56
57static PyObject *
58recpy_method (PyObject *self, void* closure)
59{
60 return PyErr_Format (PyExc_NotImplementedError, _("Not implemented."));
61}
62
63/* Implementation of record.format. */
64
65static PyObject *
66recpy_format (PyObject *self, void* closure)
67{
68 return PyErr_Format (PyExc_NotImplementedError, _("Not implemented."));
69}
70
71/* Implementation of record.goto (instruction) -> None. */
72
73static PyObject *
74recpy_goto (PyObject *self, PyObject *value)
75{
76 return PyErr_Format (PyExc_NotImplementedError, _("Not implemented."));
77}
78
79/* Implementation of record.replay_position [instruction] */
80
81static PyObject *
82recpy_replay_position (PyObject *self, void *closure)
83{
84 return PyErr_Format (PyExc_NotImplementedError, _("Not implemented."));
85}
86
87/* Implementation of record.instruction_history [list]. */
88
89static PyObject *
90recpy_instruction_history (PyObject *self, void* closure)
91{
92 return PyErr_Format (PyExc_NotImplementedError, _("Not implemented."));
93}
94
95/* Implementation of record.function_call_history [list]. */
96
97static PyObject *
98recpy_function_call_history (PyObject *self, void* closure)
99{
100 return PyErr_Format (PyExc_NotImplementedError, _("Not implemented."));
101}
102
103/* Implementation of record.begin [instruction]. */
104
105static PyObject *
106recpy_begin (PyObject *self, void* closure)
107{
108 return PyErr_Format (PyExc_NotImplementedError, _("Not implemented."));
109}
110
111/* Implementation of record.end [instruction]. */
112
113static PyObject *
114recpy_end (PyObject *self, void* closure)
115{
116 return PyErr_Format (PyExc_NotImplementedError, _("Not implemented."));
117}
118
119/* Record method list. */
120
121static PyMethodDef recpy_record_methods[] = {
122 { "goto", recpy_goto, METH_VARARGS,
123 "goto (instruction|function_call) -> None.\n\
124Rewind to given location."},
125 { NULL }
126};
127
128/* Record member list. */
129
130static PyGetSetDef recpy_record_getset[] = {
131 { "ptid", recpy_ptid, NULL, "Current thread.", NULL },
132 { "method", recpy_method, NULL, "Current recording method.", NULL },
133 { "format", recpy_format, NULL, "Current recording format.", NULL },
134 { "replay_position", recpy_replay_position, NULL, "Current replay position.",
135 NULL },
136 { "instruction_history", recpy_instruction_history, NULL,
137 "List of instructions in current recording.", NULL },
138 { "function_call_history", recpy_function_call_history, NULL,
139 "List of function calls in current recording.", NULL },
140 { "begin", recpy_begin, NULL,
141 "First instruction in current recording.", NULL },
142 { "end", recpy_end, NULL,
143 "One past the last instruction in current recording. This is typically \
144the current instruction and is used for e.g. record.goto (record.end).", NULL },
145 { NULL }
146};
147
148/* Sets up the record API in the gdb module. */
149
150int
151gdbpy_initialize_record (void)
152{
153 recpy_record_type.tp_new = PyType_GenericNew;
154 recpy_record_type.tp_flags = Py_TPFLAGS_DEFAULT;
155 recpy_record_type.tp_basicsize = sizeof (recpy_record_object);
156 recpy_record_type.tp_name = "gdb.Record";
157 recpy_record_type.tp_doc = "GDB record object";
158 recpy_record_type.tp_methods = recpy_record_methods;
159 recpy_record_type.tp_getset = recpy_record_getset;
160
161 return PyType_Ready (&recpy_record_type);
162}
163
164/* Implementation of gdb.start_recording (method) -> gdb.Record. */
165
166PyObject *
167gdbpy_start_recording (PyObject *self, PyObject *args)
168{
169 const char *method = NULL;
170 const char *format = NULL;
171 PyObject *ret = NULL;
172
173 if (!PyArg_ParseTuple (args, "|ss", &method, &format))
174 return NULL;
175
176 TRY
177 {
178 record_start (method, format, 0);
179 ret = gdbpy_current_recording (self, args);
180 }
181 CATCH (except, RETURN_MASK_ALL)
182 {
183 gdbpy_convert_exception (except);
184 }
185 END_CATCH
186
187 return ret;
188}
189
190/* Implementation of gdb.current_recording (self) -> gdb.Record. */
191
192PyObject *
193gdbpy_current_recording (PyObject *self, PyObject *args)
194{
195 recpy_record_object *ret = NULL;
196
197 if (find_record_target () == NULL)
198 Py_RETURN_NONE;
199
200 ret = PyObject_New (recpy_record_object, &recpy_record_type);
201 ret->ptid = inferior_ptid;
202 ret->method = target_record_method (inferior_ptid);
203
204 return (PyObject *) ret;
205}
206
207/* Implementation of gdb.stop_recording (self) -> None. */
208
209PyObject *
210gdbpy_stop_recording (PyObject *self, PyObject *args)
211{
212 PyObject *ret = NULL;
213
214 TRY
215 {
216 record_stop (0);
217 ret = Py_None;
218 Py_INCREF (Py_None);
219 }
220 CATCH (except, RETURN_MASK_ALL)
221 {
222 gdbpy_convert_exception (except);
223 }
224 END_CATCH
225
226 return ret;
227}
This page took 0.03192 seconds and 4 git commands to generate.