Commit | Line | Data |
---|---|---|
d57a3c85 TJB |
1 | /* Gdb/Python header for private use by Python module. |
2 | ||
7b6bb8da | 3 | Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
d57a3c85 TJB |
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 | ||
8a1ea21f DE |
23 | #include <stdio.h> |
24 | ||
d57a3c85 TJB |
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. | |
aac63f0f JB |
33 | To work around this, undef _POSIX_C_SOURCE before we include Python.h. |
34 | ||
35 | Same problem with _XOPEN_SOURCE. */ | |
d57a3c85 | 36 | #undef _POSIX_C_SOURCE |
aac63f0f | 37 | #undef _XOPEN_SOURCE |
d57a3c85 | 38 | |
aed1781d JB |
39 | /* On sparc-solaris, /usr/include/sys/feature_tests.h defines |
40 | _FILE_OFFSET_BITS, which pyconfig.h also defines. Same work | |
284a3db3 | 41 | around technique as above. */ |
aed1781d JB |
42 | #undef _FILE_OFFSET_BITS |
43 | ||
ac534cba JB |
44 | /* Include the Python header files using angle brackets rather than |
45 | double quotes. On case-insensitive filesystems, this prevents us | |
46 | from including our python/python.h header file. */ | |
47 | #include <Python.h> | |
48 | #include <frameobject.h> | |
d57a3c85 | 49 | #if HAVE_LIBPYTHON2_4 |
5171e6b3 TT |
50 | /* Py_ssize_t is not defined until 2.5. |
51 | Logical type for Py_ssize_t is Py_intptr_t, but that fails in 64-bit | |
52 | compilation due to several apparent mistakes in python2.4 API, so we | |
53 | use 'int' instead. */ | |
54 | typedef int Py_ssize_t; | |
d57a3c85 TJB |
55 | #endif |
56 | ||
ca30a762 TT |
57 | /* If Python.h does not define WITH_THREAD, then the various |
58 | GIL-related functions will not be defined. However, | |
59 | PyGILState_STATE will be. */ | |
60 | #ifndef WITH_THREAD | |
61 | #define PyGILState_Ensure() ((PyGILState_STATE) 0) | |
548a926a | 62 | #define PyGILState_Release(ARG) ((void)(ARG)) |
aed1781d | 63 | #define PyEval_InitThreads() |
548a926a | 64 | #define PyThreadState_Swap(ARG) ((void)(ARG)) |
aed1781d | 65 | #define PyEval_ReleaseLock() |
ca30a762 TT |
66 | #endif |
67 | ||
74aedc46 TT |
68 | /* Python supplies HAVE_LONG_LONG and some `long long' support when it |
69 | is available. These defines let us handle the differences more | |
70 | cleanly. */ | |
71 | #ifdef HAVE_LONG_LONG | |
72 | ||
73 | #define GDB_PY_LL_ARG "L" | |
74 | #define GDB_PY_LLU_ARG "K" | |
75 | typedef PY_LONG_LONG gdb_py_longest; | |
76 | typedef unsigned PY_LONG_LONG gdb_py_ulongest; | |
77 | #define gdb_py_long_from_longest PyLong_FromLongLong | |
78 | #define gdb_py_long_from_ulongest PyLong_FromUnsignedLongLong | |
79 | #define gdb_py_long_as_ulongest PyLong_AsUnsignedLongLong | |
80 | ||
81 | #else /* HAVE_LONG_LONG */ | |
82 | ||
83 | #define GDB_PY_LL_ARG "L" | |
84 | #define GDB_PY_LLU_ARG "K" | |
85 | typedef long gdb_py_longest; | |
86 | typedef unsigned long gdb_py_ulongest; | |
87 | #define gdb_py_long_from_longest PyLong_FromLong | |
88 | #define gdb_py_long_from_ulongest PyLong_FromUnsignedLong | |
89 | #define gdb_py_long_as_ulongest PyLong_AsUnsignedLong | |
90 | ||
91 | #endif /* HAVE_LONG_LONG */ | |
92 | ||
93 | ||
9cb74f47 PM |
94 | /* In order to be able to parse symtab_and_line_to_sal_object function |
95 | a real symtab_and_line structure is needed. */ | |
96 | #include "symtab.h" | |
97 | ||
d7b32ed3 PM |
98 | /* Also needed to parse enum var_types. */ |
99 | #include "command.h" | |
505500db | 100 | #include "breakpoint.h" |
d7b32ed3 | 101 | |
621c8364 TT |
102 | #include "exceptions.h" |
103 | ||
f3e9a817 | 104 | struct block; |
a08702d6 | 105 | struct value; |
d452c4bc | 106 | struct language_defn; |
fa33c3cd | 107 | struct program_space; |
505500db | 108 | struct bpstats; |
d57a3c85 TJB |
109 | |
110 | extern PyObject *gdb_module; | |
a08702d6 | 111 | extern PyTypeObject value_object_type; |
f3e9a817 PM |
112 | extern PyTypeObject block_object_type; |
113 | extern PyTypeObject symbol_object_type; | |
505500db SW |
114 | extern PyTypeObject event_object_type; |
115 | extern PyTypeObject events_object_type; | |
116 | extern PyTypeObject stop_event_object_type; | |
117 | ||
118 | /* Defined in py-breakpoint.c */ | |
119 | typedef struct breakpoint_object breakpoint_object; | |
a08702d6 | 120 | |
595939de PM |
121 | typedef struct |
122 | { | |
123 | PyObject_HEAD | |
124 | ||
125 | /* The thread we represent. */ | |
126 | struct thread_info *thread; | |
127 | ||
128 | /* The Inferior object to which this thread belongs. */ | |
129 | PyObject *inf_obj; | |
130 | } thread_object; | |
131 | ||
8a1ea21f DE |
132 | extern struct cmd_list_element *set_python_list; |
133 | extern struct cmd_list_element *show_python_list; | |
134 | ||
08c637de | 135 | PyObject *gdbpy_history (PyObject *self, PyObject *args); |
adc36818 | 136 | PyObject *gdbpy_breakpoints (PyObject *, PyObject *); |
f8f6f20b | 137 | PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *); |
f3e9a817 | 138 | PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw); |
d8e22779 | 139 | PyObject *gdbpy_newest_frame (PyObject *self, PyObject *args); |
f8f6f20b | 140 | PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args); |
f3e9a817 | 141 | PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args); |
2c74e833 | 142 | PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw); |
be759fcf | 143 | PyObject *gdbpy_create_lazy_string_object (CORE_ADDR address, long length, |
9a2b4c1b MS |
144 | const char *encoding, |
145 | struct type *type); | |
595939de PM |
146 | PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2); |
147 | PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args); | |
07ca107c | 148 | PyObject *gdbpy_string_to_argv (PyObject *self, PyObject *args); |
d7b32ed3 PM |
149 | PyObject *gdbpy_parameter (PyObject *self, PyObject *args); |
150 | PyObject *gdbpy_parameter_value (enum var_types type, void *var); | |
151 | char *gdbpy_parse_command_name (char *text, | |
152 | struct cmd_list_element ***base_list, | |
153 | struct cmd_list_element **start_list); | |
a08702d6 | 154 | |
f3e9a817 PM |
155 | PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal); |
156 | PyObject *symtab_to_symtab_object (struct symtab *symtab); | |
157 | PyObject *symbol_to_symbol_object (struct symbol *sym); | |
158 | PyObject *block_to_block_object (struct block *block, struct objfile *objfile); | |
a08702d6 | 159 | PyObject *value_to_value_object (struct value *v); |
2c74e833 | 160 | PyObject *type_to_type_object (struct type *); |
595939de | 161 | PyObject *frame_info_to_frame_object (struct frame_info *frame); |
89c73ade | 162 | |
fa33c3cd DE |
163 | PyObject *pspace_to_pspace_object (struct program_space *); |
164 | PyObject *pspy_get_printers (PyObject *, void *); | |
165 | ||
166 | PyObject *objfile_to_objfile_object (struct objfile *); | |
89c73ade | 167 | PyObject *objfpy_get_printers (PyObject *, void *); |
a08702d6 | 168 | |
595939de PM |
169 | thread_object *create_thread_object (struct thread_info *tp); |
170 | thread_object *find_thread_object (ptid_t ptid); | |
171 | PyObject *find_inferior_object (int pid); | |
505500db | 172 | PyObject *inferior_to_inferior_object (struct inferior *inferior); |
595939de | 173 | |
f3e9a817 PM |
174 | struct block *block_object_to_block (PyObject *obj); |
175 | struct symbol *symbol_object_to_symbol (PyObject *obj); | |
a6bac58e | 176 | struct value *value_object_to_value (PyObject *self); |
a08702d6 | 177 | struct value *convert_value_from_python (PyObject *obj); |
2c74e833 | 178 | struct type *type_object_to_type (PyObject *obj); |
f3e9a817 PM |
179 | struct symtab *symtab_object_to_symtab (PyObject *obj); |
180 | struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj); | |
a08702d6 | 181 | |
8a1ea21f | 182 | void gdbpy_initialize_auto_load (void); |
a08702d6 | 183 | void gdbpy_initialize_values (void); |
f8f6f20b | 184 | void gdbpy_initialize_frames (void); |
f3e9a817 | 185 | void gdbpy_initialize_symtabs (void); |
d8906c6f | 186 | void gdbpy_initialize_commands (void); |
f3e9a817 PM |
187 | void gdbpy_initialize_symbols (void); |
188 | void gdbpy_initialize_symtabs (void); | |
189 | void gdbpy_initialize_blocks (void); | |
2c74e833 | 190 | void gdbpy_initialize_types (void); |
bc3b79fd | 191 | void gdbpy_initialize_functions (void); |
fa33c3cd | 192 | void gdbpy_initialize_pspace (void); |
89c73ade | 193 | void gdbpy_initialize_objfile (void); |
adc36818 | 194 | void gdbpy_initialize_breakpoints (void); |
be759fcf | 195 | void gdbpy_initialize_lazy_string (void); |
d7b32ed3 | 196 | void gdbpy_initialize_parameters (void); |
595939de PM |
197 | void gdbpy_initialize_thread (void); |
198 | void gdbpy_initialize_inferior (void); | |
505500db SW |
199 | void gdbpy_initialize_eventregistry (void); |
200 | void gdbpy_initialize_event (void); | |
201 | void gdbpy_initialize_py_events (void); | |
202 | void gdbpy_initialize_stop_event (void); | |
203 | void gdbpy_initialize_signal_event (void); | |
204 | void gdbpy_initialize_breakpoint_event (void); | |
205 | void gdbpy_initialize_continue_event (void); | |
206 | void gdbpy_initialize_exited_event (void); | |
207 | void gdbpy_initialize_thread_event (void); | |
d57a3c85 TJB |
208 | |
209 | struct cleanup *make_cleanup_py_decref (PyObject *py); | |
d452c4bc UW |
210 | |
211 | struct cleanup *ensure_python_env (struct gdbarch *gdbarch, | |
212 | const struct language_defn *language); | |
213 | ||
214 | extern struct gdbarch *python_gdbarch; | |
215 | extern const struct language_defn *python_language; | |
d57a3c85 TJB |
216 | |
217 | /* Use this after a TRY_EXCEPT to throw the appropriate Python | |
218 | exception. */ | |
219 | #define GDB_PY_HANDLE_EXCEPTION(Exception) \ | |
220 | do { \ | |
221 | if (Exception.reason < 0) \ | |
621c8364 | 222 | return gdbpy_convert_exception (Exception); \ |
d57a3c85 TJB |
223 | } while (0) |
224 | ||
adc36818 PM |
225 | /* Use this after a TRY_EXCEPT to throw the appropriate Python |
226 | exception. This macro is for use inside setter functions. */ | |
227 | #define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \ | |
228 | do { \ | |
229 | if (Exception.reason < 0) \ | |
230 | { \ | |
621c8364 | 231 | gdbpy_convert_exception (Exception); \ |
adc36818 PM |
232 | return -1; \ |
233 | } \ | |
234 | } while (0) | |
d57a3c85 TJB |
235 | |
236 | void gdbpy_print_stack (void); | |
237 | ||
8a1ea21f DE |
238 | void source_python_script_for_objfile (struct objfile *objfile, |
239 | FILE *stream, const char *file); | |
240 | ||
d57a3c85 TJB |
241 | PyObject *python_string_to_unicode (PyObject *obj); |
242 | char *unicode_to_target_string (PyObject *unicode_str); | |
243 | char *python_string_to_target_string (PyObject *obj); | |
fbb8f299 | 244 | PyObject *python_string_to_target_python_string (PyObject *obj); |
08c637de | 245 | char *python_string_to_host_string (PyObject *obj); |
b6cb8e7d | 246 | PyObject *target_string_to_unicode (const gdb_byte *str, int length); |
08c637de | 247 | int gdbpy_is_string (PyObject *obj); |
07ca107c DE |
248 | char *gdbpy_obj_to_string (PyObject *obj); |
249 | char *gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue); | |
250 | ||
be759fcf | 251 | int gdbpy_is_lazy_string (PyObject *result); |
09ca9e2e TT |
252 | void gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr, |
253 | struct type **str_type, | |
254 | long *length, char **encoding); | |
d57a3c85 | 255 | |
595939de PM |
256 | int gdbpy_is_value_object (PyObject *obj); |
257 | ||
b6313243 TT |
258 | /* Note that these are declared here, and not in python.h with the |
259 | other pretty-printer functions, because they refer to PyObject. */ | |
fbb8f299 | 260 | PyObject *apply_varobj_pretty_printer (PyObject *print_obj, |
621c8364 TT |
261 | struct value **replacement, |
262 | struct ui_file *stream); | |
b6313243 TT |
263 | PyObject *gdbpy_get_varobj_pretty_printer (struct value *value); |
264 | char *gdbpy_get_display_hint (PyObject *printer); | |
265 | PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args); | |
266 | ||
d8906c6f | 267 | extern PyObject *gdbpy_doc_cst; |
a6bac58e TT |
268 | extern PyObject *gdbpy_children_cst; |
269 | extern PyObject *gdbpy_to_string_cst; | |
270 | extern PyObject *gdbpy_display_hint_cst; | |
967cf477 | 271 | extern PyObject *gdbpy_enabled_cst; |
d8906c6f | 272 | |
621c8364 TT |
273 | /* Exception types. */ |
274 | extern PyObject *gdbpy_gdb_error; | |
275 | extern PyObject *gdbpy_gdb_memory_error; | |
07ca107c DE |
276 | extern PyObject *gdbpy_gdberror_exc; |
277 | ||
621c8364 TT |
278 | extern PyObject *gdbpy_convert_exception (struct gdb_exception); |
279 | ||
595939de PM |
280 | int get_addr_from_python (PyObject *obj, CORE_ADDR *addr); |
281 | ||
74aedc46 TT |
282 | PyObject *gdb_py_object_from_longest (LONGEST l); |
283 | PyObject *gdb_py_object_from_ulongest (ULONGEST l); | |
284 | int gdb_py_int_as_long (PyObject *, long *); | |
285 | ||
d57a3c85 | 286 | #endif /* GDB_PYTHON_INTERNAL_H */ |