Remove sp_regnum_from_eax and pc_regnum_from_eax
[deliverable/binutils-gdb.git] / gdb / python / python-internal.h
CommitLineData
d57a3c85
TJB
1/* Gdb/Python header for private use by Python module.
2
0b302171 3 Copyright (C) 2008-2012 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
1c033f8c
TT
44/* Request clean size types from Python. */
45#define PY_SSIZE_T_CLEAN
46
ac534cba
JB
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. */
50#include <Python.h>
51#include <frameobject.h>
d57a3c85 52#if HAVE_LIBPYTHON2_4
5171e6b3
TT
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
56 use 'int' instead. */
57typedef int Py_ssize_t;
d57a3c85
TJB
58#endif
59
ca30a762
TT
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. */
63#ifndef WITH_THREAD
64#define PyGILState_Ensure() ((PyGILState_STATE) 0)
548a926a 65#define PyGILState_Release(ARG) ((void)(ARG))
aed1781d 66#define PyEval_InitThreads()
548a926a 67#define PyThreadState_Swap(ARG) ((void)(ARG))
aed1781d 68#define PyEval_ReleaseLock()
ca30a762
TT
69#endif
70
74aedc46
TT
71/* Python supplies HAVE_LONG_LONG and some `long long' support when it
72 is available. These defines let us handle the differences more
73 cleanly. */
74#ifdef HAVE_LONG_LONG
75
76#define GDB_PY_LL_ARG "L"
77#define GDB_PY_LLU_ARG "K"
78typedef PY_LONG_LONG gdb_py_longest;
79typedef 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
83
84#else /* HAVE_LONG_LONG */
85
86#define GDB_PY_LL_ARG "L"
87#define GDB_PY_LLU_ARG "K"
88typedef long gdb_py_longest;
89typedef 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
93
94#endif /* HAVE_LONG_LONG */
95
96
9cb74f47
PM
97/* In order to be able to parse symtab_and_line_to_sal_object function
98 a real symtab_and_line structure is needed. */
99#include "symtab.h"
100
d7b32ed3
PM
101/* Also needed to parse enum var_types. */
102#include "command.h"
505500db 103#include "breakpoint.h"
d7b32ed3 104
621c8364
TT
105#include "exceptions.h"
106
a73bb892
PK
107enum gdbpy_iter_kind { iter_keys, iter_values, iter_items };
108
f3e9a817 109struct block;
a08702d6 110struct value;
d452c4bc 111struct language_defn;
fa33c3cd 112struct program_space;
505500db 113struct bpstats;
619cebe8 114struct inferior;
d57a3c85
TJB
115
116extern PyObject *gdb_module;
b9516fa1 117extern PyObject *gdb_python_module;
a08702d6 118extern PyTypeObject value_object_type;
f3e9a817
PM
119extern PyTypeObject block_object_type;
120extern PyTypeObject symbol_object_type;
505500db
SW
121extern PyTypeObject event_object_type;
122extern PyTypeObject events_object_type;
123extern PyTypeObject stop_event_object_type;
cc72b2a2 124extern PyTypeObject breakpoint_object_type;
f0823d2c 125extern PyTypeObject frame_object_type;
cc72b2a2
KP
126
127typedef struct breakpoint_object
128{
129 PyObject_HEAD
130
131 /* The breakpoint number according to gdb. */
132 int number;
133
134 /* The gdb breakpoint object, or NULL if the breakpoint has been
135 deleted. */
136 struct breakpoint *bp;
137
138 /* 1 is this is a FinishBreakpoint object, 0 otherwise. */
139 int is_finish_bp;
140} breakpoint_object;
141
142/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
143 exception if it is invalid. */
144#define BPPY_REQUIRE_VALID(Breakpoint) \
145 do { \
146 if ((Breakpoint)->bp == NULL) \
147 return PyErr_Format (PyExc_RuntimeError, \
148 _("Breakpoint %d is invalid."), \
149 (Breakpoint)->number); \
150 } while (0)
151
152/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
153 exception if it is invalid. This macro is for use in setter functions. */
154#define BPPY_SET_REQUIRE_VALID(Breakpoint) \
155 do { \
156 if ((Breakpoint)->bp == NULL) \
157 { \
158 PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
159 (Breakpoint)->number); \
160 return -1; \
161 } \
162 } while (0)
163
164
165/* Variables used to pass information between the Breakpoint
166 constructor and the breakpoint-created hook function. */
167extern breakpoint_object *bppy_pending_object;
505500db 168
a08702d6 169
595939de
PM
170typedef struct
171{
172 PyObject_HEAD
173
174 /* The thread we represent. */
175 struct thread_info *thread;
176
177 /* The Inferior object to which this thread belongs. */
178 PyObject *inf_obj;
179} thread_object;
180
8a1ea21f
DE
181extern struct cmd_list_element *set_python_list;
182extern struct cmd_list_element *show_python_list;
183
08c637de 184PyObject *gdbpy_history (PyObject *self, PyObject *args);
adc36818 185PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
f8f6f20b 186PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
f3e9a817 187PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw);
6e6fbe60
DE
188PyObject *gdbpy_lookup_global_symbol (PyObject *self, PyObject *args,
189 PyObject *kw);
d8e22779 190PyObject *gdbpy_newest_frame (PyObject *self, PyObject *args);
f8f6f20b 191PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args);
f3e9a817 192PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
2c74e833 193PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw);
be759fcf 194PyObject *gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
9a2b4c1b
MS
195 const char *encoding,
196 struct type *type);
595939de
PM
197PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2);
198PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args);
2aa48337 199PyObject *gdbpy_selected_inferior (PyObject *self, PyObject *args);
07ca107c 200PyObject *gdbpy_string_to_argv (PyObject *self, PyObject *args);
d7b32ed3
PM
201PyObject *gdbpy_parameter (PyObject *self, PyObject *args);
202PyObject *gdbpy_parameter_value (enum var_types type, void *var);
63d97a20 203char *gdbpy_parse_command_name (const char *name,
d7b32ed3
PM
204 struct cmd_list_element ***base_list,
205 struct cmd_list_element **start_list);
a08702d6 206
f3e9a817
PM
207PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
208PyObject *symtab_to_symtab_object (struct symtab *symtab);
209PyObject *symbol_to_symbol_object (struct symbol *sym);
9df2fbc4
PM
210PyObject *block_to_block_object (const struct block *block,
211 struct objfile *objfile);
a08702d6 212PyObject *value_to_value_object (struct value *v);
2c74e833 213PyObject *type_to_type_object (struct type *);
595939de 214PyObject *frame_info_to_frame_object (struct frame_info *frame);
89c73ade 215
fa33c3cd
DE
216PyObject *pspace_to_pspace_object (struct program_space *);
217PyObject *pspy_get_printers (PyObject *, void *);
218
219PyObject *objfile_to_objfile_object (struct objfile *);
89c73ade 220PyObject *objfpy_get_printers (PyObject *, void *);
a08702d6 221
595939de
PM
222thread_object *create_thread_object (struct thread_info *tp);
223thread_object *find_thread_object (ptid_t ptid);
224PyObject *find_inferior_object (int pid);
505500db 225PyObject *inferior_to_inferior_object (struct inferior *inferior);
595939de 226
9df2fbc4 227const struct block *block_object_to_block (PyObject *obj);
f3e9a817 228struct symbol *symbol_object_to_symbol (PyObject *obj);
a6bac58e 229struct value *value_object_to_value (PyObject *self);
a08702d6 230struct value *convert_value_from_python (PyObject *obj);
2c74e833 231struct type *type_object_to_type (PyObject *obj);
f3e9a817
PM
232struct symtab *symtab_object_to_symtab (PyObject *obj);
233struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj);
cc72b2a2 234struct frame_info *frame_object_to_frame_info (PyObject *frame_obj);
a08702d6 235
037bbc8e 236void gdbpy_initialize_gdb_readline (void);
8a1ea21f 237void gdbpy_initialize_auto_load (void);
a08702d6 238void gdbpy_initialize_values (void);
f8f6f20b 239void gdbpy_initialize_frames (void);
f3e9a817 240void gdbpy_initialize_symtabs (void);
d8906c6f 241void gdbpy_initialize_commands (void);
f3e9a817
PM
242void gdbpy_initialize_symbols (void);
243void gdbpy_initialize_symtabs (void);
244void gdbpy_initialize_blocks (void);
2c74e833 245void gdbpy_initialize_types (void);
bc3b79fd 246void gdbpy_initialize_functions (void);
fa33c3cd 247void gdbpy_initialize_pspace (void);
89c73ade 248void gdbpy_initialize_objfile (void);
adc36818 249void gdbpy_initialize_breakpoints (void);
cc72b2a2 250void gdbpy_initialize_finishbreakpoints (void);
be759fcf 251void gdbpy_initialize_lazy_string (void);
d7b32ed3 252void gdbpy_initialize_parameters (void);
595939de
PM
253void gdbpy_initialize_thread (void);
254void gdbpy_initialize_inferior (void);
505500db
SW
255void gdbpy_initialize_eventregistry (void);
256void gdbpy_initialize_event (void);
257void gdbpy_initialize_py_events (void);
258void gdbpy_initialize_stop_event (void);
259void gdbpy_initialize_signal_event (void);
260void gdbpy_initialize_breakpoint_event (void);
261void gdbpy_initialize_continue_event (void);
262void gdbpy_initialize_exited_event (void);
263void gdbpy_initialize_thread_event (void);
20c168b5 264void gdbpy_initialize_new_objfile_event (void);
d57a3c85
TJB
265
266struct cleanup *make_cleanup_py_decref (PyObject *py);
d452c4bc
UW
267
268struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
269 const struct language_defn *language);
270
271extern struct gdbarch *python_gdbarch;
272extern const struct language_defn *python_language;
d57a3c85
TJB
273
274/* Use this after a TRY_EXCEPT to throw the appropriate Python
275 exception. */
276#define GDB_PY_HANDLE_EXCEPTION(Exception) \
277 do { \
278 if (Exception.reason < 0) \
621c8364 279 return gdbpy_convert_exception (Exception); \
d57a3c85
TJB
280 } while (0)
281
adc36818
PM
282/* Use this after a TRY_EXCEPT to throw the appropriate Python
283 exception. This macro is for use inside setter functions. */
284#define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
285 do { \
286 if (Exception.reason < 0) \
287 { \
621c8364 288 gdbpy_convert_exception (Exception); \
adc36818
PM
289 return -1; \
290 } \
291 } while (0)
d57a3c85
TJB
292
293void gdbpy_print_stack (void);
294
4c63965b
JK
295void source_python_script_for_objfile (struct objfile *objfile, FILE *file,
296 const char *filename);
8a1ea21f 297
d57a3c85
TJB
298PyObject *python_string_to_unicode (PyObject *obj);
299char *unicode_to_target_string (PyObject *unicode_str);
300char *python_string_to_target_string (PyObject *obj);
fbb8f299 301PyObject *python_string_to_target_python_string (PyObject *obj);
08c637de 302char *python_string_to_host_string (PyObject *obj);
b6cb8e7d 303PyObject *target_string_to_unicode (const gdb_byte *str, int length);
08c637de 304int gdbpy_is_string (PyObject *obj);
07ca107c
DE
305char *gdbpy_obj_to_string (PyObject *obj);
306char *gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue);
307
be759fcf 308int gdbpy_is_lazy_string (PyObject *result);
09ca9e2e
TT
309void gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr,
310 struct type **str_type,
311 long *length, char **encoding);
d57a3c85 312
595939de
PM
313int gdbpy_is_value_object (PyObject *obj);
314
b6313243
TT
315/* Note that these are declared here, and not in python.h with the
316 other pretty-printer functions, because they refer to PyObject. */
fbb8f299 317PyObject *apply_varobj_pretty_printer (PyObject *print_obj,
621c8364
TT
318 struct value **replacement,
319 struct ui_file *stream);
b6313243
TT
320PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
321char *gdbpy_get_display_hint (PyObject *printer);
322PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);
323
cc72b2a2
KP
324void bpfinishpy_pre_stop_hook (struct breakpoint_object *bp_obj);
325void bpfinishpy_post_stop_hook (struct breakpoint_object *bp_obj);
326
d8906c6f 327extern PyObject *gdbpy_doc_cst;
a6bac58e
TT
328extern PyObject *gdbpy_children_cst;
329extern PyObject *gdbpy_to_string_cst;
330extern PyObject *gdbpy_display_hint_cst;
967cf477 331extern PyObject *gdbpy_enabled_cst;
fb6a3ed3 332extern PyObject *gdbpy_value_cst;
d8906c6f 333
621c8364
TT
334/* Exception types. */
335extern PyObject *gdbpy_gdb_error;
336extern PyObject *gdbpy_gdb_memory_error;
07ca107c
DE
337extern PyObject *gdbpy_gdberror_exc;
338
621c8364
TT
339extern PyObject *gdbpy_convert_exception (struct gdb_exception);
340
595939de
PM
341int get_addr_from_python (PyObject *obj, CORE_ADDR *addr);
342
74aedc46
TT
343PyObject *gdb_py_object_from_longest (LONGEST l);
344PyObject *gdb_py_object_from_ulongest (ULONGEST l);
345int gdb_py_int_as_long (PyObject *, long *);
346
2e8265fd
TT
347PyObject *gdb_py_generic_dict (PyObject *self, void *closure);
348
d57a3c85 349#endif /* GDB_PYTHON_INTERNAL_H */
This page took 0.433609 seconds and 4 git commands to generate.