23#include "gdbsupport/gdb_obstack.h"
47#define pyuw_debug_printf(fmt, ...) \
48 debug_prefixed_printf_cond (pyuw_debug, "py-unwind", fmt, ##__VA_ARGS__)
52#define PYUW_SCOPED_DEBUG_ENTER_EXIT \
53 scoped_debug_enter_exit (pyuw_debug, "py-unwind")
138 catch (
const gdb_exception &except)
157 if (PyObject_HasAttrString (pyo, attr_name))
159 gdbpy_ref<> pyo_value (PyObject_GetAttrString (pyo, attr_name));
161 if (pyo_value != NULL && pyo_value != Py_None)
167 _(
"The value of the '%s' attribute is not a pointer."),
185 const char *sep =
"";
189 stb.
printf (
"\nSaved registers: (");
202 catch (
const gdb_exception &except)
214 return PyUnicode_FromString (stb.
c_str ());
229 PyErr_SetString (PyExc_ValueError,
230 "Attempting to use stale PendingFrame");
234 Py_INCREF (pyo_pending_frame);
236 unwind_info->
saved_regs =
new std::vector<saved_reg>;
255 PyErr_SetString (PyExc_ValueError,
256 "UnwindInfo instance refers to a stale PendingFrame");
259 if (!PyArg_UnpackTuple (args,
"previous_frame_register", 2, 2,
260 &pyo_reg_id, &pyo_reg_value))
273 struct value *user_reg_value
279 PyErr_SetString (PyExc_ValueError,
"Bad register");
288 if (pyo_reg_value == NULL
291 PyErr_SetString (PyExc_ValueError,
"Bad register value");
299 "The value of the register returned by the Python "
300 "sniffer has unexpected size: %u instead of %u.",
302 (
unsigned) data_size);
314 reg.value = std::move (new_value);
333 Py_TYPE (self)->tp_free (self);
343 const char *sp_str = NULL;
344 const char *pc_str = NULL;
347 return PyUnicode_FromString (
"Stale PendingFrame instance");
353 catch (
const gdb_exception &except)
358 return PyUnicode_FromFormat (
"SP=%s,PC=%s", sp_str, pc_str);
368 struct value *val = NULL;
374 PyErr_SetString (PyExc_ValueError,
375 "Attempting to read register from stale PendingFrame");
378 if (!PyArg_UnpackTuple (args,
"read_register", 1, 1, &pyo_reg_id))
392 PyErr_Format (PyExc_ValueError,
393 "Cannot read register %d from frame.",
396 catch (
const gdb_exception &except)
415 if (!PyArg_ParseTuple (args,
"O:create_unwind_info", &pyo_frame_id))
419 PyErr_SetString (PyExc_ValueError,
420 _(
"frame_id should have 'sp' attribute."));
451 PyErr_SetString (PyExc_ValueError,
452 "Attempting to read register from stale PendingFrame");
467 PyErr_SetString (PyExc_ValueError,
468 "Attempting to read stack level from stale PendingFrame");
499 for (; reg_info < reg_info_end; ++reg_info)
530 if (pyo_pending_frame == NULL)
536 scoped_restore invalidate_frame = make_scoped_restore (&pfo->
frame_info,
543 PyErr_SetString (PyExc_NameError,
544 "Installation error: gdb._execute_unwinders function "
550 "_execute_unwinders"));
551 if (pyo_execute ==
nullptr)
559 (PyObject_CallFunctionObjArgs (pyo_execute.get (),
560 pyo_pending_frame.get (), NULL));
561 if (pyo_execute_ret ==
nullptr)
568 if (pyo_execute_ret == Py_None)
572 gdb_assert (PyTuple_Check (pyo_execute_ret.get ()));
573 gdb_assert (PyTuple_GET_SIZE (pyo_execute_ret.get ()) == 2);
577 PyObject *pyo_unwinder_name = PyTuple_GET_ITEM (pyo_execute_ret.get (), 1);
578 gdb::unique_xmalloc_ptr<char>
name
586 name = make_unique_xstrdup (
"<failed to get unwinder name>");
593 PyObject *pyo_unwind_info = PyTuple_GET_ITEM (pyo_execute_ret.get (), 0);
594 if (PyObject_IsInstance (pyo_unwind_info,
596 error (_(
"A Unwinder should return gdb.UnwindInfo instance."));
601 int reg_count = unwind_info->
saved_regs->size ();
605 xmalloc (
sizeof (*cached_frame)
606 + reg_count *
sizeof (cached_frame->
reg[0])));
612 for (
int i = 0; i < unwind_info->
saved_regs->size (); ++i)
622 gdb_assert (
value != NULL);
626 memcpy (cached_frame->
reg[i].
data,
631 *cache_ptr = cached_frame;
643 for (
int i = 0; i < cached_frame->
reg_count; i++)
667 if (!data->unwinder_registered)
672 unwinder->
name =
"python";
681 data->unwinder_registered = 1;
691 _(
"Set Python unwinder debugging."),
692 _(
"Show Python unwinder debugging."),
693 _(
"When on, Python unwinder debugging is enabled."),
723 "read_register (REG) -> gdb.Value\n"
724 "Return the value of the REG in the frame." },
725 {
"create_unwind_info",
727 "create_unwind_info (FRAME_ID) -> gdb.UnwindInfo\n"
728 "Construct UnwindInfo for this PendingFrame, using FRAME_ID\n"
732 "architecture () -> gdb.Architecture\n"
733 "The architecture for this PendingFrame." },
735 "The stack level of this frame." },
741 PyVarObject_HEAD_INIT (NULL, 0)
761 "GDB PendingFrame object",
782 {
"add_saved_register",
784 "add_saved_register (REG, VALUE) -> None\n"
785 "Set the value of the REG in the previous frame to VALUE." },
791 PyVarObject_HEAD_INIT (NULL, 0)
810 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
811 "GDB UnwindInfo object",
const char * c_str() const
virtual void puts(const char *str)
void printf(const char *,...) ATTRIBUTE_PRINTF(2
struct cmd_list_element * showdebuglist
struct cmd_list_element * setdebuglist
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct value * value_of_register(int regnum, frame_info_ptr frame)
struct value * frame_unwind_got_optimized(frame_info_ptr frame, int regnum)
void frame_unwind_prepend_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
enum unwind_stop_reason default_frame_unwind_stop_reason(frame_info_ptr this_frame, void **this_cache)
struct value * frame_unwind_got_bytes(frame_info_ptr frame, int regnum, const gdb_byte *buf)
int frame_relative_level(frame_info_ptr fi)
CORE_ADDR get_frame_pc(frame_info_ptr frame)
CORE_ADDR get_frame_sp(frame_info_ptr this_frame)
struct frame_id frame_id_build_special(CORE_ADDR stack_addr, CORE_ADDR code_addr, CORE_ADDR special_addr)
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
struct frame_id frame_id_build_wild(CORE_ADDR stack_addr)
#define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE)
static int gdbarch_num_cooked_regs(gdbarch *arch)
observable< struct gdbarch * > architecture_changed
PyObject * gdbarch_to_arch_object(struct gdbarch *gdbarch)
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
bool gdbpy_parse_register_id(struct gdbarch *gdbarch, PyObject *pyo_reg_id, int *reg_num)
static void pyuw_on_new_gdbarch(struct gdbarch *newarch)
#define pyuw_debug_printf(fmt,...)
static PyObject * pyuw_create_unwind_info(PyObject *pyo_pending_frame, struct frame_id frame_id)
static void pyuw_dealloc_cache(frame_info *this_frame, void *cache)
static void show_pyuw_debug(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static PyObject * pending_framepy_level(PyObject *self, PyObject *args)
static PyObject * pending_framepy_read_register(PyObject *self, PyObject *args)
PyTypeObject pending_frame_object_type
static const registry< gdbarch >::key< pyuw_gdbarch_data_type > pyuw_gdbarch_data
static PyObject * pending_framepy_str(PyObject *self)
static struct value * pyuw_prev_register(frame_info_ptr this_frame, void **cache_ptr, int regnum)
static int pyuw_object_attribute_to_pointer(PyObject *pyo, const char *attr_name, CORE_ADDR *addr)
static int pyuw_sniffer(const struct frame_unwind *self, frame_info_ptr this_frame, void **cache_ptr)
#define PYUW_SCOPED_DEBUG_ENTER_EXIT
static PyMethodDef pending_frame_object_methods[]
int gdbpy_initialize_unwind(void)
static void unwind_infopy_dealloc(PyObject *self)
static int pyuw_value_obj_to_pointer(PyObject *pyo_value, CORE_ADDR *addr)
static PyObject * pending_framepy_create_unwind_info(PyObject *self, PyObject *args)
static PyObject * unwind_infopy_str(PyObject *self)
PyTypeObject unwind_info_object_type
static PyObject * pending_framepy_architecture(PyObject *self, PyObject *args)
static PyObject * unwind_infopy_add_saved_register(PyObject *self, PyObject *args)
void _initialize_py_unwind()
static void pyuw_this_id(frame_info_ptr this_frame, void **cache_ptr, struct frame_id *this_id)
static PyMethodDef unwind_info_object_methods[]
gdbpy_ref gdb_py_object_from_longest(LONGEST l)
void gdbpy_convert_exception(const struct gdb_exception &exception)
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
PyObject * value_to_value_object(struct value *val)
struct value * value_object_to_value(PyObject *self)
void gdbpy_print_stack(void)
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
void gdbpy_print_stack_or_quit()
PyObject * gdb_python_module
#define GDB_PY_HANDLE_EXCEPTION(Exception)
int register_size(struct gdbarch *gdbarch, int regnum)
std::string to_string() const
frame_sniffer_ftype * sniffer
frame_dealloc_cache_ftype * dealloc_cache
frame_this_id_ftype * this_id
frame_unwind_stop_reason_ftype * stop_reason
const struct frame_data * unwind_data
frame_prev_register_ftype * prev_register
PyObject_HEAD frame_info_ptr frame_info
saved_reg(int n, gdbpy_ref<> &&v)
std::vector< saved_reg > * saved_regs
PyObject_HEAD PyObject * pending_frame
struct value::@195::@196 reg
struct value * value_of_user_reg(int regnum, frame_info_ptr frame)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
void gdb_printf(struct ui_file *stream, const char *format,...)
void value_print(struct value *val, struct ui_file *stream, const struct value_print_options *options)
void get_user_print_options(struct value_print_options *opts)
struct type * value_type(const struct value *value)
CORE_ADDR unpack_pointer(struct type *type, const gdb_byte *valaddr)
gdb::array_view< const gdb_byte > value_contents(struct value *value)
#define VALUE_REGNUM(val)