23#include "gdbsupport/gdb_obstack.h"
51#define pyuw_debug_printf(fmt, ...) \
52 debug_prefixed_printf_cond (pyuw_debug, "py-unwind", fmt, ##__VA_ARGS__)
56#define PYUW_SCOPED_DEBUG_ENTER_EXIT \
57 scoped_debug_enter_exit (pyuw_debug, "py-unwind")
60#define PENDING_FRAMEPY_REQUIRE_VALID(pending_frame) \
62 if ((pending_frame)->frame_info == nullptr) \
64 PyErr_SetString (PyExc_ValueError, \
65 _("gdb.PendingFrame is invalid.")); \
173 if (!PyObject_HasAttrString (pyo, attr_name))
176 gdbpy_ref<> pyo_value (PyObject_GetAttrString (pyo, attr_name));
177 if (pyo_value ==
nullptr)
179 gdb_assert (PyErr_Occurred ());
182 if (pyo_value == Py_None)
187 gdb_assert (PyErr_Occurred ());
205 const char *sep =
"";
209 stb.
printf (
"\nSaved registers: (");
222 catch (
const gdb_exception &except)
234 return PyUnicode_FromString (stb.
c_str ());
247 if (frame ==
nullptr)
248 return PyUnicode_FromFormat (
"<%s for an invalid frame>",
249 Py_TYPE (self)->tp_name);
251 std::string saved_reg_names;
257 if (saved_reg_names.empty ())
258 saved_reg_names =
name;
260 saved_reg_names = (saved_reg_names +
", ") +
name;
263 return PyUnicode_FromFormat (
"<%s frame #%d, saved_regs=(%s)>",
264 Py_TYPE (self)->tp_name,
266 saved_reg_names.c_str ());
285 Py_INCREF (pyo_pending_frame);
287 unwind_info->
saved_regs =
new std::vector<saved_reg>;
306 PyErr_SetString (PyExc_ValueError,
307 "UnwindInfo instance refers to a stale PendingFrame");
311 static const char *keywords[] = {
"register",
"value",
nullptr };
328 struct value *user_reg_value
334 PyErr_SetString (PyExc_ValueError,
"Bad register");
342 gdb_assert (pyo_reg_value !=
nullptr);
344 gdb_assert (
value !=
nullptr);
349 PyErr_Format (PyExc_ValueError,
350 "The value of the register returned by the Python "
351 "sniffer has unexpected size: %s instead of %s.",
353 pulongest (reg_size));
364 reg.value = std::move (new_value);
383 Py_TYPE (self)->tp_free (self);
393 const char *sp_str = NULL;
394 const char *pc_str = NULL;
397 return PyUnicode_FromString (
"Stale PendingFrame instance");
403 catch (
const gdb_exception &except)
408 return PyUnicode_FromFormat (
"SP=%s,PC=%s", sp_str, pc_str);
419 if (frame ==
nullptr)
420 return PyUnicode_FromFormat (
"<%s (invalid)>", Py_TYPE (self)->tp_name);
422 const char *sp_str =
nullptr;
423 const char *pc_str =
nullptr;
430 catch (
const gdb_exception &except)
435 return PyUnicode_FromFormat (
"<%s level=%d, sp=%s, pc=%s>",
436 Py_TYPE (self)->tp_name,
452 static const char *keywords[] = {
"register",
nullptr };
473 PyErr_Format (PyExc_ValueError,
474 "Cannot read register %d from frame.",
479 catch (
const gdb_exception &except)
511 gdb::unique_xmalloc_ptr<char>
name;
520 catch (
const gdb_exception &except)
526 return PyUnicode_Decode (
name.get (), strlen (
name.get ()),
548 catch (
const gdb_exception &except)
575 catch (
const gdb_exception &except)
602 catch (
const gdb_exception &except)
621 const struct block *
block =
nullptr, *fn_block;
627 catch (
const gdb_exception &except)
632 for (fn_block =
block;
633 fn_block !=
nullptr && fn_block->
function () ==
nullptr;
634 fn_block = fn_block->superblock ())
638 || fn_block ==
nullptr
639 || fn_block->
function () ==
nullptr)
641 PyErr_SetString (PyExc_RuntimeError,
642 _(
"Cannot locate block for frame."));
660 struct symbol *sym =
nullptr;
667 gdb::unique_xmalloc_ptr<char> funname
670 catch (
const gdb_exception &except)
695 static const char *keywords[] = {
"frame_id",
nullptr };
704 PyErr_SetString (PyExc_ValueError,
705 _(
"frame_id should have 'sp' attribute."));
785 for (; reg_info < reg_info_end; ++reg_info)
816 if (pyo_pending_frame == NULL)
823 scoped_restore invalidate_frame = make_scoped_restore (&pfo->
frame_info,
830 PyErr_SetString (PyExc_NameError,
831 "Installation error: gdb._execute_unwinders function "
837 "_execute_unwinders"));
838 if (pyo_execute ==
nullptr)
846 (PyObject_CallFunctionObjArgs (pyo_execute.get (),
847 pyo_pending_frame.get (), NULL));
848 if (pyo_execute_ret ==
nullptr)
855 if (pyo_execute_ret == Py_None)
859 gdb_assert (PyTuple_Check (pyo_execute_ret.get ()));
860 gdb_assert (PyTuple_GET_SIZE (pyo_execute_ret.get ()) == 2);
864 PyObject *pyo_unwinder_name = PyTuple_GET_ITEM (pyo_execute_ret.get (), 1);
865 gdb::unique_xmalloc_ptr<char>
name
873 name = make_unique_xstrdup (
"<failed to get unwinder name>");
880 PyObject *pyo_unwind_info = PyTuple_GET_ITEM (pyo_execute_ret.get (), 0);
881 if (PyObject_IsInstance (pyo_unwind_info,
883 error (_(
"A Unwinder should return gdb.UnwindInfo instance."));
888 int reg_count = unwind_info->
saved_regs->size ();
892 xmalloc (
sizeof (*cached_frame)
893 + reg_count *
sizeof (cached_frame->
reg[0])));
899 for (
int i = 0; i < unwind_info->
saved_regs->size (); ++i)
909 gdb_assert (
value != NULL);
913 memcpy (cached_frame->
reg[i].
data,
918 *cache_ptr = cached_frame;
930 for (
int i = 0; i < cached_frame->
reg_count; i++)
954 if (!data->unwinder_registered)
959 unwinder->
name =
"python";
968 data->unwinder_registered = 1;
999 _(
"Set Python unwinder debugging."),
1000 _(
"Show Python unwinder debugging."),
1001 _(
"When on, Python unwinder debugging is enabled."),
1014 METH_VARARGS | METH_KEYWORDS,
1015 "read_register (REG) -> gdb.Value\n"
1016 "Return the value of the REG in the frame." },
1018 METH_VARARGS | METH_KEYWORDS,
1019 "create_unwind_info (FRAME_ID) -> gdb.UnwindInfo\n"
1020 "Construct UnwindInfo for this PendingFrame, using FRAME_ID\n"
1021 "to identify it." },
1024 "architecture () -> gdb.Architecture\n"
1025 "The architecture for this PendingFrame." },
1028 "name() -> String.\n\
1029Return the function name of the frame, or None if it can't be determined." },
1032 "is_valid () -> Boolean.\n\
1033Return true if this PendingFrame is valid, false if not." },
1037Return the frame's resume address." },
1039 "The language of this frame." },
1041 "find_sal () -> gdb.Symtab_and_line.\n\
1042Return the frame's symtab and line." },
1044 "block () -> gdb.Block.\n\
1045Return the frame's code block." },
1047 "function () -> gdb.Symbol.\n\
1048Returns the symbol for the function corresponding to this frame." },
1050 "The stack level of this frame." },
1056 PyVarObject_HEAD_INIT (NULL, 0)
1076 "GDB PendingFrame object",
1097 {
"add_saved_register",
1099 METH_VARARGS | METH_KEYWORDS,
1100 "add_saved_register (REG, VALUE) -> None\n"
1101 "Set the value of the REG in the previous frame to VALUE." },
1107 PyVarObject_HEAD_INIT (NULL, 0)
1127 "GDB UnwindInfo object",
const struct block * get_frame_block(frame_info_ptr frame, CORE_ADDR *addr_in_block)
const char * host_charset(void)
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)
enum language get_frame_language(frame_info_ptr frame)
symtab_and_line find_frame_sal(frame_info_ptr frame)
const char * gdbarch_register_name(struct gdbarch *gdbarch, int regnr)
#define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE)
static int gdbarch_num_cooked_regs(gdbarch *arch)
const struct language_defn * language_def(enum language lang)
observable< struct gdbarch * > architecture_changed
PyObject * gdbarch_to_arch_object(struct gdbarch *gdbarch)
PyObject * block_to_block_object(const struct block *block, struct objfile *objfile)
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)
PyObject * symbol_to_symbol_object(struct symbol *sym)
PyObject * symtab_and_line_to_sal_object(struct symtab_and_line sal)
static void pyuw_on_new_gdbarch(struct gdbarch *newarch)
static PyObject * pending_framepy_read_register(PyObject *self, PyObject *args, PyObject *kw)
#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 int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION gdbpy_initialize_unwind(void)
static void show_pyuw_debug(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static PyObject * pending_framepy_repr(PyObject *self)
static PyObject * pending_framepy_level(PyObject *self, PyObject *args)
PyTypeObject pending_frame_object_type
static pyuw_get_attr_code pyuw_object_attribute_to_pointer(PyObject *pyo, const char *attr_name, CORE_ADDR *addr)
#define PENDING_FRAMEPY_REQUIRE_VALID(pending_frame)
static const registry< gdbarch >::key< pyuw_gdbarch_data_type > pyuw_gdbarch_data
static PyObject * unwind_infopy_add_saved_register(PyObject *self, PyObject *args, PyObject *kw)
static PyObject * pending_framepy_function(PyObject *self, PyObject *args)
static PyObject * pending_framepy_str(PyObject *self)
static PyObject * pending_framepy_name(PyObject *self, PyObject *args)
static struct value * pyuw_prev_register(frame_info_ptr this_frame, void **cache_ptr, int regnum)
static PyObject * pending_framepy_create_unwind_info(PyObject *self, PyObject *args, PyObject *kw)
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[]
static void unwind_infopy_dealloc(PyObject *self)
static PyObject * pending_framepy_block(PyObject *self, PyObject *args)
static PyObject * unwind_infopy_repr(PyObject *self)
static PyObject * pending_framepy_find_sal(PyObject *self, PyObject *args)
static PyObject * unwind_infopy_str(PyObject *self)
PyTypeObject unwind_info_object_type
static PyObject * pending_framepy_is_valid(PyObject *self, PyObject *args)
static PyObject * pending_framepy_architecture(PyObject *self, PyObject *args)
void _initialize_py_unwind()
static PyObject * pending_framepy_language(PyObject *self, PyObject *args)
static PyObject * pending_framepy_pc(PyObject *self, PyObject *args)
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 host_string_to_python_string(const char *str)
gdbpy_ref gdb_py_object_from_longest(LONGEST l)
int get_addr_from_python(PyObject *obj, CORE_ADDR *addr)
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
gdbpy_ref gdb_py_object_from_ulongest(ULONGEST l)
PyObject * value_to_value_object(struct value *val)
struct value * value_object_to_value(PyObject *self)
PyTypeObject value_object_type
void gdbpy_print_stack(void)
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
void gdbpy_print_stack_or_quit()
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
#define GDBPY_INITIALIZE_FILE(INIT,...)
PyObject * gdb_python_module
#define GDB_PY_HANDLE_EXCEPTION(Exception)
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
int register_size(struct gdbarch *gdbarch, int regnum)
gdb::unique_xmalloc_ptr< char > find_frame_funname(frame_info_ptr frame, enum language *funlang, struct symbol **funcp)
symbol * function() const
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
virtual const char * name() const =0
PyObject_HEAD frame_info_ptr frame_info
saved_reg(int n, gdbpy_ref<> &&v)
struct objfile * objfile() const
std::vector< saved_reg > * saved_regs
PyObject_HEAD PyObject * pending_frame
gdb::array_view< const gdb_byte > contents()
struct type * type() const
enum lval_type lval() const
struct value::@203::@204 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)
#define VALUE_REGNUM(val)