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
116#define GDB_PY_LL_ARG "L"
117#define GDB_PY_LLU_ARG "K"
120#define gdb_py_long_as_ulongest PyLong_AsUnsignedLong
124#if PY_VERSION_HEX < 0x03020000
131#if PY_VERSION_HEX < 0x03040000
132#define PyMem_RawMalloc PyMem_Malloc
142template<
typename... Args>
143static inline PyObject *
148 const_cast<char *
> (method),
149 const_cast<char *
> (format),
153#undef PyObject_CallMethod
154#define PyObject_CallMethod gdb_PyObject_CallMethod
160static inline PyObject*
166#define PyErr_NewException gdb_PyErr_NewException
172static inline PyObject *
178#define PySys_GetObject gdb_PySys_GetObject
182#if PY_VERSION_HEX < 0x030a0000
188# define GDB_PYSYS_SETPATH_CHAR wchar_t
196#define PySys_SetPath gdb_PySys_SetPath
211 const char *doc_,
void *closure_)
212 : PyGetSetDef {const_cast<char *> (name_), get_, set_,
213 const_cast<char *> (doc_), closure_}
243 const char *format,
const char **keywords, ...)
248 va_start (ap, keywords);
249 res = PyArg_VaParseTupleAndKeywords (args, kw, format,
250 const_cast<char **
> (keywords),
322#define BPPY_REQUIRE_VALID(Breakpoint) \
324 if ((Breakpoint)->bp == NULL) \
325 return PyErr_Format (PyExc_RuntimeError, \
326 _("Breakpoint %d is invalid."), \
327 (Breakpoint)->number); \
332#define BPPY_SET_REQUIRE_VALID(Breakpoint) \
334 if ((Breakpoint)->bp == NULL) \
336 PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
337 (Breakpoint)->number); \
376 struct ui_file *stream,
int recurse,
383 struct ui_out *out,
int frame_low,
int frame_high);
386 htab_t copied_types);
394 struct type *obj_type,
const char *method_name,
395 std::vector<xmethod_worker_up> *dm_vec);
420 const char *encoding,
461 const char *group_name);
469 CORE_ADDR address, ULONGEST length);
573 PyObject *
error_type, *error_value, *error_traceback;
575 PyErr_Fetch (&
error_type, &error_value, &error_traceback);
577 m_error_value.reset (error_value);
578 m_error_traceback.reset (error_traceback);
587 PyErr_Restore (m_error_type.release (),
588 m_error_value.release (),
589 m_error_traceback.release ());
596 gdb::unique_xmalloc_ptr<char> to_string ()
const;
608 return PyErr_GivenExceptionMatches (m_error_type.get (),
type);
615 return m_error_value;
692 :
m_save (PyEval_SaveThread ())
694 gdb_assert (
m_save !=
nullptr);
699 PyEval_RestoreThread (
m_save);
711#define GDB_PY_HANDLE_EXCEPTION(Exception) \
713 if (Exception.reason < 0) \
715 gdbpy_convert_exception (Exception); \
722#define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
724 if (Exception.reason < 0) \
726 gdbpy_convert_exception (Exception); \
758 struct
type **str_type,
760 gdb::unique_xmalloc_ptr<
char> *encoding);
767 struct
value **replacement,
820 void operator() (Py_buffer *b)
const
822 PyBuffer_Release (b);
847 PyObject *pyo_reg_id,
int *reg_num);
877 (gdb::unique_xmalloc_ptr<char> doc);
891 disassemble_info *info);
DISABLE_COPY_AND_ASSIGN(gdbpy_allow_threads)
const struct language_defn * m_language
gdb::optional< gdbpy_err_fetch > m_error
struct gdbarch * m_gdbarch
static struct gdbarch * python_gdbarch
struct active_ext_lang_state * m_previous_active
DISABLE_COPY_AND_ASSIGN(gdbpy_enter)
static struct gdbarch * get_gdbarch()
bool type_matches(PyObject *type) const
gdbpy_ref m_error_traceback
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)
int gdbpy_initialize_functions(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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)
int gdbpy_initialize_breakpoints(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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)
int gdbpy_initialize_blocks(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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)
void gdbpy_initialize_gdb_readline(void)
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)
int gdbpy_initialize_unwind(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_disasm() CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_types(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
struct symtab_and_line * sal_object_to_symtab_and_line(PyObject *obj)
int gdb_python_initialized
PyObject * gdbpy_stop_recording(PyObject *self, PyObject *args)
int gdbpy_initialize_micommands(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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 * 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)
int gdbpy_initialize_objfile(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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
int gdbpy_initialize_registers() CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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)
int gdbpy_initialize_finishbreakpoints(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_instruction(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
#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)
int gdbpy_initialize_xmethods(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
#define CPYCHECKER_SETS_EXCEPTION
int gdbpy_initialize_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_record(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_default_visualizer(PyObject *self, PyObject *args)
int gdbpy_initialize_auto_load(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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
int gdbpy_initialize_pspace(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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)
int gdbpy_initialize_parameters(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_gdb_error
PyObject * value_to_value_object_no_release(struct value *v)
PyObject * gdbpy_current_recording(PyObject *self, PyObject *args)
int gdbpy_initialize_symbols(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_thread(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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 *)
int gdbpy_initialize_linetable(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_enabled_cst
PyObject * pspy_get_frame_unwinders(PyObject *, void *)
int gdbpy_initialize_arch(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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)
int gdbpy_initialize_membuf() CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
const struct block * block_object_to_block(PyObject *obj)
PyObject * gdbpy_print_options(PyObject *self, PyObject *args)
int gdbpy_initialize_symtabs(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_ref gdbpy_get_varobj_pretty_printer(struct value *value)
int gdbpy_initialize_frames(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * pspy_get_frame_filters(PyObject *, void *)
int gdbpy_initialize_inferior(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_to_string_cst
int gdbpy_is_field(PyObject *obj)
PyObject * objfpy_get_printers(PyObject *, void *)
int gdbpy_initialize_connection() CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
const struct value_print_options * gdbpy_current_print_options
gdbpy_ref python_string_to_target_python_string(PyObject *obj)
PyObject * gdb_python_module
int gdbpy_initialize_eventregistry(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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)
int gdbpy_initialize_values(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
#define PyErr_NewException
PyObject * type_to_type_object(struct type *)
int gdbpy_initialize_commands(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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)
int gdbpy_initialize_tui() CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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)
int gdbpy_initialize_btrace(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_gdberror_exc
int gdbpy_initialize_lazy_string(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
static void gdb_PySys_SetPath(const GDB_PYSYS_SETPATH_CHAR *path)
int gdbpy_initialize_breakpoint_locations() CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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)
void gdbpy_finalize_micommands()
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
std::string type_to_string(struct type *type)