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
89 #define PY_SSIZE_T_CLEAN
95 #include <frameobject.h>
97 #if PY_MAJOR_VERSION >= 3
102 #define Py_TPFLAGS_HAVE_ITER 0
103 #define Py_TPFLAGS_CHECKTYPES 0
105 #define PyInt_Check PyLong_Check
106 #define PyInt_FromLong PyLong_FromLong
107 #define PyInt_AsLong PyLong_AsLong
109 #define PyString_FromString PyUnicode_FromString
110 #define PyString_Decode PyUnicode_Decode
111 #define PyString_FromFormat PyUnicode_FromFormat
112 #define PyString_Check PyUnicode_Check
115 #if HAVE_LIBPYTHON2_4
120 typedef int Py_ssize_t;
123 #ifndef PyVarObject_HEAD_INIT
125 #define PyVarObject_HEAD_INIT(type, size) \
126 PyObject_HEAD_INIT(type) size,
132 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
139 #define PyGILState_Ensure() ((PyGILState_STATE) 0)
140 #define PyGILState_Release(ARG) ((void)(ARG))
141 #define PyEval_InitThreads()
142 #define PyThreadState_Swap(ARG) ((void)(ARG))
143 #define PyEval_ReleaseLock()
149 #ifdef HAVE_LONG_LONG
151 #define GDB_PY_LL_ARG "L"
152 #define GDB_PY_LLU_ARG "K"
155 #define gdb_py_long_from_longest PyLong_FromLongLong
156 #define gdb_py_long_from_ulongest PyLong_FromUnsignedLongLong
157 #define gdb_py_long_as_ulongest PyLong_AsUnsignedLongLong
161 #define GDB_PY_LL_ARG "L"
162 #define GDB_PY_LLU_ARG "K"
165 #define gdb_py_long_from_longest PyLong_FromLong
166 #define gdb_py_long_from_ulongest PyLong_FromUnsignedLong
167 #define gdb_py_long_as_ulongest PyLong_AsUnsignedLong
171 #if PY_VERSION_HEX < 0x03020000
189 #define Py_DECREF(op) gdb_Py_DECREF (op)
195 static inline PyObject *
202 #define PyObject_GetAttrString(obj, attr) gdb_PyObject_GetAttrString (obj, attr)
215 #define PyObject_HasAttrString(obj, attr) gdb_PyObject_HasAttrString (obj, attr)
246 extern PyTypeObject stop_event_object_type
270 #define BPPY_REQUIRE_VALID(Breakpoint) \
272 if ((Breakpoint)->bp == NULL) \
273 return PyErr_Format (PyExc_RuntimeError, \
274 _("Breakpoint %d is invalid."), \
275 (Breakpoint)->number); \
280 #define BPPY_SET_REQUIRE_VALID(Breakpoint) \
282 if ((Breakpoint)->bp == NULL) \
284 PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
285 (Breakpoint)->number); \
320 struct ui_file *stream,
int recurse,
321 const struct value *val,
327 struct ui_out *out,
int frame_low,
int frame_high);
330 htab_t copied_types);
342 struct type *obj_type,
const char *method_name,
343 xmethod_worker_vec **dm_vec);
348 struct type ***arg_types);
352 struct value *
object,
struct value **args,
int nargs,
353 struct type **result_type);
357 struct value *obj,
struct value **args,
int nargs);
394 CPYCHECKER_RETURNS_BORROWED_REF;
401 CPYCHECKER_RETURNS_BORROWED_REF;
412 CPYCHECKER_RETURNS_BORROWED_REF;
428 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
430 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
432 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
434 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
436 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
438 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
440 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
442 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
444 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
446 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
448 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
450 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
452 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
454 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
456 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
458 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
460 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
462 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
464 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
466 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
468 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
470 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
472 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
474 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
476 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
478 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
480 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
482 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
484 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
486 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
488 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
490 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
492 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
494 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
496 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
498 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
500 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
508 extern struct gdbarch *python_gdbarch;
513 #define GDB_PY_HANDLE_EXCEPTION(Exception) \
515 if (Exception.reason < 0) \
517 gdbpy_convert_exception (Exception); \
524 #define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
526 if (Exception.reason < 0) \
528 gdbpy_convert_exception (Exception); \
547 struct type **str_type,
555 struct value **replacement,
577 CPYCHECKER_SETS_EXCEPTION;
580 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
590 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
PyObject * objfpy_get_xmethods(PyObject *, void *)
int gdbpy_initialize_lazy_string(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_signal_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_block_for_pc(PyObject *self, PyObject *args)
#define PyObject_GetAttrString(obj, attr)
int gdbpy_initialize_inferior_call_post_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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)
PyObject * gdbpy_value_cst
char * gdbpy_obj_to_string(PyObject *obj)
int gdbpy_initialize_blocks(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_memory_changed_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
struct type ** const(pascal_builtin_types[])
PyObject * symtab_to_symtab_object(struct symtab *symtab)
int gdbpy_is_string(PyObject *obj)
unsigned long gdb_py_ulongest
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
PyObject * gdbpy_get_varobj_pretty_printer(struct value *value)
PyObject * gdbpy_display_hint_cst
void gdbpy_extract_lazy_string(PyObject *string, CORE_ADDR *addr, struct type **str_type, long *length, char **encoding)
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 * gdb_py_object_from_longest(LONGEST l)
int gdbpy_initialize_register_changed_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * inferior_to_inferior_object(struct inferior *inferior)
int gdbpy_initialize_continue_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
char * unicode_to_target_string(PyObject *unicode_str)
int gdbpy_is_lazy_string(PyObject *result)
PyTypeObject symbol_object_type
void bpfinishpy_post_stop_hook(struct gdbpy_breakpoint_object *bp_obj)
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
void gdbpy_initialize_gdb_readline(void)
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
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)
PyObject * gdbpy_parameter(PyObject *self, PyObject *args)
void gdbpy_convert_exception(struct gdb_exception) CPYCHECKER_SETS_EXCEPTION
PyObject * gdbpy_enabled_cst
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 *)
int gdbpy_initialize_exited_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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)
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 cleanup * ensure_python_env(struct gdbarch *gdbarch, const struct language_defn *language)
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
char * python_string_to_host_string(PyObject *obj)
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 *)
char * python_string_to_target_string(PyObject *obj)
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 * apply_varobj_pretty_printer(PyObject *print_obj, struct value **replacement, struct ui_file *stream)
struct cmd_list_element * show_python_list
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
int gdbpy_initialize_breakpoint_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_auto_load(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
enum ext_lang_rc gdbpy_apply_val_pretty_printer(const struct extension_language_defn *, struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, const struct value_print_options *options, const struct language_defn *language)
gdbpy_breakpoint_object * bppy_pending_object
PyObject * objfpy_get_frame_filters(PyObject *, void *)
PyObject * gdbarch_to_arch_object(struct gdbarch *gdbarch)
char * gdbpy_get_display_hint(PyObject *printer)
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 *)
int gdbpy_initialize_inferior_call_pre_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdbpy_lookup_symbol(PyObject *self, PyObject *args, PyObject *kw)
PyObject * gdbpy_gdb_memory_error
PyObject * pspy_get_printers(PyObject *, void *)
unsigned long long ULONGEST
PyObject * gdbpy_selected_frame(PyObject *self, PyObject *args)
int gdbpy_initialize_stop_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
struct cleanup * make_cleanup_py_xdecref(PyObject *py)
static PyObject * gdb_PyObject_GetAttrString(PyObject *obj, const char *attr)
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)
int gdbpy_initialize_commands(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
struct frame_info * frame_object_to_frame_info(PyObject *frame_obj)
char * gdbpy_exception_to_string(PyObject *ptype, PyObject *pvalue)
int gdbpy_initialize_pspace(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_new_objfile_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
int gdbpy_initialize_clear_objfiles_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
PyObject * gdb_py_generic_dict(PyObject *self, void *closure)
int gdbpy_initialize_thread_event(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
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 cleanup * make_cleanup_py_decref(PyObject *py)
struct value * value_object_to_value(PyObject *self)
int gdbpy_initialize_arch(void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION