Automatic Copyright Year update after running gdb/copyright.py
[binutils-gdb.git] / gdb / python / py-unwind.c
bloba884c83ec26985e38499ef8b490ec802c7c7c262
1 /* Python frame unwinder interface.
3 Copyright (C) 2015-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "defs.h"
21 #include "arch-utils.h"
22 #include "frame-unwind.h"
23 #include "gdb_obstack.h"
24 #include "gdbcmd.h"
25 #include "language.h"
26 #include "observable.h"
27 #include "python-internal.h"
28 #include "regcache.h"
29 #include "valprint.h"
30 #include "user-regs.h"
32 /* Debugging of Python unwinders. */
34 static bool pyuw_debug;
36 /* Implementation of "show debug py-unwind". */
38 static void
39 show_pyuw_debug (struct ui_file *file, int from_tty,
40 struct cmd_list_element *c, const char *value)
42 fprintf_filtered (file, _("Python unwinder debugging is %s.\n"), value);
45 /* Print a "py-unwind" debug statement. */
47 #define pyuw_debug_printf(fmt, ...) \
48 debug_prefixed_printf_cond (pyuw_debug, "py-unwind", fmt, ##__VA_ARGS__)
50 /* Print "py-unwind" enter/exit debug statements. */
52 #define PYUW_SCOPED_DEBUG_ENTER_EXIT \
53 scoped_debug_enter_exit (pyuw_debug, "py-unwind")
55 struct pending_frame_object
57 PyObject_HEAD
59 /* Frame we are unwinding. */
60 struct frame_info *frame_info;
62 /* Its architecture, passed by the sniffer caller. */
63 struct gdbarch *gdbarch;
66 /* Saved registers array item. */
68 struct saved_reg
70 saved_reg (int n, gdbpy_ref<> &&v)
71 : number (n),
72 value (std::move (v))
76 int number;
77 gdbpy_ref<> value;
80 /* The data we keep for the PyUnwindInfo: pending_frame, saved registers
81 and frame ID. */
83 struct unwind_info_object
85 PyObject_HEAD
87 /* gdb.PendingFrame for the frame we are unwinding. */
88 PyObject *pending_frame;
90 /* Its ID. */
91 struct frame_id frame_id;
93 /* Saved registers array. */
94 std::vector<saved_reg> *saved_regs;
97 /* The data we keep for a frame we can unwind: frame ID and an array of
98 (register_number, register_value) pairs. */
100 struct cached_frame_info
102 /* Frame ID. */
103 struct frame_id frame_id;
105 /* GDB Architecture. */
106 struct gdbarch *gdbarch;
108 /* Length of the `reg' array below. */
109 int reg_count;
111 cached_reg_t reg[];
114 extern PyTypeObject pending_frame_object_type
115 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("pending_frame_object");
117 extern PyTypeObject unwind_info_object_type
118 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("unwind_info_object");
120 static struct gdbarch_data *pyuw_gdbarch_data;
122 /* Convert gdb.Value instance to inferior's pointer. Return 1 on success,
123 0 on failure. */
125 static int
126 pyuw_value_obj_to_pointer (PyObject *pyo_value, CORE_ADDR *addr)
128 int rc = 0;
129 struct value *value;
133 if ((value = value_object_to_value (pyo_value)) != NULL)
135 *addr = unpack_pointer (value_type (value),
136 value_contents (value).data ());
137 rc = 1;
140 catch (const gdb_exception &except)
142 gdbpy_convert_exception (except);
144 return rc;
147 /* Get attribute from an object and convert it to the inferior's
148 pointer value. Return 1 if attribute exists and its value can be
149 converted. Otherwise, if attribute does not exist or its value is
150 None, return 0. In all other cases set Python error and return
151 0. */
153 static int
154 pyuw_object_attribute_to_pointer (PyObject *pyo, const char *attr_name,
155 CORE_ADDR *addr)
157 int rc = 0;
159 if (PyObject_HasAttrString (pyo, attr_name))
161 gdbpy_ref<> pyo_value (PyObject_GetAttrString (pyo, attr_name));
163 if (pyo_value != NULL && pyo_value != Py_None)
165 rc = pyuw_value_obj_to_pointer (pyo_value.get (), addr);
166 if (!rc)
167 PyErr_Format (
168 PyExc_ValueError,
169 _("The value of the '%s' attribute is not a pointer."),
170 attr_name);
173 return rc;
176 /* Called by the Python interpreter to obtain string representation
177 of the UnwindInfo object. */
179 static PyObject *
180 unwind_infopy_str (PyObject *self)
182 unwind_info_object *unwind_info = (unwind_info_object *) self;
183 string_file stb;
185 stb.printf ("Frame ID: %s", unwind_info->frame_id.to_string ().c_str ());
187 const char *sep = "";
188 struct value_print_options opts;
190 get_user_print_options (&opts);
191 stb.printf ("\nSaved registers: (");
192 for (const saved_reg &reg : *unwind_info->saved_regs)
194 struct value *value = value_object_to_value (reg.value.get ());
196 stb.printf ("%s(%d, ", sep, reg.number);
197 if (value != NULL)
201 value_print (value, &stb, &opts);
202 stb.puts (")");
204 catch (const gdb_exception &except)
206 GDB_PY_HANDLE_EXCEPTION (except);
209 else
210 stb.puts ("<BAD>)");
211 sep = ", ";
213 stb.puts (")");
216 return PyString_FromString (stb.c_str ());
219 /* Create UnwindInfo instance for given PendingFrame and frame ID.
220 Sets Python error and returns NULL on error. */
222 static PyObject *
223 pyuw_create_unwind_info (PyObject *pyo_pending_frame,
224 struct frame_id frame_id)
226 unwind_info_object *unwind_info
227 = PyObject_New (unwind_info_object, &unwind_info_object_type);
229 if (((pending_frame_object *) pyo_pending_frame)->frame_info == NULL)
231 PyErr_SetString (PyExc_ValueError,
232 "Attempting to use stale PendingFrame");
233 return NULL;
235 unwind_info->frame_id = frame_id;
236 Py_INCREF (pyo_pending_frame);
237 unwind_info->pending_frame = pyo_pending_frame;
238 unwind_info->saved_regs = new std::vector<saved_reg>;
239 return (PyObject *) unwind_info;
242 /* The implementation of
243 gdb.UnwindInfo.add_saved_register (REG, VALUE) -> None. */
245 static PyObject *
246 unwind_infopy_add_saved_register (PyObject *self, PyObject *args)
248 unwind_info_object *unwind_info = (unwind_info_object *) self;
249 pending_frame_object *pending_frame
250 = (pending_frame_object *) (unwind_info->pending_frame);
251 PyObject *pyo_reg_id;
252 PyObject *pyo_reg_value;
253 int regnum;
255 if (pending_frame->frame_info == NULL)
257 PyErr_SetString (PyExc_ValueError,
258 "UnwindInfo instance refers to a stale PendingFrame");
259 return NULL;
261 if (!PyArg_UnpackTuple (args, "previous_frame_register", 2, 2,
262 &pyo_reg_id, &pyo_reg_value))
263 return NULL;
264 if (!gdbpy_parse_register_id (pending_frame->gdbarch, pyo_reg_id, &regnum))
266 PyErr_SetString (PyExc_ValueError, "Bad register");
267 return NULL;
270 /* If REGNUM identifies a user register then *maybe* we can convert this
271 to a real (i.e. non-user) register. The maybe qualifier is because we
272 don't know what user registers each target might add, however, the
273 following logic should work for the usual style of user registers,
274 where the read function just forwards the register read on to some
275 other register with no adjusting the value. */
276 if (regnum >= gdbarch_num_cooked_regs (pending_frame->gdbarch))
278 struct value *user_reg_value
279 = value_of_user_reg (regnum, pending_frame->frame_info);
280 if (VALUE_LVAL (user_reg_value) == lval_register)
281 regnum = VALUE_REGNUM (user_reg_value);
282 if (regnum >= gdbarch_num_cooked_regs (pending_frame->gdbarch))
284 PyErr_SetString (PyExc_ValueError, "Bad register");
285 return NULL;
290 struct value *value;
291 size_t data_size;
293 if (pyo_reg_value == NULL
294 || (value = value_object_to_value (pyo_reg_value)) == NULL)
296 PyErr_SetString (PyExc_ValueError, "Bad register value");
297 return NULL;
299 data_size = register_size (pending_frame->gdbarch, regnum);
300 if (data_size != TYPE_LENGTH (value_type (value)))
302 PyErr_Format (
303 PyExc_ValueError,
304 "The value of the register returned by the Python "
305 "sniffer has unexpected size: %u instead of %u.",
306 (unsigned) TYPE_LENGTH (value_type (value)),
307 (unsigned) data_size);
308 return NULL;
312 gdbpy_ref<> new_value = gdbpy_ref<>::new_reference (pyo_reg_value);
313 bool found = false;
314 for (saved_reg &reg : *unwind_info->saved_regs)
316 if (regnum == reg.number)
318 found = true;
319 reg.value = std::move (new_value);
320 break;
323 if (!found)
324 unwind_info->saved_regs->emplace_back (regnum, std::move (new_value));
326 Py_RETURN_NONE;
329 /* UnwindInfo cleanup. */
331 static void
332 unwind_infopy_dealloc (PyObject *self)
334 unwind_info_object *unwind_info = (unwind_info_object *) self;
336 Py_XDECREF (unwind_info->pending_frame);
337 delete unwind_info->saved_regs;
338 Py_TYPE (self)->tp_free (self);
341 /* Called by the Python interpreter to obtain string representation
342 of the PendingFrame object. */
344 static PyObject *
345 pending_framepy_str (PyObject *self)
347 struct frame_info *frame = ((pending_frame_object *) self)->frame_info;
348 const char *sp_str = NULL;
349 const char *pc_str = NULL;
351 if (frame == NULL)
352 return PyString_FromString ("Stale PendingFrame instance");
355 sp_str = core_addr_to_string_nz (get_frame_sp (frame));
356 pc_str = core_addr_to_string_nz (get_frame_pc (frame));
358 catch (const gdb_exception &except)
360 GDB_PY_HANDLE_EXCEPTION (except);
363 return PyString_FromFormat ("SP=%s,PC=%s", sp_str, pc_str);
366 /* Implementation of gdb.PendingFrame.read_register (self, reg) -> gdb.Value.
367 Returns the value of register REG as gdb.Value instance. */
369 static PyObject *
370 pending_framepy_read_register (PyObject *self, PyObject *args)
372 pending_frame_object *pending_frame = (pending_frame_object *) self;
373 struct value *val = NULL;
374 int regnum;
375 PyObject *pyo_reg_id;
377 if (pending_frame->frame_info == NULL)
379 PyErr_SetString (PyExc_ValueError,
380 "Attempting to read register from stale PendingFrame");
381 return NULL;
383 if (!PyArg_UnpackTuple (args, "read_register", 1, 1, &pyo_reg_id))
384 return NULL;
385 if (!gdbpy_parse_register_id (pending_frame->gdbarch, pyo_reg_id, &regnum))
387 PyErr_SetString (PyExc_ValueError, "Bad register");
388 return NULL;
393 /* Fetch the value associated with a register, whether it's
394 a real register or a so called "user" register, like "pc",
395 which maps to a real register. In the past,
396 get_frame_register_value() was used here, which did not
397 handle the user register case. */
398 val = value_of_register (regnum, pending_frame->frame_info);
399 if (val == NULL)
400 PyErr_Format (PyExc_ValueError,
401 "Cannot read register %d from frame.",
402 regnum);
404 catch (const gdb_exception &except)
406 GDB_PY_HANDLE_EXCEPTION (except);
409 return val == NULL ? NULL : value_to_value_object (val);
412 /* Implementation of
413 PendingFrame.create_unwind_info (self, frameId) -> UnwindInfo. */
415 static PyObject *
416 pending_framepy_create_unwind_info (PyObject *self, PyObject *args)
418 PyObject *pyo_frame_id;
419 CORE_ADDR sp;
420 CORE_ADDR pc;
421 CORE_ADDR special;
423 if (!PyArg_ParseTuple (args, "O:create_unwind_info", &pyo_frame_id))
424 return NULL;
425 if (!pyuw_object_attribute_to_pointer (pyo_frame_id, "sp", &sp))
427 PyErr_SetString (PyExc_ValueError,
428 _("frame_id should have 'sp' attribute."));
429 return NULL;
432 /* The logic of building frame_id depending on the attributes of
433 the frame_id object:
434 Has Has Has Function to call
435 'sp'? 'pc'? 'special'?
436 ------|------|--------------|-------------------------
437 Y N * frame_id_build_wild (sp)
438 Y Y N frame_id_build (sp, pc)
439 Y Y Y frame_id_build_special (sp, pc, special)
441 if (!pyuw_object_attribute_to_pointer (pyo_frame_id, "pc", &pc))
442 return pyuw_create_unwind_info (self, frame_id_build_wild (sp));
443 if (!pyuw_object_attribute_to_pointer (pyo_frame_id, "special", &special))
444 return pyuw_create_unwind_info (self, frame_id_build (sp, pc));
445 else
446 return pyuw_create_unwind_info (self,
447 frame_id_build_special (sp, pc, special));
450 /* Implementation of PendingFrame.architecture (self) -> gdb.Architecture. */
452 static PyObject *
453 pending_framepy_architecture (PyObject *self, PyObject *args)
455 pending_frame_object *pending_frame = (pending_frame_object *) self;
457 if (pending_frame->frame_info == NULL)
459 PyErr_SetString (PyExc_ValueError,
460 "Attempting to read register from stale PendingFrame");
461 return NULL;
463 return gdbarch_to_arch_object (pending_frame->gdbarch);
466 /* Implementation of PendingFrame.level (self) -> Integer. */
468 static PyObject *
469 pending_framepy_level (PyObject *self, PyObject *args)
471 pending_frame_object *pending_frame = (pending_frame_object *) self;
473 if (pending_frame->frame_info == NULL)
475 PyErr_SetString (PyExc_ValueError,
476 "Attempting to read stack level from stale PendingFrame");
477 return NULL;
479 int level = frame_relative_level (pending_frame->frame_info);
480 return gdb_py_object_from_longest (level).release ();
483 /* frame_unwind.this_id method. */
485 static void
486 pyuw_this_id (struct frame_info *this_frame, void **cache_ptr,
487 struct frame_id *this_id)
489 *this_id = ((cached_frame_info *) *cache_ptr)->frame_id;
490 pyuw_debug_printf ("frame_id: %s", this_id->to_string ().c_str ());
493 /* frame_unwind.prev_register. */
495 static struct value *
496 pyuw_prev_register (struct frame_info *this_frame, void **cache_ptr,
497 int regnum)
499 PYUW_SCOPED_DEBUG_ENTER_EXIT;
501 cached_frame_info *cached_frame = (cached_frame_info *) *cache_ptr;
502 cached_reg_t *reg_info = cached_frame->reg;
503 cached_reg_t *reg_info_end = reg_info + cached_frame->reg_count;
505 pyuw_debug_printf ("frame=%d, reg=%d",
506 frame_relative_level (this_frame), regnum);
507 for (; reg_info < reg_info_end; ++reg_info)
509 if (regnum == reg_info->num)
510 return frame_unwind_got_bytes (this_frame, regnum, reg_info->data);
513 return frame_unwind_got_optimized (this_frame, regnum);
516 /* Frame sniffer dispatch. */
518 static int
519 pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame,
520 void **cache_ptr)
522 PYUW_SCOPED_DEBUG_ENTER_EXIT;
524 struct gdbarch *gdbarch = (struct gdbarch *) (self->unwind_data);
525 cached_frame_info *cached_frame;
527 gdbpy_enter enter_py (gdbarch, current_language);
529 pyuw_debug_printf ("frame=%d, sp=%s, pc=%s",
530 frame_relative_level (this_frame),
531 paddress (gdbarch, get_frame_sp (this_frame)),
532 paddress (gdbarch, get_frame_pc (this_frame)));
534 /* Create PendingFrame instance to pass to sniffers. */
535 pending_frame_object *pfo = PyObject_New (pending_frame_object,
536 &pending_frame_object_type);
537 gdbpy_ref<> pyo_pending_frame ((PyObject *) pfo);
538 if (pyo_pending_frame == NULL)
540 gdbpy_print_stack ();
541 return 0;
543 pfo->gdbarch = gdbarch;
544 scoped_restore invalidate_frame = make_scoped_restore (&pfo->frame_info,
545 this_frame);
547 /* Run unwinders. */
548 if (gdb_python_module == NULL
549 || ! PyObject_HasAttrString (gdb_python_module, "_execute_unwinders"))
551 PyErr_SetString (PyExc_NameError,
552 "Installation error: gdb._execute_unwinders function "
553 "is missing");
554 gdbpy_print_stack ();
555 return 0;
557 gdbpy_ref<> pyo_execute (PyObject_GetAttrString (gdb_python_module,
558 "_execute_unwinders"));
559 if (pyo_execute == nullptr)
561 gdbpy_print_stack ();
562 return 0;
565 /* A (gdb.UnwindInfo, str) tuple, or None. */
566 gdbpy_ref<> pyo_execute_ret
567 (PyObject_CallFunctionObjArgs (pyo_execute.get (),
568 pyo_pending_frame.get (), NULL));
569 if (pyo_execute_ret == nullptr)
571 /* If the unwinder is cancelled due to a Ctrl-C, then propagate
572 the Ctrl-C as a GDB exception instead of swallowing it. */
573 gdbpy_print_stack_or_quit ();
574 return 0;
576 if (pyo_execute_ret == Py_None)
577 return 0;
579 /* Verify the return value of _execute_unwinders is a tuple of size 2. */
580 gdb_assert (PyTuple_Check (pyo_execute_ret.get ()));
581 gdb_assert (PyTuple_GET_SIZE (pyo_execute_ret.get ()) == 2);
583 if (pyuw_debug)
585 PyObject *pyo_unwinder_name = PyTuple_GET_ITEM (pyo_execute_ret.get (), 1);
586 gdb::unique_xmalloc_ptr<char> name
587 = python_string_to_host_string (pyo_unwinder_name);
589 /* This could happen if the user passed something else than a string
590 as the unwinder's name. */
591 if (name == nullptr)
593 gdbpy_print_stack ();
594 name = make_unique_xstrdup ("<failed to get unwinder name>");
597 pyuw_debug_printf ("frame claimed by unwinder %s", name.get ());
600 /* Received UnwindInfo, cache data. */
601 PyObject *pyo_unwind_info = PyTuple_GET_ITEM (pyo_execute_ret.get (), 0);
602 if (PyObject_IsInstance (pyo_unwind_info,
603 (PyObject *) &unwind_info_object_type) <= 0)
604 error (_("A Unwinder should return gdb.UnwindInfo instance."));
607 unwind_info_object *unwind_info =
608 (unwind_info_object *) pyo_unwind_info;
609 int reg_count = unwind_info->saved_regs->size ();
611 cached_frame
612 = ((cached_frame_info *)
613 xmalloc (sizeof (*cached_frame)
614 + reg_count * sizeof (cached_frame->reg[0])));
615 cached_frame->gdbarch = gdbarch;
616 cached_frame->frame_id = unwind_info->frame_id;
617 cached_frame->reg_count = reg_count;
619 /* Populate registers array. */
620 for (int i = 0; i < unwind_info->saved_regs->size (); ++i)
622 saved_reg *reg = &(*unwind_info->saved_regs)[i];
624 struct value *value = value_object_to_value (reg->value.get ());
625 size_t data_size = register_size (gdbarch, reg->number);
627 cached_frame->reg[i].num = reg->number;
629 /* `value' validation was done before, just assert. */
630 gdb_assert (value != NULL);
631 gdb_assert (data_size == TYPE_LENGTH (value_type (value)));
633 cached_frame->reg[i].data = (gdb_byte *) xmalloc (data_size);
634 memcpy (cached_frame->reg[i].data,
635 value_contents (value).data (), data_size);
639 *cache_ptr = cached_frame;
640 return 1;
643 /* Frame cache release shim. */
645 static void
646 pyuw_dealloc_cache (struct frame_info *this_frame, void *cache)
648 PYUW_SCOPED_DEBUG_ENTER_EXIT;
649 cached_frame_info *cached_frame = (cached_frame_info *) cache;
651 for (int i = 0; i < cached_frame->reg_count; i++)
652 xfree (cached_frame->reg[i].data);
654 xfree (cache);
657 struct pyuw_gdbarch_data_type
659 /* Has the unwinder shim been prepended? */
660 int unwinder_registered;
663 static void *
664 pyuw_gdbarch_data_init (struct gdbarch *gdbarch)
666 return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct pyuw_gdbarch_data_type);
669 /* New inferior architecture callback: register the Python unwinders
670 intermediary. */
672 static void
673 pyuw_on_new_gdbarch (struct gdbarch *newarch)
675 struct pyuw_gdbarch_data_type *data
676 = (struct pyuw_gdbarch_data_type *) gdbarch_data (newarch,
677 pyuw_gdbarch_data);
679 if (!data->unwinder_registered)
681 struct frame_unwind *unwinder
682 = GDBARCH_OBSTACK_ZALLOC (newarch, struct frame_unwind);
684 unwinder->name = "python";
685 unwinder->type = NORMAL_FRAME;
686 unwinder->stop_reason = default_frame_unwind_stop_reason;
687 unwinder->this_id = pyuw_this_id;
688 unwinder->prev_register = pyuw_prev_register;
689 unwinder->unwind_data = (const struct frame_data *) newarch;
690 unwinder->sniffer = pyuw_sniffer;
691 unwinder->dealloc_cache = pyuw_dealloc_cache;
692 frame_unwind_prepend_unwinder (newarch, unwinder);
693 data->unwinder_registered = 1;
697 void _initialize_py_unwind ();
698 void
699 _initialize_py_unwind ()
701 add_setshow_boolean_cmd
702 ("py-unwind", class_maintenance, &pyuw_debug,
703 _("Set Python unwinder debugging."),
704 _("Show Python unwinder debugging."),
705 _("When on, Python unwinder debugging is enabled."),
706 NULL,
707 show_pyuw_debug,
708 &setdebuglist, &showdebuglist);
709 pyuw_gdbarch_data
710 = gdbarch_data_register_post_init (pyuw_gdbarch_data_init);
713 /* Initialize unwind machinery. */
716 gdbpy_initialize_unwind (void)
718 gdb::observers::architecture_changed.attach (pyuw_on_new_gdbarch,
719 "py-unwind");
721 if (PyType_Ready (&pending_frame_object_type) < 0)
722 return -1;
723 int rc = gdb_pymodule_addobject (gdb_module, "PendingFrame",
724 (PyObject *) &pending_frame_object_type);
725 if (rc != 0)
726 return rc;
728 if (PyType_Ready (&unwind_info_object_type) < 0)
729 return -1;
730 return gdb_pymodule_addobject (gdb_module, "UnwindInfo",
731 (PyObject *) &unwind_info_object_type);
734 static PyMethodDef pending_frame_object_methods[] =
736 { "read_register", pending_framepy_read_register, METH_VARARGS,
737 "read_register (REG) -> gdb.Value\n"
738 "Return the value of the REG in the frame." },
739 { "create_unwind_info",
740 pending_framepy_create_unwind_info, METH_VARARGS,
741 "create_unwind_info (FRAME_ID) -> gdb.UnwindInfo\n"
742 "Construct UnwindInfo for this PendingFrame, using FRAME_ID\n"
743 "to identify it." },
744 { "architecture",
745 pending_framepy_architecture, METH_NOARGS,
746 "architecture () -> gdb.Architecture\n"
747 "The architecture for this PendingFrame." },
748 { "level", pending_framepy_level, METH_NOARGS,
749 "The stack level of this frame." },
750 {NULL} /* Sentinel */
753 PyTypeObject pending_frame_object_type =
755 PyVarObject_HEAD_INIT (NULL, 0)
756 "gdb.PendingFrame", /* tp_name */
757 sizeof (pending_frame_object), /* tp_basicsize */
758 0, /* tp_itemsize */
759 0, /* tp_dealloc */
760 0, /* tp_print */
761 0, /* tp_getattr */
762 0, /* tp_setattr */
763 0, /* tp_compare */
764 0, /* tp_repr */
765 0, /* tp_as_number */
766 0, /* tp_as_sequence */
767 0, /* tp_as_mapping */
768 0, /* tp_hash */
769 0, /* tp_call */
770 pending_framepy_str, /* tp_str */
771 0, /* tp_getattro */
772 0, /* tp_setattro */
773 0, /* tp_as_buffer */
774 Py_TPFLAGS_DEFAULT, /* tp_flags */
775 "GDB PendingFrame object", /* tp_doc */
776 0, /* tp_traverse */
777 0, /* tp_clear */
778 0, /* tp_richcompare */
779 0, /* tp_weaklistoffset */
780 0, /* tp_iter */
781 0, /* tp_iternext */
782 pending_frame_object_methods, /* tp_methods */
783 0, /* tp_members */
784 0, /* tp_getset */
785 0, /* tp_base */
786 0, /* tp_dict */
787 0, /* tp_descr_get */
788 0, /* tp_descr_set */
789 0, /* tp_dictoffset */
790 0, /* tp_init */
791 0, /* tp_alloc */
794 static PyMethodDef unwind_info_object_methods[] =
796 { "add_saved_register",
797 unwind_infopy_add_saved_register, METH_VARARGS,
798 "add_saved_register (REG, VALUE) -> None\n"
799 "Set the value of the REG in the previous frame to VALUE." },
800 { NULL } /* Sentinel */
803 PyTypeObject unwind_info_object_type =
805 PyVarObject_HEAD_INIT (NULL, 0)
806 "gdb.UnwindInfo", /* tp_name */
807 sizeof (unwind_info_object), /* tp_basicsize */
808 0, /* tp_itemsize */
809 unwind_infopy_dealloc, /* tp_dealloc */
810 0, /* tp_print */
811 0, /* tp_getattr */
812 0, /* tp_setattr */
813 0, /* tp_compare */
814 0, /* tp_repr */
815 0, /* tp_as_number */
816 0, /* tp_as_sequence */
817 0, /* tp_as_mapping */
818 0, /* tp_hash */
819 0, /* tp_call */
820 unwind_infopy_str, /* tp_str */
821 0, /* tp_getattro */
822 0, /* tp_setattro */
823 0, /* tp_as_buffer */
824 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
825 "GDB UnwindInfo object", /* tp_doc */
826 0, /* tp_traverse */
827 0, /* tp_clear */
828 0, /* tp_richcompare */
829 0, /* tp_weaklistoffset */
830 0, /* tp_iter */
831 0, /* tp_iternext */
832 unwind_info_object_methods, /* tp_methods */
833 0, /* tp_members */
834 0, /* tp_getset */
835 0, /* tp_base */
836 0, /* tp_dict */
837 0, /* tp_descr_get */
838 0, /* tp_descr_set */
839 0, /* tp_dictoffset */
840 0, /* tp_init */
841 0, /* tp_alloc */