* gc++filt.m4: New file.
[deliverable/binutils-gdb.git] / gdb / python / python-internal.h
1 /* Gdb/Python header for private use by Python module.
2
3 Copyright (C) 2008, 2009, 2010 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 #if HAVE_LIBPYTHON2_4
40 #include "python2.4/Python.h"
41 #include "python2.4/frameobject.h"
42 /* Py_ssize_t is not defined until 2.5.
43 Logical type for Py_ssize_t is Py_intptr_t, but that fails in 64-bit
44 compilation due to several apparent mistakes in python2.4 API, so we
45 use 'int' instead. */
46 typedef int Py_ssize_t;
47 #elif HAVE_LIBPYTHON2_5
48 #include "python2.5/Python.h"
49 #include "python2.5/frameobject.h"
50 #elif HAVE_LIBPYTHON2_6
51 #include "python2.6/Python.h"
52 #include "python2.6/frameobject.h"
53 #else
54 #error "Unable to find usable Python.h"
55 #endif
56
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)
62 #define PyGILState_Release(ARG) ((void)(ARG))
63 #define PyEval_InitThreads() 0
64 #define PyThreadState_Swap(ARG) ((void)(ARG))
65 #define PyEval_InitThreads() 0
66 #define PyEval_ReleaseLock() 0
67 #endif
68
69 /* In order to be able to parse symtab_and_line_to_sal_object function
70 a real symtab_and_line structure is needed. */
71 #include "symtab.h"
72
73 /* Also needed to parse enum var_types. */
74 #include "command.h"
75
76 struct block;
77 struct value;
78 struct language_defn;
79 struct program_space;
80
81 extern PyObject *gdb_module;
82 extern PyTypeObject value_object_type;
83 extern PyTypeObject block_object_type;
84 extern PyTypeObject symbol_object_type;
85
86 typedef struct
87 {
88 PyObject_HEAD
89
90 /* The thread we represent. */
91 struct thread_info *thread;
92
93 /* The Inferior object to which this thread belongs. */
94 PyObject *inf_obj;
95 } thread_object;
96
97 extern struct cmd_list_element *set_python_list;
98 extern struct cmd_list_element *show_python_list;
99
100 PyObject *gdbpy_history (PyObject *self, PyObject *args);
101 PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
102 PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
103 PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw);
104 PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args);
105 PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
106 PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw);
107 PyObject *gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
108 const char *encoding, struct type *type);
109 PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2);
110 PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args);
111 PyObject *gdbpy_string_to_argv (PyObject *self, PyObject *args);
112 PyObject *gdbpy_get_hook_function (const char *);
113 PyObject *gdbpy_parameter (PyObject *self, PyObject *args);
114 PyObject *gdbpy_parameter_value (enum var_types type, void *var);
115 char *gdbpy_parse_command_name (char *text,
116 struct cmd_list_element ***base_list,
117 struct cmd_list_element **start_list);
118
119 PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
120 PyObject *symtab_to_symtab_object (struct symtab *symtab);
121 PyObject *symbol_to_symbol_object (struct symbol *sym);
122 PyObject *block_to_block_object (struct block *block, struct objfile *objfile);
123 PyObject *value_to_value_object (struct value *v);
124 PyObject *type_to_type_object (struct type *);
125 PyObject *frame_info_to_frame_object (struct frame_info *frame);
126
127 PyObject *pspace_to_pspace_object (struct program_space *);
128 PyObject *pspy_get_printers (PyObject *, void *);
129
130 PyObject *objfile_to_objfile_object (struct objfile *);
131 PyObject *objfpy_get_printers (PyObject *, void *);
132
133 thread_object *create_thread_object (struct thread_info *tp);
134 thread_object *find_thread_object (ptid_t ptid);
135 PyObject *find_inferior_object (int pid);
136
137 struct block *block_object_to_block (PyObject *obj);
138 struct symbol *symbol_object_to_symbol (PyObject *obj);
139 struct value *value_object_to_value (PyObject *self);
140 struct value *convert_value_from_python (PyObject *obj);
141 struct type *type_object_to_type (PyObject *obj);
142 struct symtab *symtab_object_to_symtab (PyObject *obj);
143 struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj);
144
145 void gdbpy_initialize_auto_load (void);
146 void gdbpy_initialize_values (void);
147 void gdbpy_initialize_frames (void);
148 void gdbpy_initialize_symtabs (void);
149 void gdbpy_initialize_commands (void);
150 void gdbpy_initialize_symbols (void);
151 void gdbpy_initialize_symtabs (void);
152 void gdbpy_initialize_blocks (void);
153 void gdbpy_initialize_types (void);
154 void gdbpy_initialize_functions (void);
155 void gdbpy_initialize_pspace (void);
156 void gdbpy_initialize_objfile (void);
157 void gdbpy_initialize_breakpoints (void);
158 void gdbpy_initialize_lazy_string (void);
159 void gdbpy_initialize_parameters (void);
160 void gdbpy_initialize_thread (void);
161 void gdbpy_initialize_inferior (void);
162
163 struct cleanup *make_cleanup_py_decref (PyObject *py);
164
165 struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
166 const struct language_defn *language);
167
168 extern struct gdbarch *python_gdbarch;
169 extern const struct language_defn *python_language;
170
171 /* Use this after a TRY_EXCEPT to throw the appropriate Python
172 exception. */
173 #define GDB_PY_HANDLE_EXCEPTION(Exception) \
174 do { \
175 if (Exception.reason < 0) \
176 return PyErr_Format (Exception.reason == RETURN_QUIT \
177 ? PyExc_KeyboardInterrupt : PyExc_RuntimeError, \
178 "%s", Exception.message); \
179 } while (0)
180
181 /* Use this after a TRY_EXCEPT to throw the appropriate Python
182 exception. This macro is for use inside setter functions. */
183 #define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
184 do { \
185 if (Exception.reason < 0) \
186 { \
187 PyErr_Format (Exception.reason == RETURN_QUIT \
188 ? PyExc_KeyboardInterrupt : PyExc_RuntimeError, \
189 "%s", Exception.message); \
190 return -1; \
191 } \
192 } while (0)
193
194 void gdbpy_print_stack (void);
195
196 void source_python_script_for_objfile (struct objfile *objfile,
197 FILE *stream, const char *file);
198
199 PyObject *python_string_to_unicode (PyObject *obj);
200 char *unicode_to_target_string (PyObject *unicode_str);
201 char *python_string_to_target_string (PyObject *obj);
202 PyObject *python_string_to_target_python_string (PyObject *obj);
203 char *python_string_to_host_string (PyObject *obj);
204 PyObject *target_string_to_unicode (const gdb_byte *str, int length);
205 int gdbpy_is_string (PyObject *obj);
206 char *gdbpy_obj_to_string (PyObject *obj);
207 char *gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue);
208
209 int gdbpy_is_lazy_string (PyObject *result);
210 gdb_byte *gdbpy_extract_lazy_string (PyObject *string,
211 struct type **str_type,
212 long *length, char **encoding);
213
214 int gdbpy_is_value_object (PyObject *obj);
215
216 /* Note that these are declared here, and not in python.h with the
217 other pretty-printer functions, because they refer to PyObject. */
218 PyObject *apply_varobj_pretty_printer (PyObject *print_obj,
219 struct value **replacement);
220 PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
221 char *gdbpy_get_display_hint (PyObject *printer);
222 PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);
223
224 extern PyObject *gdbpy_doc_cst;
225 extern PyObject *gdbpy_children_cst;
226 extern PyObject *gdbpy_to_string_cst;
227 extern PyObject *gdbpy_display_hint_cst;
228 extern PyObject *gdbpy_enabled_cst;
229
230 extern PyObject *gdbpy_gdberror_exc;
231
232 int get_addr_from_python (PyObject *obj, CORE_ADDR *addr);
233
234 #endif /* GDB_PYTHON_INTERNAL_H */
This page took 0.037794 seconds and 4 git commands to generate.