20#ifndef PYTHON_PYTHON_INTERNAL_H
21#define PYTHON_PYTHON_INTERNAL_H
34#ifdef WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE
35#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG) \
36 __attribute__ ((cpychecker_type_object_for_typedef (ARG)))
38#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
41#ifdef WITH_CPYCHECKER_SETS_EXCEPTION_ATTRIBUTE
42#define CPYCHECKER_SETS_EXCEPTION __attribute__ ((cpychecker_sets_exception))
44#define CPYCHECKER_SETS_EXCEPTION
47#ifdef WITH_CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION_ATTRIBUTE
48#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION \
49 __attribute__ ((cpychecker_negative_result_sets_exception))
51#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
67#undef _FILE_OFFSET_BITS
70#if defined(_WIN32) && defined(HAVE_DECL_SNPRINTF)
71#define HAVE_SNPRINTF 1
81#define PY_SSIZE_T_CLEAN
87#include <frameobject.h>
90#define Py_TPFLAGS_CHECKTYPES 0
96#define PyGILState_Ensure() ((PyGILState_STATE) 0)
97#define PyGILState_Release(ARG) ((void)(ARG))
98#define PyEval_InitThreads()
99#define PyThreadState_Swap(ARG) ((void)(ARG))
100#define PyEval_ReleaseLock()
108#define GDB_PY_LL_ARG "L"
109#define GDB_PY_LLU_ARG "K"
112#define gdb_py_long_as_ulongest PyLong_AsUnsignedLongLong
113#define gdb_py_long_as_long_and_overflow PyLong_AsLongLongAndOverflow
117#define GDB_PY_LL_ARG "L"
118#define GDB_PY_LLU_ARG "K"
121#define gdb_py_long_as_ulongest PyLong_AsUnsignedLong
122#define gdb_py_long_as_long_and_overflow PyLong_AsLongAndOverflow
126#if PY_VERSION_HEX < 0x03020000
133#if PY_VERSION_HEX < 0x03040000
134#define PyMem_RawMalloc PyMem_Malloc
144template<
typename... Args>
150 const_cast<char *
> (method),
151 const_cast<char *
> (format),
155#undef PyObject_CallMethod
156#define PyObject_CallMethod gdb_PyObject_CallMethod
168#define PyErr_NewException gdb_PyErr_NewException
180#define PySys_GetObject gdb_PySys_GetObject
184#if PY_VERSION_HEX < 0x030a0000
190# define GDB_PYSYS_SETPATH_CHAR wchar_t
198#define PySys_SetPath gdb_PySys_SetPath
213 const char *doc_,
void *closure_)
214 : PyGetSetDef {const_cast<char *> (name_), get_, set_,
215 const_cast<char *> (doc_), closure_}
245 const char *format,
const char **keywords, ...)
250 va_start (ap, keywords);
251 res = PyArg_VaParseTupleAndKeywords (args, kw, format,
252 const_cast<char **
> (keywords),
324#define BPPY_REQUIRE_VALID(Breakpoint) \
326 if ((Breakpoint)->bp == NULL) \
327 return PyErr_Format (PyExc_RuntimeError, \
328 _("Breakpoint %d is invalid."), \
329 (Breakpoint)->number); \
334#define BPPY_SET_REQUIRE_VALID(Breakpoint) \
336 if ((Breakpoint)->bp == NULL) \
338 PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
339 (Breakpoint)->number); \
378 struct ui_file *stream,
int recurse,
385 struct ui_out *out,
int frame_low,
int frame_high);
388 htab_t copied_types);
396 struct type *obj_type,
const char *method_name,
397 std::vector<xmethod_worker_up> *dm_vec);
422 const char *encoding,
462 const char *group_name);
470 CORE_ADDR address, ULONGEST length);
541 static std::vector<callback_pair_t> &
544 static std::vector<callback_pair_t> list;
580 if (getenv (
"GDB_REVERSE_INIT_FUNCTIONS") !=
nullptr)
585 if (p.first !=
nullptr && p.first () < 0)
598 if (p.second !=
nullptr)
607#define GDBPY_INITIALIZE_FILE(INIT, ...) \
608 static gdbpy_initialize_file \
609 CONCAT(gdbpy_initialize_file_obj_, __LINE__) (INIT, ##__VA_ARGS__)
623 PyErr_Fetch (&
error_type, &error_value, &error_traceback);
644 gdb::unique_xmalloc_ptr<char>
to_string ()
const;
740 :
m_save (PyEval_SaveThread ())
742 gdb_assert (
m_save !=
nullptr);
747 PyEval_RestoreThread (
m_save);
759#define GDB_PY_HANDLE_EXCEPTION(Exception) \
761 if (Exception.reason < 0) \
763 gdbpy_convert_exception (Exception); \
770#define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
772 if (Exception.reason < 0) \
774 gdbpy_convert_exception (Exception); \
806 struct
type **str_type,
808 gdb::unique_xmalloc_ptr<
char> *encoding);
815 struct
value **replacement,
869 void operator() (Py_buffer *b)
const
871 PyBuffer_Release (b);
896 PyObject *pyo_reg_id,
int *reg_num);
926 (gdb::unique_xmalloc_ptr<char> doc);
940 disassemble_info *info);
DISABLE_COPY_AND_ASSIGN(gdbpy_allow_threads)
gdbpy_enter_varobj(const struct varobj *var)
static struct gdbarch * python_gdbarch
const struct language_defn * m_language
gdb::optional< gdbpy_err_fetch > m_error
static struct gdbarch * get_gdbarch()
gdbpy_enter(struct gdbarch *gdbarch=nullptr, const struct language_defn *language=nullptr)
struct gdbarch * m_gdbarch
struct active_ext_lang_state * m_previous_active
DISABLE_COPY_AND_ASSIGN(gdbpy_enter)
bool type_matches(PyObject *type) const
gdbpy_ref m_error_traceback
gdb::unique_xmalloc_ptr< char > type_to_string() const
gdb::unique_xmalloc_ptr< char > to_string() const
gdbpy_initialize_file(gdbpy_initialize_file_ftype init, gdbpy_finalize_file_ftype fini=nullptr)
std::pair< gdbpy_initialize_file_ftype, gdbpy_finalize_file_ftype > callback_pair_t
void(*)(void) gdbpy_finalize_file_ftype
static std::vector< callback_pair_t > & callbacks()
static void finalize_all()
int(*)(void) gdbpy_initialize_file_ftype
static bool initialize_all()
static void ATTRIBUTE_PRINTF(1, 0)
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
PyTypeObject block_object_type
PyTypeObject breakpoint_object_type
PyTypeObject event_object_type
PyTypeObject frame_object_type
PyTypeObject thread_object_type
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
PyTypeObject symbol_object_type
PyTypeObject value_object_type
PyObject * gdbpy_buffer_to_membuf(gdb::unique_xmalloc_ptr< gdb_byte > buffer, CORE_ADDR address, ULONGEST length)
enum ext_lang_bp_stop gdbpy_breakpoint_cond_says_stop(const struct extension_language_defn *, struct breakpoint *)
void gdbpy_print_stack(void)
bool gdbpy_is_progspace(PyObject *obj)
void gdbpy_ref python_string_to_unicode(PyObject *obj)
PyObject * gdbpy_new_register_descriptor_iterator(struct gdbarch *gdbarch, const char *group_name)
PyMODINIT_FUNC gdbpy_events_mod_func()
struct value * convert_value_from_python(PyObject *obj)
PyObject * gdbpy_all_architecture_names(PyObject *self, PyObject *args)
struct symbol * symbol_object_to_symbol(PyObject *obj)
bool gdbpy_breakpoint_init_breakpoint_type()
gdbpy_ref host_string_to_python_string(const char *str)
PyObject * symtab_to_linetable_object(PyObject *symtab)
PyObject * block_to_block_object(const struct block *block, struct objfile *objfile)
#define GDB_PYSYS_SETPATH_CHAR
PyObject * objfpy_get_xmethods(PyObject *, void *)
PyObject * pspy_get_printers(PyObject *, void *)
void gdbpy_convert_exception(const struct gdb_exception &) CPYCHECKER_SETS_EXCEPTION
gdb::unique_xmalloc_ptr< char > gdbpy_fix_doc_string_indentation(gdb::unique_xmalloc_ptr< char > doc)
#define PyObject_CallMethod
int gdbpy_breakpoint_has_cond(const struct extension_language_defn *, struct breakpoint *b)
struct symtab * symtab_object_to_symtab(PyObject *obj)
gdbpy_ref< inferior_object > inferior_to_inferior_object(inferior *inf)
void gdbpy_handle_exception() ATTRIBUTE_NORETURN
int gdbpy_print_python_errors_p(void)
gdb::unique_xmalloc_ptr< char > python_string_to_target_string(PyObject *obj)
gdbpy_ref apply_varobj_pretty_printer(PyObject *print_obj, struct value **replacement, struct ui_file *stream, const value_print_options *opts)
PyObject * symbol_to_symbol_object(struct symbol *sym)
enum ext_lang_rc gdbpy_get_matching_xmethod_workers(const struct extension_language_defn *extlang, struct type *obj_type, const char *method_name, std::vector< xmethod_worker_up > *dm_vec)
std::unique_ptr< Py_buffer, Py_buffer_deleter > Py_buffer_up
int gdbpy_is_value_object(PyObject *obj)
PyObject * gdbpy_lookup_static_symbol(PyObject *self, PyObject *args, PyObject *kw)
struct symtab_and_line * sal_object_to_symtab_and_line(PyObject *obj)
int gdb_python_initialized
PyObject * gdbpy_stop_recording(PyObject *self, PyObject *args)
PyObject * gdbpy_lookup_global_symbol(PyObject *self, PyObject *args, PyObject *kw)
gdbpy_ref gdb_py_object_from_longest(LONGEST l)
PyObject * gdbpy_register_tui_window(PyObject *self, PyObject *args, PyObject *kw)
frame_info_ptr frame_object_to_frame_info(PyObject *frame_obj)
std::unique_ptr< varobj_iter > py_varobj_get_iterator(struct varobj *var, PyObject *printer, const value_print_options *opts)
PyObject * gdbpy_lookup_objfile(PyObject *self, PyObject *args, PyObject *kw)
PyObject * gdbpy_execute_mi_command(PyObject *self, PyObject *args, PyObject *kw)
PyObject * pspy_get_xmethods(PyObject *, void *)
gdbpy_ref objfile_to_objfile_object(struct objfile *)
void bpfinishpy_post_stop_hook(struct gdbpy_breakpoint_object *bp_obj)
PyObject * symtab_to_symtab_object(struct symtab *symtab)
gdb::unique_xmalloc_ptr< char > gdbpy_parse_command_name(const char *name, struct cmd_list_element ***base_list, struct cmd_list_element **start_list)
PyObject * symtab_and_line_to_sal_object(struct symtab_and_line sal)
struct cmd_list_element * show_python_list
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
struct value * value_object_to_value(PyObject *self)
PyObject * gdbpy_children_cst
PyObject * frame_info_to_frame_object(frame_info_ptr frame)
void gdbpy_extract_lazy_string(PyObject *string, CORE_ADDR *addr, struct type **str_type, long *length, gdb::unique_xmalloc_ptr< char > *encoding)
void gdbpy_print_stack_or_quit()
int gdbpy_is_lazy_string(PyObject *result)
PyObject * gdbpy_add_history(PyObject *self, PyObject *args)
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_create_lazy_string_object(CORE_ADDR address, long length, const char *encoding, struct type *type)
gdb::unique_xmalloc_ptr< char > gdbpy_get_display_hint(PyObject *printer)
PyObject * gdbpy_string_to_argv(PyObject *self, PyObject *args)
PyObject * gdbpy_selected_inferior(PyObject *self, PyObject *args)
#define CPYCHECKER_SETS_EXCEPTION
void bpfinishpy_pre_delete_hook(struct gdbpy_breakpoint_object *bp_obj)
PyObject * gdbpy_default_visualizer(PyObject *self, PyObject *args)
bool gdbpy_is_architecture(PyObject *obj)
PyObject * gdbpy_selected_frame(PyObject *self, PyObject *args)
gdb::unique_xmalloc_ptr< char > gdbpy_obj_to_string(PyObject *obj)
PyObject * gdbpy_history_count(PyObject *self, PyObject *args)
PyObject * gdbpy_gdb_memory_error
PyObject * gdbpy_display_hint_cst
unsigned long gdb_py_ulongest
PyObject * gdbpy_parameter_value(const setting &var)
PyObject * gdbpy_create_ptid_object(ptid_t ptid)
PyObject * gdbpy_start_recording(PyObject *self, PyObject *args)
PyObject * gdbpy_selected_thread(PyObject *self, PyObject *args)
PyObject * gdbpy_new_reggroup_iterator(struct gdbarch *gdbarch)
PyObject * objfpy_get_frame_filters(PyObject *, void *)
struct gdbarch * arch_object_to_gdbarch(PyObject *obj)
PyObject * gdbpy_lookup_symbol(PyObject *self, PyObject *args, PyObject *kw)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
void gdbpy_error(const char *fmt,...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF(1
gdbpy_ref target_to_connection_object(process_stratum_target *target)
PyObject * gdbpy_newest_frame(PyObject *self, PyObject *args)
PyObject * gdbpy_history(PyObject *self, PyObject *args)
PyObject * objfpy_get_frame_unwinders(PyObject *, void *)
PyObject * gdbpy_set_convenience_variable(PyObject *self, PyObject *args)
PyObject * gdbpy_gdb_error
PyObject * gdbpy_current_recording(PyObject *self, PyObject *args)
gdbpy_breakpoint_object * bppy_pending_object
int gdb_py_int_as_long(PyObject *, long *)
void gdbpy_preserve_values(const struct extension_language_defn *, struct objfile *objfile, htab_t copied_types)
enum ext_lang_rc gdbpy_apply_val_pretty_printer(const struct extension_language_defn *, struct value *value, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
PyObject * value_to_value_object(struct value *v)
gdbpy_ref pspace_to_pspace_object(struct program_space *)
PyObject * gdbpy_enabled_cst
PyObject * pspy_get_frame_unwinders(PyObject *, void *)
PyObject * gdbpy_lookup_static_symbols(PyObject *self, PyObject *args, PyObject *kw)
bool gdbpy_parse_register_id(struct gdbarch *gdbarch, PyObject *pyo_reg_id, int *reg_num)
PyObject * gdbpy_frame_stop_reason_string(PyObject *, PyObject *)
enum ext_lang_bt_status gdbpy_apply_frame_filter(const struct extension_language_defn *, frame_info_ptr frame, frame_filter_flags flags, enum ext_lang_frame_args args_type, struct ui_out *out, int frame_low, int frame_high)
gdbpy_ref thread_to_thread_object(thread_info *thr)
const struct block * block_object_to_block(PyObject *obj)
PyObject * gdbpy_print_options(PyObject *self, PyObject *args)
gdbpy_ref gdbpy_get_varobj_pretty_printer(struct value *value)
PyObject * pspy_get_frame_filters(PyObject *, void *)
PyObject * gdbpy_to_string_cst
int gdbpy_is_field(PyObject *obj)
PyObject * objfpy_get_printers(PyObject *, void *)
const struct value_print_options * gdbpy_current_print_options
gdbpy_ref python_string_to_target_python_string(PyObject *obj)
PyObject * gdb_python_module
PyObject * gdbpy_inferiors(PyObject *unused, PyObject *unused2)
struct program_space * progspace_object_to_program_space(PyObject *obj)
PyObject * gdb_py_generic_dict(PyObject *self, void *closure)
int get_addr_from_python(PyObject *obj, CORE_ADDR *addr) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbarch_to_arch_object(struct gdbarch *gdbarch)
PyObject * gdbpy_value_cst
gdb::optional< int > gdbpy_print_insn(struct gdbarch *gdbarch, CORE_ADDR address, disassemble_info *info)
int gdbpy_is_string(PyObject *obj)
PyObject * gdbpy_convenience_variable(PyObject *self, PyObject *args)
static PyObject * gdb_PySys_GetObject(const char *name)
#define PyErr_NewException
PyObject * type_to_type_object(struct type *)
gdbpy_ref< thread_object > create_thread_object(struct thread_info *tp)
struct type * type_object_to_type(PyObject *obj)
bool gdbpy_auto_load_enabled(const struct extension_language_defn *)
void bpfinishpy_pre_stop_hook(struct gdbpy_breakpoint_object *bp_obj)
static PyObject * gdb_PyObject_CallMethod(PyObject *o, const char *method, const char *format, Args... args)
PyObject * gdbpy_lookup_type(PyObject *self, PyObject *args, PyObject *kw)
PyObject * gdbpy_gdberror_exc
static void gdb_PySys_SetPath(const GDB_PYSYS_SETPATH_CHAR *path)
gdbpy_ref gdb_py_object_from_ulongest(ULONGEST l)
static PyObject * gdb_PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
struct cmd_list_element * set_python_list
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
gdb::unique_xmalloc_ptr< char > unicode_to_target_string(PyObject *unicode_str)
PyObject * gdbpy_connections(PyObject *self, PyObject *args)
PyObject * gdbpy_breakpoints(PyObject *, PyObject *)
void gdbpy_get_print_options(value_print_options *opts)
static struct type * error_type(const char **, struct objfile *)
gdb::optional< setting > var
constexpr gdb_PyGetSetDef(std::nullptr_t)
constexpr gdb_PyGetSetDef(const char *name_, getter get_, setter set_, const char *doc_, void *closure_)
constexpr gdb_PyGetSetDef(const char *name_, getter get_, setter set_, const char *doc_)
PyObject_HEAD struct thread_info * thread