1 /* Gdb/Python header for private use by Python module.
3 Copyright (C) 2008, 2009, 2010, 2011 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/>. */
20 #ifndef GDB_PYTHON_INTERNAL_H
21 #define GDB_PYTHON_INTERNAL_H
25 /* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t
26 needed by pyport.h. */
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.
35 Same problem with _XOPEN_SOURCE. */
36 #undef _POSIX_C_SOURCE
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
44 /* Request clean size types from Python. */
45 #define PY_SSIZE_T_CLEAN
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. */
51 #include <frameobject.h>
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
57 typedef int Py_ssize_t
;
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. */
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()
71 /* Python supplies HAVE_LONG_LONG and some `long long' support when it
72 is available. These defines let us handle the differences more
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
84 #else /* HAVE_LONG_LONG */
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
94 #endif /* HAVE_LONG_LONG */
97 /* In order to be able to parse symtab_and_line_to_sal_object function
98 a real symtab_and_line structure is needed. */
101 /* Also needed to parse enum var_types. */
103 #include "breakpoint.h"
105 #include "exceptions.h"
109 struct language_defn
;
110 struct program_space
;
114 extern PyObject
*gdb_module
;
115 extern PyTypeObject value_object_type
;
116 extern PyTypeObject block_object_type
;
117 extern PyTypeObject symbol_object_type
;
118 extern PyTypeObject event_object_type
;
119 extern PyTypeObject events_object_type
;
120 extern PyTypeObject stop_event_object_type
;
122 /* Defined in py-breakpoint.c */
123 typedef struct breakpoint_object breakpoint_object
;
129 /* The thread we represent. */
130 struct thread_info
*thread
;
132 /* The Inferior object to which this thread belongs. */
136 extern struct cmd_list_element
*set_python_list
;
137 extern struct cmd_list_element
*show_python_list
;
139 PyObject
*gdbpy_history (PyObject
*self
, PyObject
*args
);
140 PyObject
*gdbpy_breakpoints (PyObject
*, PyObject
*);
141 PyObject
*gdbpy_frame_stop_reason_string (PyObject
*, PyObject
*);
142 PyObject
*gdbpy_lookup_symbol (PyObject
*self
, PyObject
*args
, PyObject
*kw
);
143 PyObject
*gdbpy_lookup_global_symbol (PyObject
*self
, PyObject
*args
,
145 PyObject
*gdbpy_newest_frame (PyObject
*self
, PyObject
*args
);
146 PyObject
*gdbpy_selected_frame (PyObject
*self
, PyObject
*args
);
147 PyObject
*gdbpy_block_for_pc (PyObject
*self
, PyObject
*args
);
148 PyObject
*gdbpy_lookup_type (PyObject
*self
, PyObject
*args
, PyObject
*kw
);
149 PyObject
*gdbpy_create_lazy_string_object (CORE_ADDR address
, long length
,
150 const char *encoding
,
152 PyObject
*gdbpy_inferiors (PyObject
*unused
, PyObject
*unused2
);
153 PyObject
*gdbpy_selected_thread (PyObject
*self
, PyObject
*args
);
154 PyObject
*gdbpy_selected_inferior (PyObject
*self
, PyObject
*args
);
155 PyObject
*gdbpy_string_to_argv (PyObject
*self
, PyObject
*args
);
156 PyObject
*gdbpy_parameter (PyObject
*self
, PyObject
*args
);
157 PyObject
*gdbpy_parameter_value (enum var_types type
, void *var
);
158 char *gdbpy_parse_command_name (const char *name
,
159 struct cmd_list_element
***base_list
,
160 struct cmd_list_element
**start_list
);
162 PyObject
*symtab_and_line_to_sal_object (struct symtab_and_line sal
);
163 PyObject
*symtab_to_symtab_object (struct symtab
*symtab
);
164 PyObject
*symbol_to_symbol_object (struct symbol
*sym
);
165 PyObject
*block_to_block_object (struct block
*block
, struct objfile
*objfile
);
166 PyObject
*value_to_value_object (struct value
*v
);
167 PyObject
*type_to_type_object (struct type
*);
168 PyObject
*frame_info_to_frame_object (struct frame_info
*frame
);
170 PyObject
*pspace_to_pspace_object (struct program_space
*);
171 PyObject
*pspy_get_printers (PyObject
*, void *);
173 PyObject
*objfile_to_objfile_object (struct objfile
*);
174 PyObject
*objfpy_get_printers (PyObject
*, void *);
176 thread_object
*create_thread_object (struct thread_info
*tp
);
177 thread_object
*find_thread_object (ptid_t ptid
);
178 PyObject
*find_inferior_object (int pid
);
179 PyObject
*inferior_to_inferior_object (struct inferior
*inferior
);
181 struct block
*block_object_to_block (PyObject
*obj
);
182 struct symbol
*symbol_object_to_symbol (PyObject
*obj
);
183 struct value
*value_object_to_value (PyObject
*self
);
184 struct value
*convert_value_from_python (PyObject
*obj
);
185 struct type
*type_object_to_type (PyObject
*obj
);
186 struct symtab
*symtab_object_to_symtab (PyObject
*obj
);
187 struct symtab_and_line
*sal_object_to_symtab_and_line (PyObject
*obj
);
189 void gdbpy_initialize_auto_load (void);
190 void gdbpy_initialize_values (void);
191 void gdbpy_initialize_frames (void);
192 void gdbpy_initialize_symtabs (void);
193 void gdbpy_initialize_commands (void);
194 void gdbpy_initialize_symbols (void);
195 void gdbpy_initialize_symtabs (void);
196 void gdbpy_initialize_blocks (void);
197 void gdbpy_initialize_types (void);
198 void gdbpy_initialize_functions (void);
199 void gdbpy_initialize_pspace (void);
200 void gdbpy_initialize_objfile (void);
201 void gdbpy_initialize_breakpoints (void);
202 void gdbpy_initialize_lazy_string (void);
203 void gdbpy_initialize_parameters (void);
204 void gdbpy_initialize_thread (void);
205 void gdbpy_initialize_inferior (void);
206 void gdbpy_initialize_eventregistry (void);
207 void gdbpy_initialize_event (void);
208 void gdbpy_initialize_py_events (void);
209 void gdbpy_initialize_stop_event (void);
210 void gdbpy_initialize_signal_event (void);
211 void gdbpy_initialize_breakpoint_event (void);
212 void gdbpy_initialize_continue_event (void);
213 void gdbpy_initialize_exited_event (void);
214 void gdbpy_initialize_thread_event (void);
216 struct cleanup
*make_cleanup_py_decref (PyObject
*py
);
218 struct cleanup
*ensure_python_env (struct gdbarch
*gdbarch
,
219 const struct language_defn
*language
);
221 extern struct gdbarch
*python_gdbarch
;
222 extern const struct language_defn
*python_language
;
224 /* Use this after a TRY_EXCEPT to throw the appropriate Python
226 #define GDB_PY_HANDLE_EXCEPTION(Exception) \
228 if (Exception.reason < 0) \
229 return gdbpy_convert_exception (Exception); \
232 /* Use this after a TRY_EXCEPT to throw the appropriate Python
233 exception. This macro is for use inside setter functions. */
234 #define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
236 if (Exception.reason < 0) \
238 gdbpy_convert_exception (Exception); \
243 void gdbpy_print_stack (void);
245 void source_python_script_for_objfile (struct objfile
*objfile
,
246 FILE *stream
, const char *file
);
248 PyObject
*python_string_to_unicode (PyObject
*obj
);
249 char *unicode_to_target_string (PyObject
*unicode_str
);
250 char *python_string_to_target_string (PyObject
*obj
);
251 PyObject
*python_string_to_target_python_string (PyObject
*obj
);
252 char *python_string_to_host_string (PyObject
*obj
);
253 PyObject
*target_string_to_unicode (const gdb_byte
*str
, int length
);
254 int gdbpy_is_string (PyObject
*obj
);
255 char *gdbpy_obj_to_string (PyObject
*obj
);
256 char *gdbpy_exception_to_string (PyObject
*ptype
, PyObject
*pvalue
);
258 int gdbpy_is_lazy_string (PyObject
*result
);
259 void gdbpy_extract_lazy_string (PyObject
*string
, CORE_ADDR
*addr
,
260 struct type
**str_type
,
261 long *length
, char **encoding
);
263 int gdbpy_is_value_object (PyObject
*obj
);
265 /* Note that these are declared here, and not in python.h with the
266 other pretty-printer functions, because they refer to PyObject. */
267 PyObject
*apply_varobj_pretty_printer (PyObject
*print_obj
,
268 struct value
**replacement
,
269 struct ui_file
*stream
);
270 PyObject
*gdbpy_get_varobj_pretty_printer (struct value
*value
);
271 char *gdbpy_get_display_hint (PyObject
*printer
);
272 PyObject
*gdbpy_default_visualizer (PyObject
*self
, PyObject
*args
);
274 extern PyObject
*gdbpy_doc_cst
;
275 extern PyObject
*gdbpy_children_cst
;
276 extern PyObject
*gdbpy_to_string_cst
;
277 extern PyObject
*gdbpy_display_hint_cst
;
278 extern PyObject
*gdbpy_enabled_cst
;
279 extern PyObject
*gdbpy_value_cst
;
281 /* Exception types. */
282 extern PyObject
*gdbpy_gdb_error
;
283 extern PyObject
*gdbpy_gdb_memory_error
;
284 extern PyObject
*gdbpy_gdberror_exc
;
286 extern PyObject
*gdbpy_convert_exception (struct gdb_exception
);
288 int get_addr_from_python (PyObject
*obj
, CORE_ADDR
*addr
);
290 PyObject
*gdb_py_object_from_longest (LONGEST l
);
291 PyObject
*gdb_py_object_from_ulongest (ULONGEST l
);
292 int gdb_py_int_as_long (PyObject
*, long *);
294 #endif /* GDB_PYTHON_INTERNAL_H */