gdb/python/python-internal.h - gdb

Data types defined

Functions defined

Macros defined

Source code

  1. /* Gdb/Python header for private use by Python module.

  2.    Copyright (C) 2008-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #ifndef GDB_PYTHON_INTERNAL_H
  15. #define GDB_PYTHON_INTERNAL_H

  16. #include "extension.h"

  17. /* These WITH_* macros are defined by the CPython API checker that
  18.    comes with the Python plugin for GCC.  See:
  19.    https://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html
  20.    The checker defines a WITH_ macro for each attribute it
  21.    exposes.  */

  22. #ifdef WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE
  23. #define CPYCHECKER_RETURNS_BORROWED_REF                        \
  24.   __attribute__ ((cpychecker_returns_borrowed_ref))
  25. #else
  26. #define CPYCHECKER_RETURNS_BORROWED_REF
  27. #endif

  28. #ifdef WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE
  29. #define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)                \
  30.   __attribute__ ((cpychecker_type_object_for_typedef (ARG)))
  31. #else
  32. #define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
  33. #endif

  34. #ifdef WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE
  35. #define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n) \
  36.    __attribute__ ((cpychecker_steals_reference_to_arg (n)))
  37. #else
  38. #define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n)
  39. #endif

  40. #ifdef WITH_CPYCHECKER_SETS_EXCEPTION_ATTRIBUTE
  41. #define CPYCHECKER_SETS_EXCEPTION __attribute__ ((cpychecker_sets_exception))
  42. #else
  43. #define CPYCHECKER_SETS_EXCEPTION
  44. #endif

  45. #ifdef WITH_CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION_ATTRIBUTE
  46. #define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION                \
  47.   __attribute__ ((cpychecker_negative_result_sets_exception))
  48. #else
  49. #define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
  50. #endif

  51. /* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t
  52.    needed by pyport.h.  */
  53. #include <stdint.h>

  54. /* /usr/include/features.h on linux systems will define _POSIX_C_SOURCE
  55.    if it sees _GNU_SOURCE (which config.h will define).
  56.    pyconfig.h defines _POSIX_C_SOURCE to a different value than
  57.    /usr/include/features.h does causing compilation to fail.
  58.    To work around this, undef _POSIX_C_SOURCE before we include Python.h.

  59.    Same problem with _XOPEN_SOURCE.  */
  60. #undef _POSIX_C_SOURCE
  61. #undef _XOPEN_SOURCE

  62. /* On sparc-solaris, /usr/include/sys/feature_tests.h defines
  63.    _FILE_OFFSET_BITS, which pyconfig.h also defines.  Same work
  64.    around technique as above.  */
  65. #undef _FILE_OFFSET_BITS

  66. /* A kludge to avoid redefinition of snprintf on Windows by pyerrors.h.  */
  67. #if defined(_WIN32) && defined(HAVE_DECL_SNPRINTF)
  68. #define HAVE_SNPRINTF 1
  69. #endif

  70. /* Request clean size types from Python.  */
  71. #define PY_SSIZE_T_CLEAN

  72. /* Include the Python header files using angle brackets rather than
  73.    double quotes.  On case-insensitive filesystems, this prevents us
  74.    from including our python/python.h header file.  */
  75. #include <Python.h>
  76. #include <frameobject.h>

  77. #if PY_MAJOR_VERSION >= 3
  78. #define IS_PY3K 1
  79. #endif

  80. #ifdef IS_PY3K
  81. #define Py_TPFLAGS_HAVE_ITER 0
  82. #define Py_TPFLAGS_CHECKTYPES 0

  83. #define PyInt_Check PyLong_Check
  84. #define PyInt_FromLong PyLong_FromLong
  85. #define PyInt_AsLong PyLong_AsLong

  86. #define PyString_FromString PyUnicode_FromString
  87. #define PyString_Decode PyUnicode_Decode
  88. #define PyString_FromFormat PyUnicode_FromFormat
  89. #define PyString_Check PyUnicode_Check
  90. #endif

  91. #if HAVE_LIBPYTHON2_4
  92. /* Py_ssize_t is not defined until 2.5.
  93.    Logical type for Py_ssize_t is Py_intptr_t, but that fails in 64-bit
  94.    compilation due to several apparent mistakes in python2.4 API, so we
  95.    use 'int' instead.  */
  96. typedef int Py_ssize_t;
  97. #endif

  98. #ifndef PyVarObject_HEAD_INIT
  99. /* Python 2.4 does not define PyVarObject_HEAD_INIT.  */
  100. #define PyVarObject_HEAD_INIT(type, size)       \
  101.     PyObject_HEAD_INIT(type) size,

  102. #endif

  103. #ifndef Py_TYPE
  104. /* Python 2.4 does not define Py_TYPE.  */
  105. #define Py_TYPE(ob)             (((PyObject*)(ob))->ob_type)
  106. #endif

  107. /* If Python.h does not define WITH_THREAD, then the various
  108.    GIL-related functions will not be defined.  However,
  109.    PyGILState_STATE will be.  */
  110. #ifndef WITH_THREAD
  111. #define PyGILState_Ensure() ((PyGILState_STATE) 0)
  112. #define PyGILState_Release(ARG) ((void)(ARG))
  113. #define PyEval_InitThreads()
  114. #define PyThreadState_Swap(ARG) ((void)(ARG))
  115. #define PyEval_ReleaseLock()
  116. #endif

  117. /* Python supplies HAVE_LONG_LONG and some `long long' support when it
  118.    is available.  These defines let us handle the differences more
  119.    cleanly.  */
  120. #ifdef HAVE_LONG_LONG

  121. #define GDB_PY_LL_ARG "L"
  122. #define GDB_PY_LLU_ARG "K"
  123. typedef PY_LONG_LONG gdb_py_longest;
  124. typedef unsigned PY_LONG_LONG gdb_py_ulongest;
  125. #define gdb_py_long_from_longest PyLong_FromLongLong
  126. #define gdb_py_long_from_ulongest PyLong_FromUnsignedLongLong
  127. #define gdb_py_long_as_ulongest PyLong_AsUnsignedLongLong

  128. #else /* HAVE_LONG_LONG */

  129. #define GDB_PY_LL_ARG "L"
  130. #define GDB_PY_LLU_ARG "K"
  131. typedef long gdb_py_longest;
  132. typedef unsigned long gdb_py_ulongest;
  133. #define gdb_py_long_from_longest PyLong_FromLong
  134. #define gdb_py_long_from_ulongest PyLong_FromUnsignedLong
  135. #define gdb_py_long_as_ulongest PyLong_AsUnsignedLong

  136. #endif /* HAVE_LONG_LONG */

  137. /* Python 2.6 did not wrap Py_DECREF in 'do {...} while (0)', leading
  138.    to 'suggest explicit braces to avoid ambiguous ‘else’' gcc errors.
  139.    Wrap it ourselves, so that callers don't need to care.  */

  140. static inline void
  141. gdb_Py_DECREF (void *op) /* ARI: editCase function */
  142. {
  143.   /* ... and Python 2.4 didn't cast OP to PyObject pointer on the
  144.      '(op)->ob_refcnt' references within the macro.  Cast it ourselves
  145.      too.  */
  146.   Py_DECREF ((PyObject *) op);
  147. }

  148. #undef Py_DECREF
  149. #define Py_DECREF(op) gdb_Py_DECREF (op)

  150. /* The second argument to PyObject_GetAttrString was missing the 'const'
  151.    qualifier in Python-2.4.  Hence, we wrap it in a function to avoid errors
  152.    when compiled with -Werror.  */

  153. static inline PyObject *
  154. gdb_PyObject_GetAttrString (PyObject *obj,
  155.                             const char *attr) /* ARI: editCase function */
  156. {
  157.   return PyObject_GetAttrString (obj, (char *) attr);
  158. }

  159. #define PyObject_GetAttrString(obj, attr) gdb_PyObject_GetAttrString (obj, attr)

  160. /* The second argument to PyObject_HasAttrString was also missing the 'const'
  161.    qualifier in Python-2.4.  Hence, we wrap it also in a function to avoid
  162.    errors when compiled with -Werror.  */

  163. static inline int
  164. gdb_PyObject_HasAttrString (PyObject *obj,
  165.                             const char *attr/* ARI: editCase function */
  166. {
  167.   return PyObject_HasAttrString (obj, (char *) attr);
  168. }

  169. #define PyObject_HasAttrString(obj, attr) gdb_PyObject_HasAttrString (obj, attr)

  170. /* In order to be able to parse symtab_and_line_to_sal_object function
  171.    a real symtab_and_line structure is needed.  */
  172. #include "symtab.h"

  173. /* Also needed to parse enum var_types. */
  174. #include "command.h"
  175. #include "breakpoint.h"

  176. enum gdbpy_iter_kind { iter_keys, iter_values, iter_items };

  177. struct block;
  178. struct value;
  179. struct language_defn;
  180. struct program_space;
  181. struct bpstats;
  182. struct inferior;

  183. extern int gdb_python_initialized;

  184. extern PyObject *gdb_module;
  185. extern PyObject *gdb_python_module;
  186. extern PyTypeObject value_object_type
  187.     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("value_object");
  188. extern PyTypeObject block_object_type
  189.     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("block_object");
  190. extern PyTypeObject symbol_object_type
  191.     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symbol_object");
  192. extern PyTypeObject event_object_type
  193.     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
  194. extern PyTypeObject stop_event_object_type
  195.     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
  196. extern PyTypeObject breakpoint_object_type
  197.     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("breakpoint_object");
  198. extern PyTypeObject frame_object_type
  199.     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("frame_object");

  200. typedef struct gdbpy_breakpoint_object
  201. {
  202.   PyObject_HEAD

  203.   /* The breakpoint number according to gdb.  */
  204.   int number;

  205.   /* The gdb breakpoint object, or NULL if the breakpoint has been
  206.      deleted.  */
  207.   struct breakpoint *bp;

  208.   /* 1 is this is a FinishBreakpoint object, 0 otherwise.  */
  209.   int is_finish_bp;
  210. } gdbpy_breakpoint_object;

  211. /* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
  212.    exception if it is invalid.  */
  213. #define BPPY_REQUIRE_VALID(Breakpoint)                                  \
  214.     do {                                                                \
  215.       if ((Breakpoint)->bp == NULL)                                     \
  216.         return PyErr_Format (PyExc_RuntimeError,                        \
  217.                              _("Breakpoint %d is invalid."),            \
  218.                              (Breakpoint)->number);                     \
  219.     } while (0)

  220. /* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
  221.    exception if it is invalid.  This macro is for use in setter functions.  */
  222. #define BPPY_SET_REQUIRE_VALID(Breakpoint)                              \
  223.     do {                                                                \
  224.       if ((Breakpoint)->bp == NULL)                                     \
  225.         {                                                               \
  226.           PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
  227.                         (Breakpoint)->number);                          \
  228.           return -1;                                                    \
  229.         }                                                               \
  230.     } while (0)


  231. /* Variables used to pass information between the Breakpoint
  232.    constructor and the breakpoint-created hook function.  */
  233. extern gdbpy_breakpoint_object *bppy_pending_object;


  234. typedef struct
  235. {
  236.   PyObject_HEAD

  237.   /* The thread we represent.  */
  238.   struct thread_info *thread;

  239.   /* The Inferior object to which this thread belongs.  */
  240.   PyObject *inf_obj;
  241. } thread_object;

  242. extern struct cmd_list_element *set_python_list;
  243. extern struct cmd_list_element *show_python_list;

  244. /* extension_language_script_ops "methods".  */

  245. extern int gdbpy_auto_load_enabled (const struct extension_language_defn *);

  246. /* extension_language_ops "methods".  */

  247. extern enum ext_lang_rc gdbpy_apply_val_pretty_printer
  248.   (const struct extension_language_defn *,
  249.    struct type *type, const gdb_byte *valaddr,
  250.    int embedded_offset, CORE_ADDR address,
  251.    struct ui_file *stream, int recurse,
  252.    const struct value *val,
  253.    const struct value_print_options *options,
  254.    const struct language_defn *language);
  255. extern enum ext_lang_bt_status gdbpy_apply_frame_filter
  256.   (const struct extension_language_defn *,
  257.    struct frame_info *frame, int flags, enum ext_lang_frame_args args_type,
  258.    struct ui_out *out, int frame_low, int frame_high);
  259. extern void gdbpy_preserve_values (const struct extension_language_defn *,
  260.                                    struct objfile *objfile,
  261.                                    htab_t copied_types);
  262. extern enum ext_lang_bp_stop gdbpy_breakpoint_cond_says_stop
  263.   (const struct extension_language_defn *, struct breakpoint *);
  264. extern int gdbpy_breakpoint_has_cond (const struct extension_language_defn *,
  265.                                       struct breakpoint *b);

  266. extern void *gdbpy_clone_xmethod_worker_data
  267.   (const struct extension_language_defn *extlang, void *data);
  268. extern void gdbpy_free_xmethod_worker_data
  269.   (const struct extension_language_defn *extlang, void *data);
  270. extern enum ext_lang_rc gdbpy_get_matching_xmethod_workers
  271.   (const struct extension_language_defn *extlang,
  272.    struct type *obj_type, const char *method_name,
  273.    xmethod_worker_vec **dm_vec);
  274. extern enum ext_lang_rc gdbpy_get_xmethod_arg_types
  275.   (const struct extension_language_defn *extlang,
  276.    struct xmethod_worker *worker,
  277.    int *nargs,
  278.    struct type ***arg_types);
  279. extern struct value *gdbpy_invoke_xmethod
  280.   (const struct extension_language_defn *extlang,
  281.    struct xmethod_worker *worker,
  282.    struct value *obj, struct value **args, int nargs);

  283. PyObject *gdbpy_history (PyObject *self, PyObject *args);
  284. PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
  285. PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
  286. PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw);
  287. PyObject *gdbpy_lookup_global_symbol (PyObject *self, PyObject *args,
  288.                                       PyObject *kw);
  289. PyObject *gdbpy_newest_frame (PyObject *self, PyObject *args);
  290. PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args);
  291. PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
  292. PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw);
  293. int gdbpy_is_field (PyObject *obj);
  294. PyObject *gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
  295.                                            const char *encoding,
  296.                                            struct type *type);
  297. PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2);
  298. PyObject *gdbpy_create_ptid_object (ptid_t ptid);
  299. PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args);
  300. PyObject *gdbpy_selected_inferior (PyObject *self, PyObject *args);
  301. PyObject *gdbpy_string_to_argv (PyObject *self, PyObject *args);
  302. PyObject *gdbpy_parameter (PyObject *self, PyObject *args);
  303. PyObject *gdbpy_parameter_value (enum var_types type, void *var);
  304. char *gdbpy_parse_command_name (const char *name,
  305.                                 struct cmd_list_element ***base_list,
  306.                                 struct cmd_list_element **start_list);

  307. PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
  308. PyObject *symtab_to_symtab_object (struct symtab *symtab);
  309. PyObject *symbol_to_symbol_object (struct symbol *sym);
  310. PyObject *block_to_block_object (const struct block *block,
  311.                                  struct objfile *objfile);
  312. PyObject *value_to_value_object (struct value *v);
  313. PyObject *type_to_type_object (struct type *);
  314. PyObject *frame_info_to_frame_object (struct frame_info *frame);
  315. PyObject *symtab_to_linetable_object (PyObject *symtab);
  316. PyObject *pspace_to_pspace_object (struct program_space *)
  317.     CPYCHECKER_RETURNS_BORROWED_REF;
  318. PyObject *pspy_get_printers (PyObject *, void *);
  319. PyObject *pspy_get_frame_filters (PyObject *, void *);
  320. PyObject *pspy_get_xmethods (PyObject *, void *);

  321. PyObject *objfile_to_objfile_object (struct objfile *)
  322.     CPYCHECKER_RETURNS_BORROWED_REF;
  323. PyObject *objfpy_get_printers (PyObject *, void *);
  324. PyObject *objfpy_get_frame_filters (PyObject *, void *);
  325. PyObject *objfpy_get_xmethods (PyObject *, void *);
  326. PyObject *gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw);

  327. PyObject *gdbarch_to_arch_object (struct gdbarch *gdbarch);

  328. thread_object *create_thread_object (struct thread_info *tp);
  329. thread_object *find_thread_object (ptid_t ptid)
  330.     CPYCHECKER_RETURNS_BORROWED_REF;
  331. PyObject *find_inferior_object (int pid);
  332. PyObject *inferior_to_inferior_object (struct inferior *inferior);

  333. const struct block *block_object_to_block (PyObject *obj);
  334. struct symbol *symbol_object_to_symbol (PyObject *obj);
  335. struct value *value_object_to_value (PyObject *self);
  336. struct value *convert_value_from_python (PyObject *obj);
  337. struct type *type_object_to_type (PyObject *obj);
  338. struct symtab *symtab_object_to_symtab (PyObject *obj);
  339. struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj);
  340. struct frame_info *frame_object_to_frame_info (PyObject *frame_obj);
  341. struct gdbarch *arch_object_to_gdbarch (PyObject *obj);

  342. void gdbpy_initialize_gdb_readline (void);
  343. int gdbpy_initialize_auto_load (void)
  344.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  345. int gdbpy_initialize_values (void)
  346.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  347. int gdbpy_initialize_frames (void)
  348.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  349. int gdbpy_initialize_symtabs (void)
  350.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  351. int gdbpy_initialize_commands (void)
  352.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  353. int gdbpy_initialize_symbols (void)
  354.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  355. int gdbpy_initialize_symtabs (void)
  356.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  357. int gdbpy_initialize_blocks (void)
  358.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  359. int gdbpy_initialize_types (void)
  360.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  361. int gdbpy_initialize_functions (void)
  362.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  363. int gdbpy_initialize_pspace (void)
  364.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  365. int gdbpy_initialize_objfile (void)
  366.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  367. int gdbpy_initialize_breakpoints (void)
  368.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  369. int gdbpy_initialize_finishbreakpoints (void)
  370.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  371. int gdbpy_initialize_lazy_string (void)
  372.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  373. int gdbpy_initialize_linetable (void)
  374.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  375. int gdbpy_initialize_parameters (void)
  376.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  377. int gdbpy_initialize_thread (void)
  378.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  379. int gdbpy_initialize_inferior (void)
  380.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  381. int gdbpy_initialize_eventregistry (void)
  382.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  383. int gdbpy_initialize_event (void)
  384.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  385. int gdbpy_initialize_py_events (void)
  386.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  387. int gdbpy_initialize_stop_event (void)
  388.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  389. int gdbpy_initialize_signal_event (void)
  390.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  391. int gdbpy_initialize_breakpoint_event (void)
  392.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  393. int gdbpy_initialize_continue_event (void)
  394.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  395. int gdbpy_initialize_inferior_call_pre_event (void)
  396.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  397. int gdbpy_initialize_inferior_call_post_event (void)
  398.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  399. int gdbpy_initialize_register_changed_event (void)
  400.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  401. int gdbpy_initialize_memory_changed_event (void)
  402.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  403. int gdbpy_initialize_exited_event (void)
  404.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  405. int gdbpy_initialize_thread_event (void)
  406.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  407. int gdbpy_initialize_new_objfile_event (void)
  408.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  409. int gdbpy_initialize_clear_objfiles_event (void)
  410.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  411. int gdbpy_initialize_arch (void)
  412.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
  413. int gdbpy_initialize_xmethods (void)
  414.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;

  415. struct cleanup *make_cleanup_py_decref (PyObject *py);
  416. struct cleanup *make_cleanup_py_xdecref (PyObject *py);

  417. struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
  418.                                    const struct language_defn *language);

  419. extern struct gdbarch *python_gdbarch;
  420. extern const struct language_defn *python_language;

  421. /* Use this after a TRY_EXCEPT to throw the appropriate Python
  422.    exception.  */
  423. #define GDB_PY_HANDLE_EXCEPTION(Exception)        \
  424.   do {                                                \
  425.     if (Exception.reason < 0)                        \
  426.       {                                                \
  427.         gdbpy_convert_exception (Exception);        \
  428.         return NULL;                                \
  429.       }                                                \
  430.   } while (0)

  431. /* Use this after a TRY_EXCEPT to throw the appropriate Python
  432.    exception.  This macro is for use inside setter functions.  */
  433. #define GDB_PY_SET_HANDLE_EXCEPTION(Exception)                                \
  434.     do {                                                                \
  435.       if (Exception.reason < 0)                                                \
  436.         {                                                                \
  437.           gdbpy_convert_exception (Exception);                                \
  438.           return -1;                                                        \
  439.         }                                                                \
  440.     } while (0)

  441. void gdbpy_print_stack (void);

  442. PyObject *python_string_to_unicode (PyObject *obj);
  443. char *unicode_to_target_string (PyObject *unicode_str);
  444. char *python_string_to_target_string (PyObject *obj);
  445. PyObject *python_string_to_target_python_string (PyObject *obj);
  446. char *python_string_to_host_string (PyObject *obj);
  447. int gdbpy_is_string (PyObject *obj);
  448. char *gdbpy_obj_to_string (PyObject *obj);
  449. char *gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue);

  450. int gdbpy_is_lazy_string (PyObject *result);
  451. void gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr,
  452.                                 struct type **str_type,
  453.                                 long *length, char **encoding);

  454. int gdbpy_is_value_object (PyObject *obj);

  455. /* Note that these are declared here, and not in python.h with the
  456.    other pretty-printer functions, because they refer to PyObject.  */
  457. PyObject *apply_varobj_pretty_printer (PyObject *print_obj,
  458.                                        struct value **replacement,
  459.                                        struct ui_file *stream);
  460. PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
  461. char *gdbpy_get_display_hint (PyObject *printer);
  462. PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);

  463. void bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj);
  464. void bpfinishpy_post_stop_hook (struct gdbpy_breakpoint_object *bp_obj);

  465. extern PyObject *gdbpy_doc_cst;
  466. extern PyObject *gdbpy_children_cst;
  467. extern PyObject *gdbpy_to_string_cst;
  468. extern PyObject *gdbpy_display_hint_cst;
  469. extern PyObject *gdbpy_enabled_cst;
  470. extern PyObject *gdbpy_value_cst;

  471. /* Exception types.  */
  472. extern PyObject *gdbpy_gdb_error;
  473. extern PyObject *gdbpy_gdb_memory_error;
  474. extern PyObject *gdbpy_gdberror_exc;

  475. extern void gdbpy_convert_exception (struct gdb_exception)
  476.     CPYCHECKER_SETS_EXCEPTION;

  477. int get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
  478.     CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;

  479. PyObject *gdb_py_object_from_longest (LONGEST l);
  480. PyObject *gdb_py_object_from_ulongest (ULONGEST l);
  481. int gdb_py_int_as_long (PyObject *, long *);

  482. PyObject *gdb_py_generic_dict (PyObject *self, void *closure);

  483. int gdb_pymodule_addobject (PyObject *module, const char *name,
  484.                             PyObject *object)
  485.   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;

  486. struct varobj_iter;
  487. struct varobj;
  488. struct varobj_iter *py_varobj_get_iterator (struct varobj *var,
  489.                                             PyObject *printer);

  490. #endif /* GDB_PYTHON_INTERNAL_H */