/* Gdb/Python header for private use by Python module.
- Copyright (C) 2008-2019 Free Software Foundation, Inc.
+ Copyright (C) 2008-2022 Free Software Foundation, Inc.
This file is part of GDB.
#endif
#ifdef IS_PY3K
-#define Py_TPFLAGS_HAVE_ITER 0
#define Py_TPFLAGS_CHECKTYPES 0
#define PyInt_Check PyLong_Check
-#define PyInt_FromLong PyLong_FromLong
-#define PyInt_FromSsize_t PyLong_FromSsize_t
#define PyInt_AsLong PyLong_AsLong
#define PyInt_AsSsize_t PyLong_AsSsize_t
#define GDB_PY_LLU_ARG "K"
typedef PY_LONG_LONG gdb_py_longest;
typedef unsigned PY_LONG_LONG gdb_py_ulongest;
-#define gdb_py_long_from_longest PyLong_FromLongLong
-#define gdb_py_long_from_ulongest PyLong_FromUnsignedLongLong
#define gdb_py_long_as_ulongest PyLong_AsUnsignedLongLong
#else /* HAVE_LONG_LONG */
#define GDB_PY_LLU_ARG "K"
typedef long gdb_py_longest;
typedef unsigned long gdb_py_ulongest;
-#define gdb_py_long_from_longest PyLong_FromLong
-#define gdb_py_long_from_ulongest PyLong_FromUnsignedLong
#define gdb_py_long_as_ulongest PyLong_AsUnsignedLong
#endif /* HAVE_LONG_LONG */
struct value;
struct language_defn;
struct program_space;
-struct bpstats;
+struct bpstat;
struct inferior;
extern int gdb_python_initialized;
extern PyTypeObject thread_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("thread_object");
-typedef struct gdbpy_breakpoint_object
+struct gdbpy_breakpoint_object
{
PyObject_HEAD
/* 1 is this is a FinishBreakpoint object, 0 otherwise. */
int is_finish_bp;
-} gdbpy_breakpoint_object;
+};
/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
exception if it is invalid. */
#define BPPY_REQUIRE_VALID(Breakpoint) \
do { \
if ((Breakpoint)->bp == NULL) \
- return PyErr_Format (PyExc_RuntimeError, \
- _("Breakpoint %d is invalid."), \
- (Breakpoint)->number); \
+ return PyErr_Format (PyExc_RuntimeError, \
+ _("Breakpoint %d is invalid."), \
+ (Breakpoint)->number); \
} while (0)
/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
#define BPPY_SET_REQUIRE_VALID(Breakpoint) \
do { \
if ((Breakpoint)->bp == NULL) \
- { \
- PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
- (Breakpoint)->number); \
- return -1; \
- } \
+ { \
+ PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
+ (Breakpoint)->number); \
+ return -1; \
+ } \
} while (0)
extern gdbpy_breakpoint_object *bppy_pending_object;
-typedef struct
+struct thread_object
{
PyObject_HEAD
/* The Inferior object to which this thread belongs. */
PyObject *inf_obj;
-} thread_object;
+};
struct inferior_object;
\f
/* extension_language_script_ops "methods". */
-extern int gdbpy_auto_load_enabled (const struct extension_language_defn *);
+/* Return true if auto-loading Python scripts is enabled.
+ This is the extension_language_script_ops.auto_load_enabled "method". */
+
+extern bool gdbpy_auto_load_enabled (const struct extension_language_defn *);
/* extension_language_ops "methods". */
extern enum ext_lang_rc gdbpy_apply_val_pretty_printer
(const struct extension_language_defn *,
- struct type *type,
- LONGEST embedded_offset, CORE_ADDR address,
+ struct value *value,
struct ui_file *stream, int recurse,
- struct value *val,
const struct value_print_options *options,
const struct language_defn *language);
extern enum ext_lang_bt_status gdbpy_apply_frame_filter
\f
PyObject *gdbpy_history (PyObject *self, PyObject *args);
+PyObject *gdbpy_add_history (PyObject *self, PyObject *args);
+extern PyObject *gdbpy_history_count (PyObject *self, PyObject *args);
PyObject *gdbpy_convenience_variable (PyObject *self, PyObject *args);
PyObject *gdbpy_set_convenience_variable (PyObject *self, PyObject *args);
PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args);
PyObject *gdbpy_selected_inferior (PyObject *self, PyObject *args);
PyObject *gdbpy_string_to_argv (PyObject *self, PyObject *args);
-PyObject *gdbpy_parameter_value (enum var_types type, void *var);
-char *gdbpy_parse_command_name (const char *name,
- struct cmd_list_element ***base_list,
- struct cmd_list_element **start_list);
+PyObject *gdbpy_parameter_value (const setting &var);
+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 *gdbpy_register_tui_window (PyObject *self, PyObject *args,
+ PyObject *kw);
PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
PyObject *symtab_to_symtab_object (struct symtab *symtab);
PyObject *block_to_block_object (const struct block *block,
struct objfile *objfile);
PyObject *value_to_value_object (struct value *v);
+PyObject *value_to_value_object_no_release (struct value *v);
PyObject *type_to_type_object (struct type *);
PyObject *frame_info_to_frame_object (struct frame_info *frame);
PyObject *symtab_to_linetable_object (PyObject *symtab);
PyObject *gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw);
PyObject *gdbarch_to_arch_object (struct gdbarch *gdbarch);
+PyObject *gdbpy_all_architecture_names (PyObject *self, PyObject *args);
+
+PyObject *gdbpy_new_register_descriptor_iterator (struct gdbarch *gdbarch,
+ const char *group_name);
+PyObject *gdbpy_new_reggroup_iterator (struct gdbarch *gdbarch);
gdbpy_ref<thread_object> create_thread_object (struct thread_info *tp);
gdbpy_ref<> thread_to_thread_object (thread_info *thr);;
gdbpy_ref<inferior_object> inferior_to_inferior_object (inferior *inf);
+PyObject *gdbpy_buffer_to_membuf (gdb::unique_xmalloc_ptr<gdb_byte> buffer,
+ CORE_ADDR address, ULONGEST length);
+
+struct process_stratum_target;
+gdbpy_ref<> target_to_connection_object (process_stratum_target *target);
+PyObject *gdbpy_connections (PyObject *self, PyObject *args);
+
const struct block *block_object_to_block (PyObject *obj);
struct symbol *symbol_object_to_symbol (PyObject *obj);
struct value *value_object_to_value (PyObject *self);
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
int gdbpy_initialize_arch (void)
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_registers ()
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
int gdbpy_initialize_xmethods (void)
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
int gdbpy_initialize_unwind (void)
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_tui ()
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_membuf ()
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_connection ()
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
/* A wrapper for PyErr_Fetch that handles reference counting for the
caller. */
{
public:
- gdbpy_enter (struct gdbarch *gdbarch, const struct language_defn *language);
+ /* Set the ambient Python architecture to GDBARCH and the language
+ to LANGUAGE. If GDBARCH is nullptr, then the architecture will
+ be computed, when needed, using get_current_arch; see the
+ get_gdbarch method. If LANGUAGE is not nullptr, then the current
+ language at time of construction will be saved (to be restored on
+ destruction), and the current language will be set to
+ LANGUAGE. */
+ explicit gdbpy_enter (struct gdbarch *gdbarch = nullptr,
+ const struct language_defn *language = nullptr);
~gdbpy_enter ();
DISABLE_COPY_AND_ASSIGN (gdbpy_enter);
+ /* Return the current gdbarch, as known to the Python layer. This
+ is either python_gdbarch (which comes from the most recent call
+ to the gdbpy_enter constructor), or, if that is nullptr, the
+ result of get_current_arch. */
+ static struct gdbarch *get_gdbarch ();
+
+ /* Called only during gdb shutdown. This sets python_gdbarch to an
+ acceptable value. */
+ static void finalize ();
+
private:
+ /* The current gdbarch, according to Python. This can be
+ nullptr. */
+ static struct gdbarch *python_gdbarch;
+
struct active_ext_lang_state *m_previous_active;
PyGILState_STATE m_state;
struct gdbarch *m_gdbarch;
PyThreadState *m_save;
};
-extern struct gdbarch *python_gdbarch;
-extern const struct language_defn *python_language;
-
/* Use this after a TRY_EXCEPT to throw the appropriate Python
exception. */
#define GDB_PY_HANDLE_EXCEPTION(Exception) \
if (Exception.reason < 0) \
{ \
gdbpy_convert_exception (Exception); \
- return NULL; \
+ return NULL; \
} \
} while (0)
#define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
do { \
if (Exception.reason < 0) \
- { \
+ { \
gdbpy_convert_exception (Exception); \
return -1; \
} \
struct varobj_iter;
struct varobj;
-struct varobj_iter *py_varobj_get_iterator (struct varobj *var,
- PyObject *printer);
+std::unique_ptr<varobj_iter> py_varobj_get_iterator (struct varobj *var,
+ PyObject *printer);
/* Deleter for Py_buffer unique_ptr specialization. */
/* A unique_ptr specialization for Py_buffer. */
typedef std::unique_ptr<Py_buffer, Py_buffer_deleter> Py_buffer_up;
+/* Parse a register number from PYO_REG_ID and place the register number
+ into *REG_NUM. The register is a register for GDBARCH.
+
+ If a register is parsed successfully then *REG_NUM will have been
+ updated, and true is returned. Otherwise the contents of *REG_NUM are
+ undefined, and false is returned.
+
+ The PYO_REG_ID object can be a string, the name of the register. This
+ is the slowest approach as GDB has to map the name to a number for each
+ call. Alternatively PYO_REG_ID can be an internal GDB register
+ number. This is quick but should not be encouraged as this means
+ Python scripts are now dependent on GDB's internal register numbering.
+ Final PYO_REG_ID can be a gdb.RegisterDescriptor object, these objects
+ can be looked up by name once, and then cache the register number so
+ should be as quick as using a register number. */
+
+extern bool gdbpy_parse_register_id (struct gdbarch *gdbarch,
+ PyObject *pyo_reg_id, int *reg_num);
+
#endif /* PYTHON_PYTHON_INTERNAL_H */