]> Git Repo - binutils.git/blob - gdb/python/py-unwind.c
gdb: remove SYMTAB_COMPUNIT macro, add getter/setter
[binutils.git] / gdb / python / py-unwind.c
1 /* Python frame unwinder interface.
2
3    Copyright (C) 2015-2022 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
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.
11
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.
16
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/>.  */
19
20 #include "defs.h"
21 #include "arch-utils.h"
22 #include "frame-unwind.h"
23 #include "gdbsupport/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"
31
32 /* Debugging of Python unwinders.  */
33
34 static bool pyuw_debug;
35
36 /* Implementation of "show debug py-unwind".  */
37
38 static void
39 show_pyuw_debug (struct ui_file *file, int from_tty,
40                  struct cmd_list_element *c, const char *value)
41 {
42   fprintf_filtered (file, _("Python unwinder debugging is %s.\n"), value);
43 }
44
45 /* Print a "py-unwind" debug statement.  */
46
47 #define pyuw_debug_printf(fmt, ...) \
48   debug_prefixed_printf_cond (pyuw_debug, "py-unwind", fmt, ##__VA_ARGS__)
49
50 /* Print "py-unwind" enter/exit debug statements.  */
51
52 #define PYUW_SCOPED_DEBUG_ENTER_EXIT \
53   scoped_debug_enter_exit (pyuw_debug, "py-unwind")
54
55 struct pending_frame_object
56 {
57   PyObject_HEAD
58
59   /* Frame we are unwinding.  */
60   struct frame_info *frame_info;
61
62   /* Its architecture, passed by the sniffer caller.  */
63   struct gdbarch *gdbarch;
64 };
65
66 /* Saved registers array item.  */
67
68 struct saved_reg
69 {
70   saved_reg (int n, gdbpy_ref<> &&v)
71     : number (n),
72       value (std::move (v))
73   {
74   }
75
76   int number;
77   gdbpy_ref<> value;
78 };
79
80 /* The data we keep for the PyUnwindInfo: pending_frame, saved registers
81    and frame ID.  */
82
83 struct unwind_info_object
84 {
85   PyObject_HEAD
86
87   /* gdb.PendingFrame for the frame we are unwinding.  */
88   PyObject *pending_frame;
89
90   /* Its ID.  */
91   struct frame_id frame_id;
92
93   /* Saved registers array.  */
94   std::vector<saved_reg> *saved_regs;
95 };
96
97 /* The data we keep for a frame we can unwind: frame ID and an array of
98    (register_number, register_value) pairs.  */
99
100 struct cached_frame_info
101 {
102   /* Frame ID.  */
103   struct frame_id frame_id;
104
105   /* GDB Architecture.  */
106   struct gdbarch *gdbarch;
107
108   /* Length of the `reg' array below.  */
109   int reg_count;
110
111   cached_reg_t reg[];
112 };
113
114 extern PyTypeObject pending_frame_object_type
115     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("pending_frame_object");
116
117 extern PyTypeObject unwind_info_object_type
118     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("unwind_info_object");
119
120 static struct gdbarch_data *pyuw_gdbarch_data;
121
122 /* Convert gdb.Value instance to inferior's pointer.  Return 1 on success,
123    0 on failure.  */
124
125 static int
126 pyuw_value_obj_to_pointer (PyObject *pyo_value, CORE_ADDR *addr)
127 {
128   int rc = 0;
129   struct value *value;
130
131   try
132     {
133       if ((value = value_object_to_value (pyo_value)) != NULL)
134         {
135           *addr = unpack_pointer (value_type (value),
136                                   value_contents (value).data ());
137           rc = 1;
138         }
139     }
140   catch (const gdb_exception &except)
141     {
142       gdbpy_convert_exception (except);
143     }
144   return rc;
145 }
146
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.  */
152
153 static int
154 pyuw_object_attribute_to_pointer (PyObject *pyo, const char *attr_name,
155                                   CORE_ADDR *addr)
156 {
157   int rc = 0;
158
159   if (PyObject_HasAttrString (pyo, attr_name))
160     {
161       gdbpy_ref<> pyo_value (PyObject_GetAttrString (pyo, attr_name));
162
163       if (pyo_value != NULL && pyo_value != Py_None)
164         {
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);
171         }
172     }
173   return rc;
174 }
175
176 /* Called by the Python interpreter to obtain string representation
177    of the UnwindInfo object.  */
178
179 static PyObject *
180 unwind_infopy_str (PyObject *self)
181 {
182   unwind_info_object *unwind_info = (unwind_info_object *) self;
183   string_file stb;
184
185   stb.printf ("Frame ID: %s", unwind_info->frame_id.to_string ().c_str ());
186   {
187     const char *sep = "";
188     struct value_print_options opts;
189
190     get_user_print_options (&opts);
191     stb.printf ("\nSaved registers: (");
192     for (const saved_reg &reg : *unwind_info->saved_regs)
193       {
194         struct value *value = value_object_to_value (reg.value.get ());
195
196         stb.printf ("%s(%d, ", sep, reg.number);
197         if (value != NULL)
198           {
199             try
200               {
201                 value_print (value, &stb, &opts);
202                 stb.puts (")");
203               }
204             catch (const gdb_exception &except)
205               {
206                 GDB_PY_HANDLE_EXCEPTION (except);
207               }
208           }
209         else
210           stb.puts ("<BAD>)");
211         sep = ", ";
212       }
213     stb.puts (")");
214   }
215
216   return PyString_FromString (stb.c_str ());
217 }
218
219 /* Create UnwindInfo instance for given PendingFrame and frame ID.
220    Sets Python error and returns NULL on error.  */
221
222 static PyObject *
223 pyuw_create_unwind_info (PyObject *pyo_pending_frame,
224                          struct frame_id frame_id)
225 {
226   unwind_info_object *unwind_info
227       = PyObject_New (unwind_info_object, &unwind_info_object_type);
228
229   if (((pending_frame_object *) pyo_pending_frame)->frame_info == NULL)
230     {
231       PyErr_SetString (PyExc_ValueError,
232                        "Attempting to use stale PendingFrame");
233       return NULL;
234     }
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;
240 }
241
242 /* The implementation of
243    gdb.UnwindInfo.add_saved_register (REG, VALUE) -> None.  */
244
245 static PyObject *
246 unwind_infopy_add_saved_register (PyObject *self, PyObject *args)
247 {
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;
254
255   if (pending_frame->frame_info == NULL)
256     {
257       PyErr_SetString (PyExc_ValueError,
258                        "UnwindInfo instance refers to a stale PendingFrame");
259       return NULL;
260     }
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))
265     {
266       PyErr_SetString (PyExc_ValueError, "Bad register");
267       return NULL;
268     }
269
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))
277     {
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))
283         {
284           PyErr_SetString (PyExc_ValueError, "Bad register");
285           return NULL;
286         }
287     }
288
289   {
290     struct value *value;
291     size_t data_size;
292
293     if (pyo_reg_value == NULL
294       || (value = value_object_to_value (pyo_reg_value)) == NULL)
295       {
296         PyErr_SetString (PyExc_ValueError, "Bad register value");
297         return NULL;
298       }
299     data_size = register_size (pending_frame->gdbarch, regnum);
300     if (data_size != TYPE_LENGTH (value_type (value)))
301       {
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;
309       }
310   }
311   {
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)
315       {
316         if (regnum == reg.number)
317           {
318             found = true;
319             reg.value = std::move (new_value);
320             break;
321           }
322       }
323     if (!found)
324       unwind_info->saved_regs->emplace_back (regnum, std::move (new_value));
325   }
326   Py_RETURN_NONE;
327 }
328
329 /* UnwindInfo cleanup.  */
330
331 static void
332 unwind_infopy_dealloc (PyObject *self)
333 {
334   unwind_info_object *unwind_info = (unwind_info_object *) self;
335
336   Py_XDECREF (unwind_info->pending_frame);
337   delete unwind_info->saved_regs;
338   Py_TYPE (self)->tp_free (self);
339 }
340
341 /* Called by the Python interpreter to obtain string representation
342    of the PendingFrame object.  */
343
344 static PyObject *
345 pending_framepy_str (PyObject *self)
346 {
347   struct frame_info *frame = ((pending_frame_object *) self)->frame_info;
348   const char *sp_str = NULL;
349   const char *pc_str = NULL;
350
351   if (frame == NULL)
352     return PyString_FromString ("Stale PendingFrame instance");
353   try
354     {
355       sp_str = core_addr_to_string_nz (get_frame_sp (frame));
356       pc_str = core_addr_to_string_nz (get_frame_pc (frame));
357     }
358   catch (const gdb_exception &except)
359     {
360       GDB_PY_HANDLE_EXCEPTION (except);
361     }
362
363   return PyString_FromFormat ("SP=%s,PC=%s", sp_str, pc_str);
364 }
365
366 /* Implementation of gdb.PendingFrame.read_register (self, reg) -> gdb.Value.
367    Returns the value of register REG as gdb.Value instance.  */
368
369 static PyObject *
370 pending_framepy_read_register (PyObject *self, PyObject *args)
371 {
372   pending_frame_object *pending_frame = (pending_frame_object *) self;
373   struct value *val = NULL;
374   int regnum;
375   PyObject *pyo_reg_id;
376
377   if (pending_frame->frame_info == NULL)
378     {
379       PyErr_SetString (PyExc_ValueError,
380                        "Attempting to read register from stale PendingFrame");
381       return NULL;
382     }
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))
386     {
387       PyErr_SetString (PyExc_ValueError, "Bad register");
388       return NULL;
389     }
390
391   try
392     {
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);
403     }
404   catch (const gdb_exception &except)
405     {
406       GDB_PY_HANDLE_EXCEPTION (except);
407     }
408
409   return val == NULL ? NULL : value_to_value_object (val);
410 }
411
412 /* Implementation of
413    PendingFrame.create_unwind_info (self, frameId) -> UnwindInfo.  */
414
415 static PyObject *
416 pending_framepy_create_unwind_info (PyObject *self, PyObject *args)
417 {
418   PyObject *pyo_frame_id;
419   CORE_ADDR sp;
420   CORE_ADDR pc;
421   CORE_ADDR special;
422
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))
426     {
427       PyErr_SetString (PyExc_ValueError,
428                        _("frame_id should have 'sp' attribute."));
429       return NULL;
430     }
431
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)
440   */
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));
448 }
449
450 /* Implementation of PendingFrame.architecture (self) -> gdb.Architecture.  */
451
452 static PyObject *
453 pending_framepy_architecture (PyObject *self, PyObject *args)
454 {
455   pending_frame_object *pending_frame = (pending_frame_object *) self;
456
457   if (pending_frame->frame_info == NULL)
458     {
459       PyErr_SetString (PyExc_ValueError,
460                        "Attempting to read register from stale PendingFrame");
461       return NULL;
462     }
463   return gdbarch_to_arch_object (pending_frame->gdbarch);
464 }
465
466 /* Implementation of PendingFrame.level (self) -> Integer.  */
467
468 static PyObject *
469 pending_framepy_level (PyObject *self, PyObject *args)
470 {
471   pending_frame_object *pending_frame = (pending_frame_object *) self;
472
473   if (pending_frame->frame_info == NULL)
474     {
475       PyErr_SetString (PyExc_ValueError,
476                        "Attempting to read stack level from stale PendingFrame");
477       return NULL;
478     }
479   int level = frame_relative_level (pending_frame->frame_info);
480   return gdb_py_object_from_longest (level).release ();
481 }
482
483 /* frame_unwind.this_id method.  */
484
485 static void
486 pyuw_this_id (struct frame_info *this_frame, void **cache_ptr,
487               struct frame_id *this_id)
488 {
489   *this_id = ((cached_frame_info *) *cache_ptr)->frame_id;
490   pyuw_debug_printf ("frame_id: %s", this_id->to_string ().c_str ());
491 }
492
493 /* frame_unwind.prev_register.  */
494
495 static struct value *
496 pyuw_prev_register (struct frame_info *this_frame, void **cache_ptr,
497                     int regnum)
498 {
499   PYUW_SCOPED_DEBUG_ENTER_EXIT;
500
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;
504
505   pyuw_debug_printf ("frame=%d, reg=%d",
506                      frame_relative_level (this_frame), regnum);
507   for (; reg_info < reg_info_end; ++reg_info)
508     {
509       if (regnum == reg_info->num)
510         return frame_unwind_got_bytes (this_frame, regnum, reg_info->data);
511     }
512
513   return frame_unwind_got_optimized (this_frame, regnum);
514 }
515
516 /* Frame sniffer dispatch.  */
517
518 static int
519 pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame,
520               void **cache_ptr)
521 {
522   PYUW_SCOPED_DEBUG_ENTER_EXIT;
523
524   struct gdbarch *gdbarch = (struct gdbarch *) (self->unwind_data);
525   cached_frame_info *cached_frame;
526
527   gdbpy_enter enter_py (gdbarch);
528
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)));
533
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)
539     {
540       gdbpy_print_stack ();
541       return 0;
542     }
543   pfo->gdbarch = gdbarch;
544   scoped_restore invalidate_frame = make_scoped_restore (&pfo->frame_info,
545                                                          this_frame);
546
547   /* Run unwinders.  */
548   if (gdb_python_module == NULL
549       || ! PyObject_HasAttrString (gdb_python_module, "_execute_unwinders"))
550     {
551       PyErr_SetString (PyExc_NameError,
552                        "Installation error: gdb._execute_unwinders function "
553                        "is missing");
554       gdbpy_print_stack ();
555       return 0;
556     }
557   gdbpy_ref<> pyo_execute (PyObject_GetAttrString (gdb_python_module,
558                                                    "_execute_unwinders"));
559   if (pyo_execute == nullptr)
560     {
561       gdbpy_print_stack ();
562       return 0;
563     }
564
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)
570     {
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;
575     }
576   if (pyo_execute_ret == Py_None)
577     return 0;
578
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);
582
583   if (pyuw_debug)
584     {
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);
588
589       /* This could happen if the user passed something else than a string
590          as the unwinder's name.  */
591       if (name == nullptr)
592         {
593           gdbpy_print_stack ();
594           name = make_unique_xstrdup ("<failed to get unwinder name>");
595         }
596
597       pyuw_debug_printf ("frame claimed by unwinder %s", name.get ());
598     }
599
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."));
605
606   {
607     unwind_info_object *unwind_info =
608       (unwind_info_object *) pyo_unwind_info;
609     int reg_count = unwind_info->saved_regs->size ();
610
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;
618
619     /* Populate registers array.  */
620     for (int i = 0; i < unwind_info->saved_regs->size (); ++i)
621       {
622         saved_reg *reg = &(*unwind_info->saved_regs)[i];
623
624         struct value *value = value_object_to_value (reg->value.get ());
625         size_t data_size = register_size (gdbarch, reg->number);
626
627         cached_frame->reg[i].num = reg->number;
628
629         /* `value' validation was done before, just assert.  */
630         gdb_assert (value != NULL);
631         gdb_assert (data_size == TYPE_LENGTH (value_type (value)));
632
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);
636       }
637   }
638
639   *cache_ptr = cached_frame;
640   return 1;
641 }
642
643 /* Frame cache release shim.  */
644
645 static void
646 pyuw_dealloc_cache (struct frame_info *this_frame, void *cache)
647 {
648   PYUW_SCOPED_DEBUG_ENTER_EXIT;
649   cached_frame_info *cached_frame = (cached_frame_info *) cache;
650
651   for (int i = 0; i < cached_frame->reg_count; i++)
652     xfree (cached_frame->reg[i].data);
653
654   xfree (cache);
655 }
656
657 struct pyuw_gdbarch_data_type
658 {
659   /* Has the unwinder shim been prepended? */
660   int unwinder_registered;
661 };
662
663 static void *
664 pyuw_gdbarch_data_init (struct gdbarch *gdbarch)
665 {
666   return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct pyuw_gdbarch_data_type);
667 }
668
669 /* New inferior architecture callback: register the Python unwinders
670    intermediary.  */
671
672 static void
673 pyuw_on_new_gdbarch (struct gdbarch *newarch)
674 {
675   struct pyuw_gdbarch_data_type *data
676     = (struct pyuw_gdbarch_data_type *) gdbarch_data (newarch,
677                                                       pyuw_gdbarch_data);
678
679   if (!data->unwinder_registered)
680     {
681       struct frame_unwind *unwinder
682           = GDBARCH_OBSTACK_ZALLOC (newarch, struct frame_unwind);
683
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;
694     }
695 }
696
697 void _initialize_py_unwind ();
698 void
699 _initialize_py_unwind ()
700 {
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);
711 }
712
713 /* Initialize unwind machinery.  */
714
715 int
716 gdbpy_initialize_unwind (void)
717 {
718   gdb::observers::architecture_changed.attach (pyuw_on_new_gdbarch,
719                                                "py-unwind");
720
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;
727
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);
732 }
733
734 static PyMethodDef pending_frame_object_methods[] =
735 {
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 */
751 };
752
753 PyTypeObject pending_frame_object_type =
754 {
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 */
792 };
793
794 static PyMethodDef unwind_info_object_methods[] =
795 {
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 */
801 };
802
803 PyTypeObject unwind_info_object_type =
804 {
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 */
842 };
This page took 0.071686 seconds and 4 git commands to generate.