32 #define TRACE_PY_UNWIND(level, args...) if (pyuw_debug >= level) \
33 { fprintf_unfiltered (gdb_stdlog, args); }
101 extern PyTypeObject unwind_info_object_type
115 if (pyo_reg_id == NULL)
121 if (reg_name == NULL)
125 return *reg_num >= 0;
127 else if (PyInt_Check (pyo_reg_id))
132 *reg_num = (
int) value;
182 if (pyo_value != NULL && pyo_value != Py_None)
188 _(
"The value of the '%s' attribute is not a pointer."),
191 Py_XDECREF (pyo_value);
247 result = PyString_FromString (s);
266 PyErr_SetString (PyExc_ValueError,
267 "Attempting to use stale PendingFrame");
271 Py_INCREF (pyo_pending_frame);
274 return (PyObject *) unwind_info;
286 PyObject *pyo_reg_id;
287 PyObject *pyo_reg_value;
292 PyErr_SetString (PyExc_ValueError,
293 "UnwindInfo instance refers to a stale PendingFrame");
296 if (!PyArg_UnpackTuple (args,
"previous_frame_register", 2, 2,
297 &pyo_reg_id, &pyo_reg_value))
301 PyErr_SetString (PyExc_ValueError,
"Bad register");
308 if (pyo_reg_value == NULL
311 PyErr_SetString (PyExc_ValueError,
"Bad register value");
319 "The value of the register returned by the Python "
320 "sniffer has unexpected size: %u instead of %u.",
322 (
unsigned) data_size);
332 if (regnum == reg->
number)
343 Py_INCREF (pyo_reg_value);
344 reg->
value = pyo_reg_value;
362 Py_TYPE (
self)->tp_free (
self);
372 const char *sp_str = NULL;
373 const char *pc_str = NULL;
376 return PyString_FromString (
"Stale PendingFrame instance");
388 return PyString_FromFormat (
"SP=%s,PC=%s", sp_str, pc_str);
398 struct value *val = NULL;
400 PyObject *pyo_reg_id;
404 PyErr_SetString (PyExc_ValueError,
405 "Attempting to read register from stale PendingFrame");
408 if (!PyArg_UnpackTuple (args,
"read_register", 1, 1, &pyo_reg_id))
412 PyErr_SetString (PyExc_ValueError,
"Bad register");
420 PyErr_Format (PyExc_ValueError,
421 "Cannot read register %d from frame.",
439 PyObject *pyo_frame_id;
444 if (!PyArg_ParseTuple (args,
"O:create_unwind_info", &pyo_frame_id))
448 PyErr_SetString (PyExc_ValueError,
449 _(
"frame_id should have 'sp' attribute."));
476 if (pyo_pending_frame != NULL)
497 static struct value *
503 struct reg_info *reg_info_end = reg_info + cached_frame->
reg_count;
505 TRACE_PY_UNWIND (1,
"%s (frame=%p,...,reg=%d)\n", __FUNCTION__, this_frame,
507 for (; reg_info < reg_info_end; ++reg_info)
509 if (regnum == reg_info->
number)
524 PyObject *pyo_execute;
525 PyObject *pyo_pending_frame;
526 PyObject *pyo_unwind_info;
536 if (pyo_pending_frame == NULL)
547 PyErr_SetString (PyExc_NameError,
548 "Installation error: gdb.execute_unwinders function "
553 if (pyo_execute == NULL)
557 = PyObject_CallFunctionObjArgs (pyo_execute, pyo_pending_frame, NULL);
558 if (pyo_unwind_info == NULL)
561 if (pyo_unwind_info == Py_None)
565 if (PyObject_IsInstance (pyo_unwind_info,
566 (PyObject *) &unwind_info_object_type) <= 0)
567 error (
_(
"A Unwinder should return gdb.UnwindInfo instance."));
575 cached_frame =
xmalloc (
sizeof (*cached_frame) +
576 reg_count *
sizeof (cached_frame->
reg[0]));
577 cached_frame->
gdbarch = gdbarch;
598 *cache_ptr = cached_frame;
665 _(
"Set Python unwinder debugging."),
666 _(
"Show Python unwinder debugging."),
667 _(
"When non-zero, Python unwinder debugging is enabled."),
682 if (PyType_Ready (&unwind_info_object_type) < 0)
685 (PyObject *) &unwind_info_object_type);
691 "read_register (REG) -> gdb.Value\n"
692 "Return the value of the REG in the frame." },
693 {
"create_unwind_info",
695 "create_unwind_info (FRAME_ID) -> gdb.UnwindInfo\n"
696 "Construct UnwindInfo for this PendingFrame, using FRAME_ID\n"
723 "GDB PendingFrame object",
730 pending_frame_object_methods,
742 static PyMethodDef unwind_info_object_methods[] =
744 {
"add_saved_register",
746 "add_saved_register (REG, VALUE) -> None\n"
747 "Set the value of the REG in the previous frame to VALUE." },
751 PyTypeObject unwind_info_object_type =
772 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
773 "GDB UnwindInfo object",
780 unwind_info_object_methods,
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
static struct gdbarch_data * pyuw_gdbarch_data
const char * user_reg_map_regnum_to_name(struct gdbarch *gdbarch, int regnum)
#define PyObject_GetAttrString(obj, attr)
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
struct value * frame_unwind_got_bytes(struct frame_info *frame, int regnum, gdb_byte *buf)
PyObject * gdb_python_module
CORE_ADDR get_frame_pc(struct frame_info *frame)
void value_print(struct value *val, struct ui_file *stream, const struct value_print_options *options)
void add_setshow_zuinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int gdbpy_initialize_unwind(void)
CORE_ADDR unpack_pointer(struct type *type, const gdb_byte *valaddr)
int gdbpy_is_string(PyObject *obj)
char * ui_file_xstrdup(struct ui_file *file, long *length)
void ui_file_delete(struct ui_file *file)
void * gdbarch_data(struct gdbarch *gdbarch, struct gdbarch_data *data)
char * gdbpy_obj_to_string(PyObject *obj)
static void pyuw_on_new_gdbarch(struct gdbarch *newarch)
static void * pyuw_gdbarch_data_init(struct gdbarch *gdbarch)
CORE_ADDR get_frame_sp(struct frame_info *this_frame)
frame_prev_register_ftype * prev_register
frame_sniffer_ftype * sniffer
frame_dealloc_cache_ftype * dealloc_cache
#define VEC_safe_push(T, V, O)
static unsigned int pyuw_debug
void frame_unwind_prepend_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
static void pyuw_dealloc_cache(struct frame_info *this_frame, void *cache)
PyObject_HEAD struct frame_info * frame_info
#define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
static PyObject * pyuw_create_unwind_info(PyObject *pyo_pending_frame, struct frame_id frame_id)
#define GDB_PY_HANDLE_EXCEPTION(Exception)
#define VEC_iterate(T, V, I, P)
struct value * get_frame_register_value(struct frame_info *frame, int regnum)
const gdb_byte * value_contents(struct value *value)
#define CATCH(EXCEPTION, MASK)
struct observer * observer_attach_architecture_changed(observer_architecture_changed_ftype *f)
static PyObject * pending_framepy_create_unwind_info(PyObject *self, PyObject *args)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
static void unwind_infopy_dealloc(PyObject *self)
frame_unwind_stop_reason_ftype * stop_reason
struct frame_id frame_id_build_special(CORE_ADDR stack_addr, CORE_ADDR code_addr, CORE_ADDR special_addr)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
static PyObject * unwind_infopy_str(PyObject *self)
static PyMethodDef pending_frame_object_methods[]
#define TRACE_PY_UNWIND(level, args...)
struct cleanup * ensure_python_env(struct gdbarch *gdbarch, const struct language_defn *language)
PyTypeObject pending_frame_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("pending_frame_object")
PyObject * value_to_value_object(struct value *val)
struct cmd_list_element * setdebuglist
int user_reg_map_name_to_regnum(struct gdbarch *gdbarch, const char *name, int len)
struct ui_file * gdb_stdlog
struct ui_file * mem_fileopen(void)
struct value * frame_unwind_got_optimized(struct frame_info *frame, int regnum)
static struct value * pyuw_prev_register(struct frame_info *this_frame, void **cache_ptr, int regnum)
const char const char int
static int pyuw_object_attribute_to_pointer(PyObject *pyo, const char *attr_name, CORE_ADDR *addr)
static PyObject * pending_framepy_str(PyObject *self)
const struct language_defn * current_language
PyTypeObject pending_frame_object_type
static int pyuw_sniffer(const struct frame_unwind *self, struct frame_info *this_frame, void **cache_ptr)
void gdbpy_convert_exception(struct gdb_exception exception)
static PyObject * pending_framepy_read_register(PyObject *self, PyObject *args)
static void pyuw_this_id(struct frame_info *this_frame, void **cache_ptr, struct frame_id *this_id)
static PyObject * unwind_infopy_add_saved_register(PyObject *self, PyObject *args)
void gdbpy_print_stack(void)
void get_user_print_options(struct value_print_options *opts)
void fprint_frame_id(struct ui_file *file, struct frame_id id)
PyObject_HEAD PyObject * pending_frame
enum unwind_stop_reason default_frame_unwind_stop_reason(struct frame_info *this_frame, void **this_cache)
int gdb_py_int_as_long(PyObject *obj, long *result)
int register_size(struct gdbarch *gdbarch, int regnum)
struct type * value_type(const struct value *value)
frame_this_id_ftype * this_id
struct cmd_list_element * showdebuglist
struct frame_id frame_id_build_wild(CORE_ADDR stack_addr)
struct value * value_object_to_value(PyObject *self)
const struct frame_data * unwind_data
#define TYPE_LENGTH(thistype)
struct cleanup * make_cleanup_py_decref(PyObject *py)
static void pending_frame_invalidate(void *pyo_pending_frame)
static int pyuw_parse_register_id(struct gdbarch *gdbarch, PyObject *pyo_reg_id, int *reg_num)
const char * core_addr_to_string_nz(const CORE_ADDR addr)
void error(const char *fmt,...)
struct gdbarch_data * gdbarch_data_register_post_init(gdbarch_data_post_init_ftype *post_init)
gdb_byte data[MAX_REGISTER_SIZE]
#define PyObject_HasAttrString(obj, attr)
void do_cleanups(struct cleanup *old_chain)
static int pyuw_value_obj_to_pointer(PyObject *pyo_value, CORE_ADDR *addr)
#define PyVarObject_HEAD_INIT(type, size)