gdb
[deliverable/binutils-gdb.git] / gdb / python / python-internal.h
CommitLineData
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
d57a3c85
TJB
44#if HAVE_LIBPYTHON2_4
45#include "python2.4/Python.h"
a6bac58e 46#include "python2.4/frameobject.h"
5171e6b3
TT
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
50 use 'int' instead. */
51typedef int Py_ssize_t;
d57a3c85
TJB
52#elif HAVE_LIBPYTHON2_5
53#include "python2.5/Python.h"
a6bac58e 54#include "python2.5/frameobject.h"
d57a3c85
TJB
55#elif HAVE_LIBPYTHON2_6
56#include "python2.6/Python.h"
a6bac58e 57#include "python2.6/frameobject.h"
11763c18
TT
58#elif HAVE_LIBPYTHON2_7
59#include "python2.7/Python.h"
60#include "python2.7/frameobject.h"
d57a3c85
TJB
61#else
62#error "Unable to find usable Python.h"
63#endif
64
ca30a762
TT
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. */
68#ifndef WITH_THREAD
69#define PyGILState_Ensure() ((PyGILState_STATE) 0)
548a926a 70#define PyGILState_Release(ARG) ((void)(ARG))
aed1781d 71#define PyEval_InitThreads()
548a926a 72#define PyThreadState_Swap(ARG) ((void)(ARG))
aed1781d 73#define PyEval_ReleaseLock()
ca30a762
TT
74#endif
75
9cb74f47
PM
76/* In order to be able to parse symtab_and_line_to_sal_object function
77 a real symtab_and_line structure is needed. */
78#include "symtab.h"
79
d7b32ed3
PM
80/* Also needed to parse enum var_types. */
81#include "command.h"
82
621c8364
TT
83#include "exceptions.h"
84
f3e9a817 85struct block;
a08702d6 86struct value;
d452c4bc 87struct language_defn;
fa33c3cd 88struct program_space;
d57a3c85
TJB
89
90extern PyObject *gdb_module;
a08702d6 91extern PyTypeObject value_object_type;
f3e9a817
PM
92extern PyTypeObject block_object_type;
93extern PyTypeObject symbol_object_type;
a08702d6 94
595939de
PM
95typedef struct
96{
97 PyObject_HEAD
98
99 /* The thread we represent. */
100 struct thread_info *thread;
101
102 /* The Inferior object to which this thread belongs. */
103 PyObject *inf_obj;
104} thread_object;
105
8a1ea21f
DE
106extern struct cmd_list_element *set_python_list;
107extern struct cmd_list_element *show_python_list;
108
08c637de 109PyObject *gdbpy_history (PyObject *self, PyObject *args);
adc36818 110PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
f8f6f20b 111PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
f3e9a817 112PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw);
d8e22779 113PyObject *gdbpy_newest_frame (PyObject *self, PyObject *args);
f8f6f20b 114PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args);
f3e9a817 115PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
2c74e833 116PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw);
be759fcf 117PyObject *gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
9a2b4c1b
MS
118 const char *encoding,
119 struct type *type);
595939de
PM
120PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2);
121PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args);
07ca107c 122PyObject *gdbpy_string_to_argv (PyObject *self, PyObject *args);
d7b32ed3
PM
123PyObject *gdbpy_parameter (PyObject *self, PyObject *args);
124PyObject *gdbpy_parameter_value (enum var_types type, void *var);
125char *gdbpy_parse_command_name (char *text,
126 struct cmd_list_element ***base_list,
127 struct cmd_list_element **start_list);
a08702d6 128
f3e9a817
PM
129PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
130PyObject *symtab_to_symtab_object (struct symtab *symtab);
131PyObject *symbol_to_symbol_object (struct symbol *sym);
132PyObject *block_to_block_object (struct block *block, struct objfile *objfile);
a08702d6 133PyObject *value_to_value_object (struct value *v);
2c74e833 134PyObject *type_to_type_object (struct type *);
595939de 135PyObject *frame_info_to_frame_object (struct frame_info *frame);
89c73ade 136
fa33c3cd
DE
137PyObject *pspace_to_pspace_object (struct program_space *);
138PyObject *pspy_get_printers (PyObject *, void *);
139
140PyObject *objfile_to_objfile_object (struct objfile *);
89c73ade 141PyObject *objfpy_get_printers (PyObject *, void *);
a08702d6 142
595939de
PM
143thread_object *create_thread_object (struct thread_info *tp);
144thread_object *find_thread_object (ptid_t ptid);
145PyObject *find_inferior_object (int pid);
146
f3e9a817
PM
147struct block *block_object_to_block (PyObject *obj);
148struct symbol *symbol_object_to_symbol (PyObject *obj);
a6bac58e 149struct value *value_object_to_value (PyObject *self);
a08702d6 150struct value *convert_value_from_python (PyObject *obj);
2c74e833 151struct type *type_object_to_type (PyObject *obj);
f3e9a817
PM
152struct symtab *symtab_object_to_symtab (PyObject *obj);
153struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj);
a08702d6 154
8a1ea21f 155void gdbpy_initialize_auto_load (void);
a08702d6 156void gdbpy_initialize_values (void);
f8f6f20b 157void gdbpy_initialize_frames (void);
f3e9a817 158void gdbpy_initialize_symtabs (void);
d8906c6f 159void gdbpy_initialize_commands (void);
f3e9a817
PM
160void gdbpy_initialize_symbols (void);
161void gdbpy_initialize_symtabs (void);
162void gdbpy_initialize_blocks (void);
2c74e833 163void gdbpy_initialize_types (void);
bc3b79fd 164void gdbpy_initialize_functions (void);
fa33c3cd 165void gdbpy_initialize_pspace (void);
89c73ade 166void gdbpy_initialize_objfile (void);
adc36818 167void gdbpy_initialize_breakpoints (void);
be759fcf 168void gdbpy_initialize_lazy_string (void);
d7b32ed3 169void gdbpy_initialize_parameters (void);
595939de
PM
170void gdbpy_initialize_thread (void);
171void gdbpy_initialize_inferior (void);
d57a3c85
TJB
172
173struct cleanup *make_cleanup_py_decref (PyObject *py);
d452c4bc
UW
174
175struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
176 const struct language_defn *language);
177
178extern struct gdbarch *python_gdbarch;
179extern const struct language_defn *python_language;
d57a3c85
TJB
180
181/* Use this after a TRY_EXCEPT to throw the appropriate Python
182 exception. */
183#define GDB_PY_HANDLE_EXCEPTION(Exception) \
184 do { \
185 if (Exception.reason < 0) \
621c8364 186 return gdbpy_convert_exception (Exception); \
d57a3c85
TJB
187 } while (0)
188
adc36818
PM
189/* Use this after a TRY_EXCEPT to throw the appropriate Python
190 exception. This macro is for use inside setter functions. */
191#define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
192 do { \
193 if (Exception.reason < 0) \
194 { \
621c8364 195 gdbpy_convert_exception (Exception); \
adc36818
PM
196 return -1; \
197 } \
198 } while (0)
d57a3c85
TJB
199
200void gdbpy_print_stack (void);
201
8a1ea21f
DE
202void source_python_script_for_objfile (struct objfile *objfile,
203 FILE *stream, const char *file);
204
d57a3c85
TJB
205PyObject *python_string_to_unicode (PyObject *obj);
206char *unicode_to_target_string (PyObject *unicode_str);
207char *python_string_to_target_string (PyObject *obj);
fbb8f299 208PyObject *python_string_to_target_python_string (PyObject *obj);
08c637de 209char *python_string_to_host_string (PyObject *obj);
b6cb8e7d 210PyObject *target_string_to_unicode (const gdb_byte *str, int length);
08c637de 211int gdbpy_is_string (PyObject *obj);
07ca107c
DE
212char *gdbpy_obj_to_string (PyObject *obj);
213char *gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue);
214
be759fcf 215int gdbpy_is_lazy_string (PyObject *result);
09ca9e2e
TT
216void gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr,
217 struct type **str_type,
218 long *length, char **encoding);
d57a3c85 219
595939de
PM
220int gdbpy_is_value_object (PyObject *obj);
221
b6313243
TT
222/* Note that these are declared here, and not in python.h with the
223 other pretty-printer functions, because they refer to PyObject. */
fbb8f299 224PyObject *apply_varobj_pretty_printer (PyObject *print_obj,
621c8364
TT
225 struct value **replacement,
226 struct ui_file *stream);
b6313243
TT
227PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
228char *gdbpy_get_display_hint (PyObject *printer);
229PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);
230
d8906c6f 231extern PyObject *gdbpy_doc_cst;
a6bac58e
TT
232extern PyObject *gdbpy_children_cst;
233extern PyObject *gdbpy_to_string_cst;
234extern PyObject *gdbpy_display_hint_cst;
967cf477 235extern PyObject *gdbpy_enabled_cst;
d8906c6f 236
621c8364
TT
237/* Exception types. */
238extern PyObject *gdbpy_gdb_error;
239extern PyObject *gdbpy_gdb_memory_error;
07ca107c
DE
240extern PyObject *gdbpy_gdberror_exc;
241
621c8364
TT
242extern PyObject *gdbpy_convert_exception (struct gdb_exception);
243
595939de
PM
244int get_addr_from_python (PyObject *obj, CORE_ADDR *addr);
245
d57a3c85 246#endif /* GDB_PYTHON_INTERNAL_H */
This page took 0.260503 seconds and 4 git commands to generate.