]> Git Repo - binutils.git/blob - gdb/python/python-internal.h
1d6247d067114be750e2e361bd7b396ff4d843e7
[binutils.git] / gdb / python / python-internal.h
1 /* Gdb/Python header for private use by Python module.
2
3    Copyright (C) 2008-2012 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 #ifndef GDB_PYTHON_INTERNAL_H
21 #define GDB_PYTHON_INTERNAL_H
22
23 #include <stdio.h>
24
25 /* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t
26    needed by pyport.h.  */
27 #include <stdint.h>
28
29 /* /usr/include/features.h on linux systems will define _POSIX_C_SOURCE
30    if it sees _GNU_SOURCE (which config.h will define).
31    pyconfig.h defines _POSIX_C_SOURCE to a different value than
32    /usr/include/features.h does causing compilation to fail.
33    To work around this, undef _POSIX_C_SOURCE before we include Python.h.
34
35    Same problem with _XOPEN_SOURCE.  */
36 #undef _POSIX_C_SOURCE
37 #undef _XOPEN_SOURCE
38
39 /* On sparc-solaris, /usr/include/sys/feature_tests.h defines
40    _FILE_OFFSET_BITS, which pyconfig.h also defines.  Same work
41    around technique as above.  */
42 #undef _FILE_OFFSET_BITS
43
44 /* Request clean size types from Python.  */
45 #define PY_SSIZE_T_CLEAN
46
47 /* Include the Python header files using angle brackets rather than
48    double quotes.  On case-insensitive filesystems, this prevents us
49    from including our python/python.h header file.  */
50 #include <Python.h>
51 #include <frameobject.h>
52 #if HAVE_LIBPYTHON2_4
53 /* Py_ssize_t is not defined until 2.5.
54    Logical type for Py_ssize_t is Py_intptr_t, but that fails in 64-bit
55    compilation due to several apparent mistakes in python2.4 API, so we
56    use 'int' instead.  */
57 typedef int Py_ssize_t;
58 #endif
59
60 /* If Python.h does not define WITH_THREAD, then the various
61    GIL-related functions will not be defined.  However,
62    PyGILState_STATE will be.  */
63 #ifndef WITH_THREAD
64 #define PyGILState_Ensure() ((PyGILState_STATE) 0)
65 #define PyGILState_Release(ARG) ((void)(ARG))
66 #define PyEval_InitThreads()
67 #define PyThreadState_Swap(ARG) ((void)(ARG))
68 #define PyEval_ReleaseLock()
69 #endif
70
71 /* Python supplies HAVE_LONG_LONG and some `long long' support when it
72    is available.  These defines let us handle the differences more
73    cleanly.  */
74 #ifdef HAVE_LONG_LONG
75
76 #define GDB_PY_LL_ARG "L"
77 #define GDB_PY_LLU_ARG "K"
78 typedef PY_LONG_LONG gdb_py_longest;
79 typedef unsigned PY_LONG_LONG gdb_py_ulongest;
80 #define gdb_py_long_from_longest PyLong_FromLongLong
81 #define gdb_py_long_from_ulongest PyLong_FromUnsignedLongLong
82 #define gdb_py_long_as_ulongest PyLong_AsUnsignedLongLong
83
84 #else /* HAVE_LONG_LONG */
85
86 #define GDB_PY_LL_ARG "L"
87 #define GDB_PY_LLU_ARG "K"
88 typedef long gdb_py_longest;
89 typedef unsigned long gdb_py_ulongest;
90 #define gdb_py_long_from_longest PyLong_FromLong
91 #define gdb_py_long_from_ulongest PyLong_FromUnsignedLong
92 #define gdb_py_long_as_ulongest PyLong_AsUnsignedLong
93
94 #endif /* HAVE_LONG_LONG */
95
96
97 /* In order to be able to parse symtab_and_line_to_sal_object function 
98    a real symtab_and_line structure is needed.  */
99 #include "symtab.h"
100
101 /* Also needed to parse enum var_types. */
102 #include "command.h"
103 #include "breakpoint.h"
104
105 #include "exceptions.h"
106
107 enum gdbpy_iter_kind { iter_keys, iter_values, iter_items };
108
109 struct block;
110 struct value;
111 struct language_defn;
112 struct program_space;
113 struct bpstats;
114 struct inferior;
115
116 extern PyObject *gdb_module;
117 extern PyTypeObject value_object_type;
118 extern PyTypeObject block_object_type;
119 extern PyTypeObject symbol_object_type;
120 extern PyTypeObject event_object_type;
121 extern PyTypeObject events_object_type;
122 extern PyTypeObject stop_event_object_type;
123 extern PyTypeObject breakpoint_object_type;
124 extern PyTypeObject frame_object_type;
125
126 typedef struct breakpoint_object
127 {
128   PyObject_HEAD
129
130   /* The breakpoint number according to gdb.  */
131   int number;
132
133   /* The gdb breakpoint object, or NULL if the breakpoint has been
134      deleted.  */
135   struct breakpoint *bp;
136
137   /* 1 is this is a FinishBreakpoint object, 0 otherwise.  */
138   int is_finish_bp;
139 } breakpoint_object;
140
141 /* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
142    exception if it is invalid.  */
143 #define BPPY_REQUIRE_VALID(Breakpoint)                                  \
144     do {                                                                \
145       if ((Breakpoint)->bp == NULL)                                     \
146         return PyErr_Format (PyExc_RuntimeError,                        \
147                              _("Breakpoint %d is invalid."),            \
148                              (Breakpoint)->number);                     \
149     } while (0)
150
151 /* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
152    exception if it is invalid.  This macro is for use in setter functions.  */
153 #define BPPY_SET_REQUIRE_VALID(Breakpoint)                              \
154     do {                                                                \
155       if ((Breakpoint)->bp == NULL)                                     \
156         {                                                               \
157           PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
158                         (Breakpoint)->number);                          \
159           return -1;                                                    \
160         }                                                               \
161     } while (0)
162
163
164 /* Variables used to pass information between the Breakpoint
165    constructor and the breakpoint-created hook function.  */
166 extern breakpoint_object *bppy_pending_object;
167
168
169 typedef struct
170 {
171   PyObject_HEAD
172
173   /* The thread we represent.  */
174   struct thread_info *thread;
175
176   /* The Inferior object to which this thread belongs.  */
177   PyObject *inf_obj;
178 } thread_object;
179
180 extern struct cmd_list_element *set_python_list;
181 extern struct cmd_list_element *show_python_list;
182
183 PyObject *gdbpy_history (PyObject *self, PyObject *args);
184 PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
185 PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
186 PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw);
187 PyObject *gdbpy_lookup_global_symbol (PyObject *self, PyObject *args,
188                                       PyObject *kw);
189 PyObject *gdbpy_newest_frame (PyObject *self, PyObject *args);
190 PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args);
191 PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
192 PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw);
193 PyObject *gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
194                                            const char *encoding,
195                                            struct type *type);
196 PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2);
197 PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args);
198 PyObject *gdbpy_selected_inferior (PyObject *self, PyObject *args);
199 PyObject *gdbpy_string_to_argv (PyObject *self, PyObject *args);
200 PyObject *gdbpy_parameter (PyObject *self, PyObject *args);
201 PyObject *gdbpy_parameter_value (enum var_types type, void *var);
202 char *gdbpy_parse_command_name (const char *name,
203                                 struct cmd_list_element ***base_list,
204                                 struct cmd_list_element **start_list);
205
206 PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
207 PyObject *symtab_to_symtab_object (struct symtab *symtab);
208 PyObject *symbol_to_symbol_object (struct symbol *sym);
209 PyObject *block_to_block_object (const struct block *block,
210                                  struct objfile *objfile);
211 PyObject *value_to_value_object (struct value *v);
212 PyObject *type_to_type_object (struct type *);
213 PyObject *frame_info_to_frame_object (struct frame_info *frame);
214
215 PyObject *pspace_to_pspace_object (struct program_space *);
216 PyObject *pspy_get_printers (PyObject *, void *);
217
218 PyObject *objfile_to_objfile_object (struct objfile *);
219 PyObject *objfpy_get_printers (PyObject *, void *);
220
221 thread_object *create_thread_object (struct thread_info *tp);
222 thread_object *find_thread_object (ptid_t ptid);
223 PyObject *find_inferior_object (int pid);
224 PyObject *inferior_to_inferior_object (struct inferior *inferior);
225
226 const struct block *block_object_to_block (PyObject *obj);
227 struct symbol *symbol_object_to_symbol (PyObject *obj);
228 struct value *value_object_to_value (PyObject *self);
229 struct value *convert_value_from_python (PyObject *obj);
230 struct type *type_object_to_type (PyObject *obj);
231 struct symtab *symtab_object_to_symtab (PyObject *obj);
232 struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj);
233 struct frame_info *frame_object_to_frame_info (PyObject *frame_obj);
234
235 void gdbpy_initialize_auto_load (void);
236 void gdbpy_initialize_values (void);
237 void gdbpy_initialize_frames (void);
238 void gdbpy_initialize_symtabs (void);
239 void gdbpy_initialize_commands (void);
240 void gdbpy_initialize_symbols (void);
241 void gdbpy_initialize_symtabs (void);
242 void gdbpy_initialize_blocks (void);
243 void gdbpy_initialize_types (void);
244 void gdbpy_initialize_functions (void);
245 void gdbpy_initialize_pspace (void);
246 void gdbpy_initialize_objfile (void);
247 void gdbpy_initialize_breakpoints (void);
248 void gdbpy_initialize_finishbreakpoints (void);
249 void gdbpy_initialize_lazy_string (void);
250 void gdbpy_initialize_parameters (void);
251 void gdbpy_initialize_thread (void);
252 void gdbpy_initialize_inferior (void);
253 void gdbpy_initialize_eventregistry (void);
254 void gdbpy_initialize_event (void);
255 void gdbpy_initialize_py_events (void);
256 void gdbpy_initialize_stop_event (void);
257 void gdbpy_initialize_signal_event (void);
258 void gdbpy_initialize_breakpoint_event (void);
259 void gdbpy_initialize_continue_event (void);
260 void gdbpy_initialize_exited_event (void);
261 void gdbpy_initialize_thread_event (void);
262 void gdbpy_initialize_new_objfile_event (void);
263
264 struct cleanup *make_cleanup_py_decref (PyObject *py);
265
266 struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
267                                    const struct language_defn *language);
268
269 extern struct gdbarch *python_gdbarch;
270 extern const struct language_defn *python_language;
271
272 /* Use this after a TRY_EXCEPT to throw the appropriate Python
273    exception.  */
274 #define GDB_PY_HANDLE_EXCEPTION(Exception)                              \
275     do {                                                                \
276       if (Exception.reason < 0)                                         \
277         return gdbpy_convert_exception (Exception);                     \
278     } while (0)
279
280 /* Use this after a TRY_EXCEPT to throw the appropriate Python
281    exception.  This macro is for use inside setter functions.  */
282 #define GDB_PY_SET_HANDLE_EXCEPTION(Exception)                          \
283     do {                                                                \
284       if (Exception.reason < 0)                                         \
285         {                                                               \
286           gdbpy_convert_exception (Exception);                          \
287           return -1;                                                    \
288         }                                                               \
289     } while (0)
290
291 void gdbpy_print_stack (void);
292
293 void source_python_script_for_objfile (struct objfile *objfile, FILE *file,
294                                        const char *filename);
295
296 PyObject *python_string_to_unicode (PyObject *obj);
297 char *unicode_to_target_string (PyObject *unicode_str);
298 char *python_string_to_target_string (PyObject *obj);
299 PyObject *python_string_to_target_python_string (PyObject *obj);
300 char *python_string_to_host_string (PyObject *obj);
301 PyObject *target_string_to_unicode (const gdb_byte *str, int length);
302 int gdbpy_is_string (PyObject *obj);
303 char *gdbpy_obj_to_string (PyObject *obj);
304 char *gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue);
305
306 int gdbpy_is_lazy_string (PyObject *result);
307 void gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr,
308                                 struct type **str_type, 
309                                 long *length, char **encoding);
310
311 int gdbpy_is_value_object (PyObject *obj);
312
313 /* Note that these are declared here, and not in python.h with the
314    other pretty-printer functions, because they refer to PyObject.  */
315 PyObject *apply_varobj_pretty_printer (PyObject *print_obj,
316                                        struct value **replacement,
317                                        struct ui_file *stream);
318 PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
319 char *gdbpy_get_display_hint (PyObject *printer);
320 PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);
321
322 void bpfinishpy_pre_stop_hook (struct breakpoint_object *bp_obj);
323 void bpfinishpy_post_stop_hook (struct breakpoint_object *bp_obj);
324
325 extern PyObject *gdbpy_doc_cst;
326 extern PyObject *gdbpy_children_cst;
327 extern PyObject *gdbpy_to_string_cst;
328 extern PyObject *gdbpy_display_hint_cst;
329 extern PyObject *gdbpy_enabled_cst;
330 extern PyObject *gdbpy_value_cst;
331
332 /* Exception types.  */
333 extern PyObject *gdbpy_gdb_error;
334 extern PyObject *gdbpy_gdb_memory_error;
335 extern PyObject *gdbpy_gdberror_exc;
336
337 extern PyObject *gdbpy_convert_exception (struct gdb_exception);
338
339 int get_addr_from_python (PyObject *obj, CORE_ADDR *addr);
340
341 PyObject *gdb_py_object_from_longest (LONGEST l);
342 PyObject *gdb_py_object_from_ulongest (ULONGEST l);
343 int gdb_py_int_as_long (PyObject *, long *);
344
345 #endif /* GDB_PYTHON_INTERNAL_H */
This page took 0.03482 seconds and 2 git commands to generate.