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