1 /* Gdb/Python header for private use by Python module.
3 Copyright (C) 2008, 2009, 2010 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
45 #include "python2.4/Python.h"
46 #include "python2.4/frameobject.h"
47 /* Py_ssize_t is not defined until 2.5.
48 Logical type for Py_ssize_t is Py_intptr_t, but that fails in 64-bit
49 compilation due to several apparent mistakes in python2.4 API, so we
51 typedef int Py_ssize_t
;
52 #elif HAVE_LIBPYTHON2_5
53 #include "python2.5/Python.h"
54 #include "python2.5/frameobject.h"
55 #elif HAVE_LIBPYTHON2_6
56 #include "python2.6/Python.h"
57 #include "python2.6/frameobject.h"
58 #elif HAVE_LIBPYTHON2_7
59 #include "python2.7/Python.h"
60 #include "python2.7/frameobject.h"
62 #error "Unable to find usable Python.h"
65 /* If Python.h does not define WITH_THREAD, then the various
66 GIL-related functions will not be defined. However,
67 PyGILState_STATE will be. */
69 #define PyGILState_Ensure() ((PyGILState_STATE) 0)
70 #define PyGILState_Release(ARG) ((void)(ARG))
71 #define PyEval_InitThreads()
72 #define PyThreadState_Swap(ARG) ((void)(ARG))
73 #define PyEval_ReleaseLock()
76 /* In order to be able to parse symtab_and_line_to_sal_object function
77 a real symtab_and_line structure is needed. */
80 /* Also needed to parse enum var_types. */
83 #include "exceptions.h"
90 extern PyObject
*gdb_module
;
91 extern PyTypeObject value_object_type
;
92 extern PyTypeObject block_object_type
;
93 extern PyTypeObject symbol_object_type
;
99 /* The thread we represent. */
100 struct thread_info
*thread
;
102 /* The Inferior object to which this thread belongs. */
106 extern struct cmd_list_element
*set_python_list
;
107 extern struct cmd_list_element
*show_python_list
;
109 PyObject
*gdbpy_history (PyObject
*self
, PyObject
*args
);
110 PyObject
*gdbpy_breakpoints (PyObject
*, PyObject
*);
111 PyObject
*gdbpy_frame_stop_reason_string (PyObject
*, PyObject
*);
112 PyObject
*gdbpy_lookup_symbol (PyObject
*self
, PyObject
*args
, PyObject
*kw
);
113 PyObject
*gdbpy_selected_frame (PyObject
*self
, PyObject
*args
);
114 PyObject
*gdbpy_block_for_pc (PyObject
*self
, PyObject
*args
);
115 PyObject
*gdbpy_lookup_type (PyObject
*self
, PyObject
*args
, PyObject
*kw
);
116 PyObject
*gdbpy_create_lazy_string_object (CORE_ADDR address
, long length
,
117 const char *encoding
, struct type
*type
);
118 PyObject
*gdbpy_inferiors (PyObject
*unused
, PyObject
*unused2
);
119 PyObject
*gdbpy_selected_thread (PyObject
*self
, PyObject
*args
);
120 PyObject
*gdbpy_string_to_argv (PyObject
*self
, PyObject
*args
);
121 PyObject
*gdbpy_parameter (PyObject
*self
, PyObject
*args
);
122 PyObject
*gdbpy_parameter_value (enum var_types type
, void *var
);
123 char *gdbpy_parse_command_name (char *text
,
124 struct cmd_list_element
***base_list
,
125 struct cmd_list_element
**start_list
);
127 PyObject
*symtab_and_line_to_sal_object (struct symtab_and_line sal
);
128 PyObject
*symtab_to_symtab_object (struct symtab
*symtab
);
129 PyObject
*symbol_to_symbol_object (struct symbol
*sym
);
130 PyObject
*block_to_block_object (struct block
*block
, struct objfile
*objfile
);
131 PyObject
*value_to_value_object (struct value
*v
);
132 PyObject
*type_to_type_object (struct type
*);
133 PyObject
*frame_info_to_frame_object (struct frame_info
*frame
);
135 PyObject
*pspace_to_pspace_object (struct program_space
*);
136 PyObject
*pspy_get_printers (PyObject
*, void *);
138 PyObject
*objfile_to_objfile_object (struct objfile
*);
139 PyObject
*objfpy_get_printers (PyObject
*, void *);
141 thread_object
*create_thread_object (struct thread_info
*tp
);
142 thread_object
*find_thread_object (ptid_t ptid
);
143 PyObject
*find_inferior_object (int pid
);
145 struct block
*block_object_to_block (PyObject
*obj
);
146 struct symbol
*symbol_object_to_symbol (PyObject
*obj
);
147 struct value
*value_object_to_value (PyObject
*self
);
148 struct value
*convert_value_from_python (PyObject
*obj
);
149 struct type
*type_object_to_type (PyObject
*obj
);
150 struct symtab
*symtab_object_to_symtab (PyObject
*obj
);
151 struct symtab_and_line
*sal_object_to_symtab_and_line (PyObject
*obj
);
153 void gdbpy_initialize_auto_load (void);
154 void gdbpy_initialize_values (void);
155 void gdbpy_initialize_frames (void);
156 void gdbpy_initialize_symtabs (void);
157 void gdbpy_initialize_commands (void);
158 void gdbpy_initialize_symbols (void);
159 void gdbpy_initialize_symtabs (void);
160 void gdbpy_initialize_blocks (void);
161 void gdbpy_initialize_types (void);
162 void gdbpy_initialize_functions (void);
163 void gdbpy_initialize_pspace (void);
164 void gdbpy_initialize_objfile (void);
165 void gdbpy_initialize_breakpoints (void);
166 void gdbpy_initialize_lazy_string (void);
167 void gdbpy_initialize_parameters (void);
168 void gdbpy_initialize_thread (void);
169 void gdbpy_initialize_inferior (void);
171 struct cleanup
*make_cleanup_py_decref (PyObject
*py
);
173 struct cleanup
*ensure_python_env (struct gdbarch
*gdbarch
,
174 const struct language_defn
*language
);
176 extern struct gdbarch
*python_gdbarch
;
177 extern const struct language_defn
*python_language
;
179 /* Use this after a TRY_EXCEPT to throw the appropriate Python
181 #define GDB_PY_HANDLE_EXCEPTION(Exception) \
183 if (Exception.reason < 0) \
184 return gdbpy_convert_exception (Exception); \
187 /* Use this after a TRY_EXCEPT to throw the appropriate Python
188 exception. This macro is for use inside setter functions. */
189 #define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
191 if (Exception.reason < 0) \
193 gdbpy_convert_exception (Exception); \
198 void gdbpy_print_stack (void);
200 void source_python_script_for_objfile (struct objfile
*objfile
,
201 FILE *stream
, const char *file
);
203 PyObject
*python_string_to_unicode (PyObject
*obj
);
204 char *unicode_to_target_string (PyObject
*unicode_str
);
205 char *python_string_to_target_string (PyObject
*obj
);
206 PyObject
*python_string_to_target_python_string (PyObject
*obj
);
207 char *python_string_to_host_string (PyObject
*obj
);
208 PyObject
*target_string_to_unicode (const gdb_byte
*str
, int length
);
209 int gdbpy_is_string (PyObject
*obj
);
210 char *gdbpy_obj_to_string (PyObject
*obj
);
211 char *gdbpy_exception_to_string (PyObject
*ptype
, PyObject
*pvalue
);
213 int gdbpy_is_lazy_string (PyObject
*result
);
214 void gdbpy_extract_lazy_string (PyObject
*string
, CORE_ADDR
*addr
,
215 struct type
**str_type
,
216 long *length
, char **encoding
);
218 int gdbpy_is_value_object (PyObject
*obj
);
220 /* Note that these are declared here, and not in python.h with the
221 other pretty-printer functions, because they refer to PyObject. */
222 PyObject
*apply_varobj_pretty_printer (PyObject
*print_obj
,
223 struct value
**replacement
,
224 struct ui_file
*stream
);
225 PyObject
*gdbpy_get_varobj_pretty_printer (struct value
*value
);
226 char *gdbpy_get_display_hint (PyObject
*printer
);
227 PyObject
*gdbpy_default_visualizer (PyObject
*self
, PyObject
*args
);
229 extern PyObject
*gdbpy_doc_cst
;
230 extern PyObject
*gdbpy_children_cst
;
231 extern PyObject
*gdbpy_to_string_cst
;
232 extern PyObject
*gdbpy_display_hint_cst
;
233 extern PyObject
*gdbpy_enabled_cst
;
235 /* Exception types. */
236 extern PyObject
*gdbpy_gdb_error
;
237 extern PyObject
*gdbpy_gdb_memory_error
;
238 extern PyObject
*gdbpy_gdberror_exc
;
240 extern PyObject
*gdbpy_convert_exception (struct gdb_exception
);
242 int get_addr_from_python (PyObject
*obj
, CORE_ADDR
*addr
);
244 #endif /* GDB_PYTHON_INTERNAL_H */