* remote-utils.c (putpkt_binary_1): Call readchar instead of read.
[deliverable/binutils-gdb.git] / gdb / python / python-internal.h
CommitLineData
d57a3c85
TJB
1/* Gdb/Python header for private use by Python module.
2
4c38e0a4 3 Copyright (C) 2008, 2009, 2010 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.
33 To work around this, undef _POSIX_C_SOURCE before we include Python.h. */
34#undef _POSIX_C_SOURCE
35
36#if HAVE_LIBPYTHON2_4
37#include "python2.4/Python.h"
a6bac58e 38#include "python2.4/frameobject.h"
5171e6b3
TT
39/* Py_ssize_t is not defined until 2.5.
40 Logical type for Py_ssize_t is Py_intptr_t, but that fails in 64-bit
41 compilation due to several apparent mistakes in python2.4 API, so we
42 use 'int' instead. */
43typedef int Py_ssize_t;
d57a3c85
TJB
44#elif HAVE_LIBPYTHON2_5
45#include "python2.5/Python.h"
a6bac58e 46#include "python2.5/frameobject.h"
d57a3c85
TJB
47#elif HAVE_LIBPYTHON2_6
48#include "python2.6/Python.h"
a6bac58e 49#include "python2.6/frameobject.h"
d57a3c85
TJB
50#else
51#error "Unable to find usable Python.h"
52#endif
53
ca30a762
TT
54/* If Python.h does not define WITH_THREAD, then the various
55 GIL-related functions will not be defined. However,
56 PyGILState_STATE will be. */
57#ifndef WITH_THREAD
58#define PyGILState_Ensure() ((PyGILState_STATE) 0)
548a926a 59#define PyGILState_Release(ARG) ((void)(ARG))
ca30a762 60#define PyEval_InitThreads() 0
548a926a 61#define PyThreadState_Swap(ARG) ((void)(ARG))
ca30a762 62#define PyEval_InitThreads() 0
f2f35b75 63#define PyEval_ReleaseLock() 0
ca30a762
TT
64#endif
65
9cb74f47
PM
66/* In order to be able to parse symtab_and_line_to_sal_object function
67 a real symtab_and_line structure is needed. */
68#include "symtab.h"
69
f3e9a817 70struct block;
a08702d6 71struct value;
d452c4bc 72struct language_defn;
fa33c3cd 73struct program_space;
d57a3c85
TJB
74
75extern PyObject *gdb_module;
a08702d6 76extern PyTypeObject value_object_type;
f3e9a817
PM
77extern PyTypeObject block_object_type;
78extern PyTypeObject symbol_object_type;
a08702d6 79
8a1ea21f
DE
80extern struct cmd_list_element *set_python_list;
81extern struct cmd_list_element *show_python_list;
82
08c637de 83PyObject *gdbpy_history (PyObject *self, PyObject *args);
adc36818 84PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
f8f6f20b 85PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
f3e9a817 86PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw);
f8f6f20b 87PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args);
f3e9a817 88PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
2c74e833 89PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw);
be759fcf
PM
90PyObject *gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
91 const char *encoding, struct type *type);
adc36818 92PyObject *gdbpy_get_hook_function (const char *);
a08702d6 93
f3e9a817
PM
94PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
95PyObject *symtab_to_symtab_object (struct symtab *symtab);
96PyObject *symbol_to_symbol_object (struct symbol *sym);
97PyObject *block_to_block_object (struct block *block, struct objfile *objfile);
a08702d6 98PyObject *value_to_value_object (struct value *v);
2c74e833 99PyObject *type_to_type_object (struct type *);
89c73ade 100
fa33c3cd
DE
101PyObject *pspace_to_pspace_object (struct program_space *);
102PyObject *pspy_get_printers (PyObject *, void *);
103
104PyObject *objfile_to_objfile_object (struct objfile *);
89c73ade 105PyObject *objfpy_get_printers (PyObject *, void *);
a08702d6 106
f3e9a817
PM
107struct block *block_object_to_block (PyObject *obj);
108struct symbol *symbol_object_to_symbol (PyObject *obj);
a6bac58e 109struct value *value_object_to_value (PyObject *self);
a08702d6 110struct value *convert_value_from_python (PyObject *obj);
2c74e833 111struct type *type_object_to_type (PyObject *obj);
f3e9a817
PM
112struct symtab *symtab_object_to_symtab (PyObject *obj);
113struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj);
a08702d6 114
8a1ea21f 115void gdbpy_initialize_auto_load (void);
a08702d6 116void gdbpy_initialize_values (void);
f8f6f20b 117void gdbpy_initialize_frames (void);
f3e9a817 118void gdbpy_initialize_symtabs (void);
d8906c6f 119void gdbpy_initialize_commands (void);
f3e9a817
PM
120void gdbpy_initialize_symbols (void);
121void gdbpy_initialize_symtabs (void);
122void gdbpy_initialize_blocks (void);
2c74e833 123void gdbpy_initialize_types (void);
bc3b79fd 124void gdbpy_initialize_functions (void);
fa33c3cd 125void gdbpy_initialize_pspace (void);
89c73ade 126void gdbpy_initialize_objfile (void);
adc36818 127void gdbpy_initialize_breakpoints (void);
be759fcf 128void gdbpy_initialize_lazy_string (void);
d57a3c85
TJB
129
130struct cleanup *make_cleanup_py_decref (PyObject *py);
d452c4bc
UW
131
132struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
133 const struct language_defn *language);
134
135extern struct gdbarch *python_gdbarch;
136extern const struct language_defn *python_language;
d57a3c85
TJB
137
138/* Use this after a TRY_EXCEPT to throw the appropriate Python
139 exception. */
140#define GDB_PY_HANDLE_EXCEPTION(Exception) \
141 do { \
142 if (Exception.reason < 0) \
143 return PyErr_Format (Exception.reason == RETURN_QUIT \
144 ? PyExc_KeyboardInterrupt : PyExc_RuntimeError, \
145 "%s", Exception.message); \
146 } while (0)
147
adc36818
PM
148/* Use this after a TRY_EXCEPT to throw the appropriate Python
149 exception. This macro is for use inside setter functions. */
150#define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
151 do { \
152 if (Exception.reason < 0) \
153 { \
154 PyErr_Format (Exception.reason == RETURN_QUIT \
155 ? PyExc_KeyboardInterrupt : PyExc_RuntimeError, \
156 "%s", Exception.message); \
157 return -1; \
158 } \
159 } while (0)
d57a3c85
TJB
160
161void gdbpy_print_stack (void);
162
8a1ea21f
DE
163void source_python_script_for_objfile (struct objfile *objfile,
164 FILE *stream, const char *file);
165
d57a3c85
TJB
166PyObject *python_string_to_unicode (PyObject *obj);
167char *unicode_to_target_string (PyObject *unicode_str);
168char *python_string_to_target_string (PyObject *obj);
fbb8f299 169PyObject *python_string_to_target_python_string (PyObject *obj);
08c637de 170char *python_string_to_host_string (PyObject *obj);
b6cb8e7d 171PyObject *target_string_to_unicode (const gdb_byte *str, int length);
08c637de 172int gdbpy_is_string (PyObject *obj);
be759fcf
PM
173int gdbpy_is_lazy_string (PyObject *result);
174gdb_byte *gdbpy_extract_lazy_string (PyObject *string,
175 struct type **str_type,
176 long *length, char **encoding);
d57a3c85 177
b6313243
TT
178/* Note that these are declared here, and not in python.h with the
179 other pretty-printer functions, because they refer to PyObject. */
fbb8f299
PM
180PyObject *apply_varobj_pretty_printer (PyObject *print_obj,
181 struct value **replacement);
b6313243
TT
182PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
183char *gdbpy_get_display_hint (PyObject *printer);
184PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);
185
d8906c6f 186extern PyObject *gdbpy_doc_cst;
a6bac58e
TT
187extern PyObject *gdbpy_children_cst;
188extern PyObject *gdbpy_to_string_cst;
189extern PyObject *gdbpy_display_hint_cst;
d8906c6f 190
d57a3c85 191#endif /* GDB_PYTHON_INTERNAL_H */
This page took 0.207304 seconds and 4 git commands to generate.