20 #ifndef GDB_PYTHON_INTERNAL_H 21 #define GDB_PYTHON_INTERNAL_H 32 #ifdef WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE 33 #define CPYCHECKER_RETURNS_BORROWED_REF \ 34 __attribute__ ((cpychecker_returns_borrowed_ref)) 36 #define CPYCHECKER_RETURNS_BORROWED_REF 39 #ifdef WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE 40 #define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG) \ 41 __attribute__ ((cpychecker_type_object_for_typedef (ARG))) 43 #define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG) 46 #ifdef WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE 47 #define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n) \ 48 __attribute__ ((cpychecker_steals_reference_to_arg (n))) 50 #define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n) 53 #ifdef WITH_CPYCHECKER_SETS_EXCEPTION_ATTRIBUTE 54 #define CPYCHECKER_SETS_EXCEPTION __attribute__ ((cpychecker_sets_exception)) 56 #define CPYCHECKER_SETS_EXCEPTION 59 #ifdef WITH_CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION_ATTRIBUTE 60 #define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION \ 61 __attribute__ ((cpychecker_negative_result_sets_exception)) 63 #define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION 75 #undef _POSIX_C_SOURCE 81 #undef _FILE_OFFSET_BITS 84 #if defined(_WIN32) && defined(HAVE_DECL_SNPRINTF) 85 #define HAVE_SNPRINTF 1 95 #define PY_SSIZE_T_CLEAN 101 #include <frameobject.h> 103 #if PY_MAJOR_VERSION >= 3 108 #define Py_TPFLAGS_HAVE_ITER 0 109 #define Py_TPFLAGS_CHECKTYPES 0 111 #define PyInt_Check PyLong_Check 112 #define PyInt_FromLong PyLong_FromLong 113 #define PyInt_FromSsize_t PyLong_FromSsize_t 114 #define PyInt_AsLong PyLong_AsLong 115 #define PyInt_AsSsize_t PyLong_AsSsize_t 117 #define PyString_FromString PyUnicode_FromString 118 #define PyString_Decode PyUnicode_Decode 119 #define PyString_FromFormat PyUnicode_FromFormat 120 #define PyString_Check PyUnicode_Check 123 #if HAVE_LIBPYTHON2_4 128 typedef int Py_ssize_t;
131 #ifndef PyVarObject_HEAD_INIT 133 #define PyVarObject_HEAD_INIT(type, size) \ 134 PyObject_HEAD_INIT(type) size, 140 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) 147 #define PyGILState_Ensure() ((PyGILState_STATE) 0) 148 #define PyGILState_Release(ARG) ((void)(ARG)) 149 #define PyEval_InitThreads() 150 #define PyThreadState_Swap(ARG) ((void)(ARG)) 151 #define PyEval_ReleaseLock() 157 #ifdef HAVE_LONG_LONG 159 #define GDB_PY_LL_ARG "L" 160 #define GDB_PY_LLU_ARG "K" 163 #define gdb_py_long_from_longest PyLong_FromLongLong 164 #define gdb_py_long_from_ulongest PyLong_FromUnsignedLongLong 165 #define gdb_py_long_as_ulongest PyLong_AsUnsignedLongLong 169 #define GDB_PY_LL_ARG "L" 170 #define GDB_PY_LLU_ARG "K" 173 #define gdb_py_long_from_longest PyLong_FromLong 174 #define gdb_py_long_from_ulongest PyLong_FromUnsignedLong 175 #define gdb_py_long_as_ulongest PyLong_AsUnsignedLong 179 #if PY_VERSION_HEX < 0x03020000 186 #if PY_VERSION_HEX < 0x03040000 187 #define PyMem_RawMalloc PyMem_Malloc 204 #define Py_DECREF(op) gdb_Py_DECREF (op) 210 static inline PyObject *
217 #define PyObject_GetAttrString(obj, attr) gdb_PyObject_GetAttrString (obj, attr) 230 #define PyObject_HasAttrString(obj, attr) gdb_PyObject_HasAttrString (obj, attr) 239 template<
typename... Args>
240 static inline PyObject *
245 const_cast<char *> (method),
246 const_cast<char *> (format),
250 #undef PyObject_CallMethod 251 #define PyObject_CallMethod gdb_PyObject_CallMethod 257 static inline PyObject*
263 #define PyErr_NewException gdb_PyErr_NewException 269 static inline PyObject *
275 #define PySys_GetObject gdb_PySys_GetObject 282 # define GDB_PYSYS_SETPATH_CHAR wchar_t 284 # define GDB_PYSYS_SETPATH_CHAR char 293 #define PySys_SetPath gdb_PySys_SetPath 307 const char *doc_,
void *closure_)
308 : PyGetSetDef {
const_cast<char *
> (name_), get_, set_,
309 const_cast<char *> (doc_), closure_}
339 const char *format,
const char **keywords, ...)
344 va_start (ap, keywords);
345 res = PyArg_VaParseTupleAndKeywords (args, kw, format,
346 const_cast<char **> (keywords),
406 #define BPPY_REQUIRE_VALID(Breakpoint) \ 408 if ((Breakpoint)->bp == NULL) \ 409 return PyErr_Format (PyExc_RuntimeError, \ 410 _("Breakpoint %d is invalid."), \ 411 (Breakpoint)->number); \ 416 #define BPPY_SET_REQUIRE_VALID(Breakpoint) \ 418 if ((Breakpoint)->bp == NULL) \ 420 PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \ 421 (Breakpoint)->number); \ 456 struct ui_file *stream,
int recurse,
463 struct ui_out *out,
int frame_low,
int frame_high);
466 htab_t copied_types);
478 struct type *obj_type,
const char *method_name,
479 xmethod_worker_vec **dm_vec);
484 struct type ***arg_types);
488 struct value *
object,
struct value **args,
int nargs,
489 struct type **result_type);
493 struct value *obj,
struct value **args,
int nargs);
510 const char *encoding,
663 #define GDB_PY_HANDLE_EXCEPTION(Exception) \ 665 if (Exception.reason < 0) \ 667 gdbpy_convert_exception (Exception); \ 674 #define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \ 676 if (Exception.reason < 0) \ 678 gdbpy_convert_exception (Exception); \ 699 struct type **str_type,
708 struct value **replacement,
PyObject * objfpy_get_xmethods(PyObject *, void *)
int gdbpy_initialize_record(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_lazy_string(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
#define GDB_PYSYS_SETPATH_CHAR
PyObject * gdbpy_block_for_pc(PyObject *self, PyObject *args)
#define PyObject_GetAttrString(obj, attr)
const struct block * block_object_to_block(PyObject *obj)
PyObject * gdb_python_module
int gdbpy_breakpoint_has_cond(const struct extension_language_defn *, struct breakpoint *b)
PyObject * gdbpy_selected_thread(PyObject *self, PyObject *args)
PyTypeObject value_object_type
int gdbpy_initialize_finishbreakpoints(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_is_field(PyObject *obj)
struct value * convert_value_from_python(PyObject *obj)
DISABLE_COPY_AND_ASSIGN(gdbpy_enter)
PyTypeObject thread_object_type
PyObject * gdbpy_value_cst
enum ext_lang_rc gdbpy_apply_val_pretty_printer(const struct extension_language_defn *, struct type *type, LONGEST embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, struct value *val, const struct value_print_options *options, const struct language_defn *language)
gdb::unique_xmalloc_ptr< char > python_string_to_target_string(PyObject *obj)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
constexpr gdb_PyGetSetDef(const char *name_, getter get_, setter set_, const char *doc_)
int gdbpy_initialize_blocks(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_stop_recording(PyObject *self, PyObject *args)
gdb::unique_xmalloc_ptr< char > unicode_to_target_string(PyObject *unicode_str)
static void gdb_PySys_SetPath(const GDB_PYSYS_SETPATH_CHAR *path)
PyObject * symtab_to_symtab_object(struct symtab *symtab)
int gdbpy_is_string(PyObject *obj)
unsigned long gdb_py_ulongest
#define CPYCHECKER_RETURNS_BORROWED_REF
PyTypeObject block_object_type
PyObject * gdbpy_to_string_cst
struct cmd_list_element * set_python_list
PyObject * gdb_py_object_from_ulongest(ULONGEST l)
PyObject * gdbpy_lookup_type(PyObject *self, PyObject *args, PyObject *kw)
PyObject * gdbpy_newest_frame(PyObject *self, PyObject *args)
int gdbpy_initialize_linetable(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
static void gdb_Py_DECREF(void *op)
struct gdbarch * arch_object_to_gdbarch(PyObject *obj)
int gdbpy_is_value_object(PyObject *obj)
struct type * type_object_to_type(PyObject *obj)
struct gdbpy_breakpoint_object gdbpy_breakpoint_object
static PyObject * gdb_PySys_GetObject(const char *name)
PyObject * gdbpy_get_varobj_pretty_printer(struct value *value)
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
PyObject * gdbpy_display_hint_cst
PyTypeObject frame_object_type
PyObject * gdbpy_default_visualizer(PyObject *self, PyObject *args)
PyObject * pspy_get_frame_unwinders(PyObject *, void *)
PyObject * pspy_get_frame_filters(PyObject *, void *)
PyObject * symtab_to_linetable_object(PyObject *symtab)
enum ext_lang_rc gdbpy_get_xmethod_result_type(const struct extension_language_defn *extlang, struct xmethod_worker *worker, struct value *object, struct value **args, int nargs, struct type **result_type)
PyObject * symtab_and_line_to_sal_object(struct symtab_and_line sal)
PyObject * gdbpy_current_recording(PyObject *self, PyObject *args)
PyObject * gdb_py_object_from_longest(LONGEST l)
PyObject * inferior_to_inferior_object(struct inferior *inferior)
int gdbpy_initialize_instruction(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_is_lazy_string(PyObject *result)
PyTypeObject symbol_object_type
gdb::unique_xmalloc_ptr< char > gdbpy_obj_to_string(PyObject *obj)
void bpfinishpy_post_stop_hook(struct gdbpy_breakpoint_object *bp_obj)
#define PyErr_NewException
mach_port_t kern_return_t mach_port_t msgports 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
gdbpy_enter_varobj(const struct varobj *var)
void gdbpy_initialize_gdb_readline(void)
struct active_ext_lang_state * m_previous_active
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_inferiors(PyObject *unused, PyObject *unused2)
PyObject * type_to_type_object(struct type *)
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
int gdbpy_initialize_breakpoints(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
#define CPYCHECKER_SETS_EXCEPTION
PyObject * objfile_to_objfile_object(struct objfile *) CPYCHECKER_RETURNS_BORROWED_REF
PyObject * python_string_to_target_python_string(PyObject *obj)
enum ext_lang_rc gdbpy_get_xmethod_arg_types(const struct extension_language_defn *extlang, struct xmethod_worker *worker, int *nargs, struct type ***arg_types)
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
void gdbpy_convert_exception(struct gdb_exception) CPYCHECKER_SETS_EXCEPTION
PyObject * gdbpy_enabled_cst
int gdbpy_initialize_btrace(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_gdb_error
int gdbpy_initialize_py_events(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
void bpfinishpy_pre_stop_hook(struct gdbpy_breakpoint_object *bp_obj)
int gdbpy_initialize_objfile(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
struct value * gdbpy_invoke_xmethod(const struct extension_language_defn *extlang, struct xmethod_worker *worker, struct value *obj, struct value **args, int nargs)
int gdbpy_initialize_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * find_inferior_object(int pid)
int get_addr_from_python(PyObject *obj, CORE_ADDR *addr) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_auto_load_enabled(const struct extension_language_defn *)
PyObject * objfpy_get_printers(PyObject *, void *)
const struct language_defn * m_language
int gdbpy_print_python_errors_p(void)
int gdbpy_initialize_frames(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
enum ext_lang_bt_status gdbpy_apply_frame_filter(const struct extension_language_defn *, struct frame_info *frame, int flags, enum ext_lang_frame_args args_type, struct ui_out *out, int frame_low, int frame_high)
PyObject * gdbpy_parameter_value(enum var_types type, void *var)
gdb::unique_xmalloc_ptr< char > gdbpy_exception_to_string(PyObject *ptype, PyObject *pvalue)
PyObject * gdbpy_selected_inferior(PyObject *self, PyObject *args)
int gdbpy_initialize_values(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * block_to_block_object(const struct block *block, struct objfile *objfile)
PyObject * pspace_to_pspace_object(struct program_space *) CPYCHECKER_RETURNS_BORROWED_REF
PyObject * gdbpy_lookup_objfile(PyObject *self, PyObject *args, PyObject *kw)
static int gdb_PyObject_HasAttrString(PyObject *obj, const char *attr)
PyObject * gdbpy_history(PyObject *self, PyObject *args)
struct symtab_and_line * sal_object_to_symtab_and_line(PyObject *obj)
struct gdbarch * python_gdbarch
int gdbpy_initialize_unwind(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_breakpoints(PyObject *, PyObject *)
int gdbpy_initialize_symtabs(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_create_lazy_string_object(CORE_ADDR address, long length, const char *encoding, struct type *type)
PyObject * gdbpy_gdberror_exc
PyObject * gdbpy_create_ptid_object(ptid_t ptid)
PyObject * gdbpy_lookup_global_symbol(PyObject *self, PyObject *args, PyObject *kw)
int gdb_python_initialized
int gdb_py_int_as_long(PyObject *, long *)
constexpr gdb_PyGetSetDef(std::nullptr_t)
int gdbpy_initialize_parameters(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
enum ext_lang_bp_stop gdbpy_breakpoint_cond_says_stop(const struct extension_language_defn *, struct breakpoint *)
char * gdbpy_parse_command_name(const char *name, struct cmd_list_element ***base_list, struct cmd_list_element **start_list)
PyObject * value_to_value_object(struct value *v)
PyObject * host_string_to_python_string(const char *str)
PyObject * apply_varobj_pretty_printer(PyObject *print_obj, struct value **replacement, struct ui_file *stream)
void gdbpy_extract_lazy_string(PyObject *string, CORE_ADDR *addr, struct type **str_type, long *length, gdb::unique_xmalloc_ptr< char > *encoding)
struct cmd_list_element * show_python_list
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * m_error_traceback
PyObject_HEAD struct thread_info * thread
PyObject * gdbpy_string_to_argv(PyObject *self, PyObject *args)
struct symtab * symtab_object_to_symtab(PyObject *obj)
PyObject * symbol_to_symbol_object(struct symbol *sym)
PyObject * pspy_get_xmethods(PyObject *, void *)
thread_object * find_thread_object(ptid_t ptid) CPYCHECKER_RETURNS_BORROWED_REF
int gdbpy_initialize_eventregistry(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_thread(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_inferior(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_functions(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyTypeObject breakpoint_object_type
int gdbpy_initialize_types(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
void gdbpy_free_xmethod_worker_data(const struct extension_language_defn *extlang, void *data)
PyObject * gdbpy_children_cst
gdbpy_enter(struct gdbarch *gdbarch, const struct language_defn *language)
int gdbpy_initialize_auto_load(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_breakpoint_object * bppy_pending_object
gdb::unique_xmalloc_ptr< char > gdbpy_get_display_hint(PyObject *printer)
PyObject * objfpy_get_frame_filters(PyObject *, void *)
PyObject * gdbarch_to_arch_object(struct gdbarch *gdbarch)
PyTypeObject event_object_type
PyObject * objfpy_get_frame_unwinders(PyObject *, void *)
int gdbpy_initialize_xmethods(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
void gdbpy_print_stack(void)
enum ext_lang_rc gdbpy_get_matching_xmethod_workers(const struct extension_language_defn *extlang, struct type *obj_type, const char *method_name, xmethod_worker_vec **dm_vec)
PyObject * gdbpy_frame_stop_reason_string(PyObject *, PyObject *)
constexpr gdb_PyGetSetDef(const char *name_, getter get_, setter set_, const char *doc_, void *closure_)
PyObject * gdbpy_lookup_symbol(PyObject *self, PyObject *args, PyObject *kw)
static PyObject * gdb_PyObject_CallMethod(PyObject *o, const char *method, const char *format, Args... args)
PyObject * gdbpy_gdb_memory_error
PyObject * pspy_get_printers(PyObject *, void *)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
unsigned long long ULONGEST
PyObject * gdbpy_selected_frame(PyObject *self, PyObject *args)
PyObject * gdbpy_start_recording(PyObject *self, PyObject *args)
static PyObject * gdb_PyObject_GetAttrString(PyObject *obj, const char *attr)
const struct language_defn * python_language
void * gdbpy_clone_xmethod_worker_data(const struct extension_language_defn *extlang, void *data)
int gdbpy_initialize_symbols(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
struct symbol * symbol_object_to_symbol(PyObject *obj)
#define PyObject_CallMethod
int gdbpy_initialize_commands(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
struct frame_info * frame_object_to_frame_info(PyObject *frame_obj)
int gdbpy_initialize_pspace(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
struct gdbarch * m_gdbarch
static PyObject * gdb_PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
PyObject * gdb_py_generic_dict(PyObject *self, void *closure)
PyObject * frame_info_to_frame_object(struct frame_info *frame)
PyObject * python_string_to_unicode(PyObject *obj)
thread_object * create_thread_object(struct thread_info *tp)
void gdbpy_preserve_values(const struct extension_language_defn *, struct objfile *objfile, htab_t copied_types)
struct varobj_iter * py_varobj_get_iterator(struct varobj *var, PyObject *printer)
#define PyObject_HasAttrString(obj, attr)
struct value * value_object_to_value(PyObject *self)
int gdbpy_initialize_arch(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION