GDB (xrefs)
py-unwind.c
Go to the documentation of this file.
1 /* Python frame unwinder interface.
2 
3  Copyright (C) 2015 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 "gdb_obstack.h"
24 #include "gdbcmd.h"
25 #include "language.h"
26 #include "observer.h"
27 #include "python-internal.h"
28 #include "regcache.h"
29 #include "valprint.h"
30 #include "user-regs.h"
31 
32 #define TRACE_PY_UNWIND(level, args...) if (pyuw_debug >= level) \
33  { fprintf_unfiltered (gdb_stdlog, args); }
34 
35 typedef struct
36 {
37  PyObject_HEAD
38 
39  /* Frame we are unwinding. */
41 
42  /* Its architecture, passed by the sniffer caller. */
43  struct gdbarch *gdbarch;
45 
46 /* Saved registers array item. */
47 
48 typedef struct
49 {
50  int number;
51  PyObject *value;
52 } saved_reg;
54 
55 /* The data we keep for the PyUnwindInfo: pending_frame, saved registers
56  and frame ID. */
57 
58 typedef struct
59 {
60  PyObject_HEAD
61 
62  /* gdb.PendingFrame for the frame we are unwinding. */
63  PyObject *pending_frame;
64 
65  /* Its ID. */
67 
68  /* Saved registers array. */
69  VEC (saved_reg) *saved_regs;
71 
72 /* The data we keep for a frame we can unwind: frame ID and an array of
73  (register_number, register_value) pairs. */
74 
75 struct reg_info
76 {
77  /* Register number. */
78  int number;
79 
80  /* Register data bytes pointer. */
82 };
83 
84 typedef struct
85 {
86  /* Frame ID. */
88 
89  /* GDB Architecture. */
90  struct gdbarch *gdbarch;
91 
92  /* Length of the `reg' array below. */
93  int reg_count;
94 
95  struct reg_info reg[];
97 
98 extern PyTypeObject pending_frame_object_type
99  CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("pending_frame_object");
100 
101 extern PyTypeObject unwind_info_object_type
102  CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("unwind_info_object");
103 
104 static unsigned int pyuw_debug = 0;
105 
107 
108 /* Parses register id, which can be either a number or a name.
109  Returns 1 on success, 0 otherwise. */
110 
111 static int
112 pyuw_parse_register_id (struct gdbarch *gdbarch, PyObject *pyo_reg_id,
113  int *reg_num)
114 {
115  if (pyo_reg_id == NULL)
116  return 0;
117  if (gdbpy_is_string (pyo_reg_id))
118  {
119  const char *reg_name = gdbpy_obj_to_string (pyo_reg_id);
120 
121  if (reg_name == NULL)
122  return 0;
123  *reg_num = user_reg_map_name_to_regnum (gdbarch, reg_name,
124  strlen (reg_name));
125  return *reg_num >= 0;
126  }
127  else if (PyInt_Check (pyo_reg_id))
128  {
129  long value;
130  if (gdb_py_int_as_long (pyo_reg_id, &value) && (int) value == value)
131  {
132  *reg_num = (int) value;
133  return user_reg_map_regnum_to_name (gdbarch, *reg_num) != NULL;
134  }
135  }
136  return 0;
137 }
138 
139 /* Convert gdb.Value instance to inferior's pointer. Return 1 on success,
140  0 on failure. */
141 
142 static int
143 pyuw_value_obj_to_pointer (PyObject *pyo_value, CORE_ADDR *addr)
144 {
145  int rc = 0;
146  struct value *value;
147 
148  TRY
149  {
150  if ((value = value_object_to_value (pyo_value)) != NULL)
151  {
152  *addr = unpack_pointer (value_type (value),
153  value_contents (value));
154  rc = 1;
155  }
156  }
157  CATCH (except, RETURN_MASK_ALL)
158  {
159  gdbpy_convert_exception (except);
160  }
161  END_CATCH
162  return rc;
163 }
164 
165 /* Get attribute from an object and convert it to the inferior's
166  pointer value. Return 1 if attribute exists and its value can be
167  converted. Otherwise, if attribute does not exist or its value is
168  None, return 0. In all other cases set Python error and return
169  0. */
170 
171 static int
172 pyuw_object_attribute_to_pointer (PyObject *pyo, const char *attr_name,
173  CORE_ADDR *addr)
174 {
175  int rc = 0;
176 
177  if (PyObject_HasAttrString (pyo, attr_name))
178  {
179  PyObject *pyo_value = PyObject_GetAttrString (pyo, attr_name);
180  struct value *value;
181 
182  if (pyo_value != NULL && pyo_value != Py_None)
183  {
184  rc = pyuw_value_obj_to_pointer (pyo_value, addr);
185  if (!rc)
186  PyErr_Format (
187  PyExc_ValueError,
188  _("The value of the '%s' attribute is not a pointer."),
189  attr_name);
190  }
191  Py_XDECREF (pyo_value);
192  }
193  return rc;
194 }
195 
196 /* Called by the Python interpreter to obtain string representation
197  of the UnwindInfo object. */
198 
199 static PyObject *
200 unwind_infopy_str (PyObject *self)
201 {
202  struct ui_file *strfile = mem_fileopen ();
203  unwind_info_object *unwind_info = (unwind_info_object *) self;
204  pending_frame_object *pending_frame
205  = (pending_frame_object *) (unwind_info->pending_frame);
206  PyObject *result;
207 
208  fprintf_unfiltered (strfile, "Frame ID: ");
209  fprint_frame_id (strfile, unwind_info->frame_id);
210  {
211  char *sep = "";
212  int i;
213  struct value_print_options opts;
214  saved_reg *reg;
215 
216  get_user_print_options (&opts);
217  fprintf_unfiltered (strfile, "\nSaved registers: (");
218  for (i = 0;
219  i < VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg);
220  i++)
221  {
222  struct value *value = value_object_to_value (reg->value);
223 
224  fprintf_unfiltered (strfile, "%s(%d, ", sep, reg->number);
225  if (value != NULL)
226  {
227  TRY
228  {
229  value_print (value, strfile, &opts);
230  fprintf_unfiltered (strfile, ")");
231  }
232  CATCH (except, RETURN_MASK_ALL)
233  {
234  GDB_PY_HANDLE_EXCEPTION (except);
235  }
236  END_CATCH
237  }
238  else
239  fprintf_unfiltered (strfile, "<BAD>)");
240  sep = ", ";
241  }
242  fprintf_unfiltered (strfile, ")");
243  }
244  {
245  char *s = ui_file_xstrdup (strfile, NULL);
246 
247  result = PyString_FromString (s);
248  xfree (s);
249  }
250  ui_file_delete (strfile);
251  return result;
252 }
253 
254 /* Create UnwindInfo instance for given PendingFrame and frame ID.
255  Sets Python error and returns NULL on error. */
256 
257 static PyObject *
258 pyuw_create_unwind_info (PyObject *pyo_pending_frame,
259  struct frame_id frame_id)
260 {
261  unwind_info_object *unwind_info
262  = PyObject_New (unwind_info_object, &unwind_info_object_type);
263 
264  if (((pending_frame_object *) pyo_pending_frame)->frame_info == NULL)
265  {
266  PyErr_SetString (PyExc_ValueError,
267  "Attempting to use stale PendingFrame");
268  return NULL;
269  }
270  unwind_info->frame_id = frame_id;
271  Py_INCREF (pyo_pending_frame);
272  unwind_info->pending_frame = pyo_pending_frame;
273  unwind_info->saved_regs = VEC_alloc (saved_reg, 4);
274  return (PyObject *) unwind_info;
275 }
276 
277 /* The implementation of
278  gdb.UnwindInfo.add_saved_register (REG, VALUE) -> None. */
279 
280 static PyObject *
281 unwind_infopy_add_saved_register (PyObject *self, PyObject *args)
282 {
283  unwind_info_object *unwind_info = (unwind_info_object *) self;
284  pending_frame_object *pending_frame
285  = (pending_frame_object *) (unwind_info->pending_frame);
286  PyObject *pyo_reg_id;
287  PyObject *pyo_reg_value;
288  int regnum;
289 
290  if (pending_frame->frame_info == NULL)
291  {
292  PyErr_SetString (PyExc_ValueError,
293  "UnwindInfo instance refers to a stale PendingFrame");
294  return NULL;
295  }
296  if (!PyArg_UnpackTuple (args, "previous_frame_register", 2, 2,
297  &pyo_reg_id, &pyo_reg_value))
298  return NULL;
299  if (!pyuw_parse_register_id (pending_frame->gdbarch, pyo_reg_id, &regnum))
300  {
301  PyErr_SetString (PyExc_ValueError, "Bad register");
302  return NULL;
303  }
304  {
305  struct value *value;
306  size_t data_size;
307 
308  if (pyo_reg_value == NULL
309  || (value = value_object_to_value (pyo_reg_value)) == NULL)
310  {
311  PyErr_SetString (PyExc_ValueError, "Bad register value");
312  return NULL;
313  }
314  data_size = register_size (pending_frame->gdbarch, regnum);
315  if (data_size != TYPE_LENGTH (value_type (value)))
316  {
317  PyErr_Format (
318  PyExc_ValueError,
319  "The value of the register returned by the Python "
320  "sniffer has unexpected size: %u instead of %u.",
321  (unsigned) TYPE_LENGTH (value_type (value)),
322  (unsigned) data_size);
323  return NULL;
324  }
325  }
326  {
327  int i;
328  saved_reg *reg;
329 
330  for (i = 0; VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg); i++)
331  {
332  if (regnum == reg->number)
333  {
334  Py_DECREF (reg->value);
335  break;
336  }
337  }
338  if (reg == NULL)
339  {
340  reg = VEC_safe_push (saved_reg, unwind_info->saved_regs, NULL);
341  reg->number = regnum;
342  }
343  Py_INCREF (pyo_reg_value);
344  reg->value = pyo_reg_value;
345  }
346  Py_RETURN_NONE;
347 }
348 
349 /* UnwindInfo cleanup. */
350 
351 static void
352 unwind_infopy_dealloc (PyObject *self)
353 {
354  unwind_info_object *unwind_info = (unwind_info_object *) self;
355  int i;
356  saved_reg *reg;
357 
358  Py_XDECREF (unwind_info->pending_frame);
359  for (i = 0; VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg); i++)
360  Py_DECREF (reg->value);
361  VEC_free (saved_reg, unwind_info->saved_regs);
362  Py_TYPE (self)->tp_free (self);
363 }
364 
365 /* Called by the Python interpreter to obtain string representation
366  of the PendingFrame object. */
367 
368 static PyObject *
369 pending_framepy_str (PyObject *self)
370 {
371  struct frame_info *frame = ((pending_frame_object *) self)->frame_info;
372  const char *sp_str = NULL;
373  const char *pc_str = NULL;
374 
375  if (frame == NULL)
376  return PyString_FromString ("Stale PendingFrame instance");
377  TRY
378  {
379  sp_str = core_addr_to_string_nz (get_frame_sp (frame));
380  pc_str = core_addr_to_string_nz (get_frame_pc (frame));
381  }
382  CATCH (except, RETURN_MASK_ALL)
383  {
384  GDB_PY_HANDLE_EXCEPTION (except);
385  }
386  END_CATCH
387 
388  return PyString_FromFormat ("SP=%s,PC=%s", sp_str, pc_str);
389 }
390 
391 /* Implementation of gdb.PendingFrame.read_register (self, reg) -> gdb.Value.
392  Returns the value of register REG as gdb.Value instance. */
393 
394 static PyObject *
395 pending_framepy_read_register (PyObject *self, PyObject *args)
396 {
397  pending_frame_object *pending_frame = (pending_frame_object *) self;
398  struct value *val = NULL;
399  int regnum;
400  PyObject *pyo_reg_id;
401 
402  if (pending_frame->frame_info == NULL)
403  {
404  PyErr_SetString (PyExc_ValueError,
405  "Attempting to read register from stale PendingFrame");
406  return NULL;
407  }
408  if (!PyArg_UnpackTuple (args, "read_register", 1, 1, &pyo_reg_id))
409  return NULL;
410  if (!pyuw_parse_register_id (pending_frame->gdbarch, pyo_reg_id, &regnum))
411  {
412  PyErr_SetString (PyExc_ValueError, "Bad register");
413  return NULL;
414  }
415 
416  TRY
417  {
418  val = get_frame_register_value (pending_frame->frame_info, regnum);
419  if (val == NULL)
420  PyErr_Format (PyExc_ValueError,
421  "Cannot read register %d from frame.",
422  regnum);
423  }
424  CATCH (except, RETURN_MASK_ALL)
425  {
426  GDB_PY_HANDLE_EXCEPTION (except);
427  }
428  END_CATCH
429 
430  return val == NULL ? NULL : value_to_value_object (val);
431 }
432 
433 /* Implementation of
434  PendingFrame.create_unwind_info (self, frameId) -> UnwindInfo. */
435 
436 static PyObject *
437 pending_framepy_create_unwind_info (PyObject *self, PyObject *args)
438 {
439  PyObject *pyo_frame_id;
440  CORE_ADDR sp;
441  CORE_ADDR pc;
442  CORE_ADDR special;
443 
444  if (!PyArg_ParseTuple (args, "O:create_unwind_info", &pyo_frame_id))
445  return NULL;
446  if (!pyuw_object_attribute_to_pointer (pyo_frame_id, "sp", &sp))
447  {
448  PyErr_SetString (PyExc_ValueError,
449  _("frame_id should have 'sp' attribute."));
450  return NULL;
451  }
452 
453  /* The logic of building frame_id depending on the attributes of
454  the frame_id object:
455  Has Has Has Function to call
456  'sp'? 'pc'? 'special'?
457  ------|------|--------------|-------------------------
458  Y N * frame_id_build_wild (sp)
459  Y Y N frame_id_build (sp, pc)
460  Y Y Y frame_id_build_special (sp, pc, special)
461  */
462  if (!pyuw_object_attribute_to_pointer (pyo_frame_id, "pc", &pc))
463  return pyuw_create_unwind_info (self, frame_id_build_wild (sp));
464  if (!pyuw_object_attribute_to_pointer (pyo_frame_id, "special", &special))
465  return pyuw_create_unwind_info (self, frame_id_build (sp, pc));
466  else
467  return pyuw_create_unwind_info (self,
468  frame_id_build_special (sp, pc, special));
469 }
470 
471 /* Invalidate PendingFrame instance. */
472 
473 static void
474 pending_frame_invalidate (void *pyo_pending_frame)
475 {
476  if (pyo_pending_frame != NULL)
477  ((pending_frame_object *) pyo_pending_frame)->frame_info = NULL;
478 }
479 
480 /* frame_unwind.this_id method. */
481 
482 static void
483 pyuw_this_id (struct frame_info *this_frame, void **cache_ptr,
484  struct frame_id *this_id)
485 {
486  *this_id = ((cached_frame_info *) *cache_ptr)->frame_id;
487  if (pyuw_debug >= 1)
488  {
489  fprintf_unfiltered (gdb_stdlog, "%s: frame_id: ", __FUNCTION__);
490  fprint_frame_id (gdb_stdlog, *this_id);
492  }
493 }
494 
495 /* frame_unwind.prev_register. */
496 
497 static struct value *
498 pyuw_prev_register (struct frame_info *this_frame, void **cache_ptr,
499  int regnum)
500 {
501  cached_frame_info *cached_frame = *cache_ptr;
502  struct reg_info *reg_info = cached_frame->reg;
503  struct reg_info *reg_info_end = reg_info + cached_frame->reg_count;
504 
505  TRACE_PY_UNWIND (1, "%s (frame=%p,...,reg=%d)\n", __FUNCTION__, this_frame,
506  regnum);
507  for (; reg_info < reg_info_end; ++reg_info)
508  {
509  if (regnum == reg_info->number)
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  struct gdbarch *gdbarch = (struct gdbarch *) (self->unwind_data);
523  struct cleanup *cleanups = ensure_python_env (gdbarch, current_language);
524  PyObject *pyo_execute;
525  PyObject *pyo_pending_frame;
526  PyObject *pyo_unwind_info;
527  cached_frame_info *cached_frame;
528 
529  TRACE_PY_UNWIND (3, "%s (SP=%s, PC=%s)\n", __FUNCTION__,
530  paddress (gdbarch, get_frame_sp (this_frame)),
531  paddress (gdbarch, get_frame_pc (this_frame)));
532 
533  /* Create PendingFrame instance to pass to sniffers. */
534  pyo_pending_frame = (PyObject *) PyObject_New (pending_frame_object,
536  if (pyo_pending_frame == NULL)
537  goto error;
538  ((pending_frame_object *) pyo_pending_frame)->gdbarch = gdbarch;
539  ((pending_frame_object *) pyo_pending_frame)->frame_info = this_frame;
540  make_cleanup (pending_frame_invalidate, (void *) pyo_pending_frame);
541  make_cleanup_py_decref (pyo_pending_frame);
542 
543  /* Run unwinders. */
544  if (gdb_python_module == NULL
545  || ! PyObject_HasAttrString (gdb_python_module, "execute_unwinders"))
546  {
547  PyErr_SetString (PyExc_NameError,
548  "Installation error: gdb.execute_unwinders function "
549  "is missing");
550  goto error;
551  }
552  pyo_execute = PyObject_GetAttrString (gdb_python_module, "execute_unwinders");
553  if (pyo_execute == NULL)
554  goto error;
555  make_cleanup_py_decref (pyo_execute);
556  pyo_unwind_info
557  = PyObject_CallFunctionObjArgs (pyo_execute, pyo_pending_frame, NULL);
558  if (pyo_unwind_info == NULL)
559  goto error;
560  make_cleanup_py_decref (pyo_unwind_info);
561  if (pyo_unwind_info == Py_None)
562  goto cannot_unwind;
563 
564  /* Received UnwindInfo, cache data. */
565  if (PyObject_IsInstance (pyo_unwind_info,
566  (PyObject *) &unwind_info_object_type) <= 0)
567  error (_("A Unwinder should return gdb.UnwindInfo instance."));
568 
569  {
570  unwind_info_object *unwind_info = (unwind_info_object *) pyo_unwind_info;
571  int reg_count = VEC_length (saved_reg, unwind_info->saved_regs);
572  saved_reg *reg;
573  int i;
574 
575  cached_frame = xmalloc (sizeof (*cached_frame) +
576  reg_count * sizeof (cached_frame->reg[0]));
577  cached_frame->gdbarch = gdbarch;
578  cached_frame->frame_id = unwind_info->frame_id;
579  cached_frame->reg_count = reg_count;
580 
581  /* Populate registers array. */
582  for (i = 0; VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg); i++)
583  {
584  struct value *value = value_object_to_value (reg->value);
585  size_t data_size = register_size (gdbarch, reg->number);
586 
587  cached_frame->reg[i].number = reg->number;
588 
589  /* `value' validation was done before, just assert. */
590  gdb_assert (value != NULL);
591  gdb_assert (data_size == TYPE_LENGTH (value_type (value)));
592  gdb_assert (data_size <= MAX_REGISTER_SIZE);
593 
594  memcpy (cached_frame->reg[i].data, value_contents (value), data_size);
595  }
596  }
597 
598  *cache_ptr = cached_frame;
599  do_cleanups (cleanups);
600  return 1;
601 
602  error:
604  /* Fallthrough. */
605  cannot_unwind:
606  do_cleanups (cleanups);
607  return 0;
608 }
609 
610 /* Frame cache release shim. */
611 
612 static void
613 pyuw_dealloc_cache (struct frame_info *this_frame, void *cache)
614 {
615  TRACE_PY_UNWIND (3, "%s: enter", __FUNCTION__);
616  xfree (cache);
617 }
618 
620 {
621  /* Has the unwinder shim been prepended? */
623 };
624 
625 static void *
627 {
628  return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct pyuw_gdbarch_data_type);
629 }
630 
631 /* New inferior architecture callback: register the Python unwinders
632  intermediary. */
633 
634 static void
635 pyuw_on_new_gdbarch (struct gdbarch *newarch)
636 {
637  struct pyuw_gdbarch_data_type *data =
638  gdbarch_data (newarch, pyuw_gdbarch_data);
639 
640  if (!data->unwinder_registered)
641  {
642  struct frame_unwind *unwinder
643  = GDBARCH_OBSTACK_ZALLOC (newarch, struct frame_unwind);
644 
645  unwinder->type = NORMAL_FRAME;
647  unwinder->this_id = pyuw_this_id;
648  unwinder->prev_register = pyuw_prev_register;
649  unwinder->unwind_data = (void *) newarch;
650  unwinder->sniffer = pyuw_sniffer;
651  unwinder->dealloc_cache = pyuw_dealloc_cache;
652  frame_unwind_prepend_unwinder (newarch, unwinder);
653  data->unwinder_registered = 1;
654  }
655 }
656 
657 /* Initialize unwind machinery. */
658 
659 int
661 {
662  int rc;
664  ("py-unwind", class_maintenance, &pyuw_debug,
665  _("Set Python unwinder debugging."),
666  _("Show Python unwinder debugging."),
667  _("When non-zero, Python unwinder debugging is enabled."),
668  NULL,
669  NULL,
671  pyuw_gdbarch_data
674 
675  if (PyType_Ready (&pending_frame_object_type) < 0)
676  return -1;
677  rc = gdb_pymodule_addobject (gdb_module, "PendingFrame",
678  (PyObject *) &pending_frame_object_type);
679  if (rc)
680  return rc;
681 
682  if (PyType_Ready (&unwind_info_object_type) < 0)
683  return -1;
684  return gdb_pymodule_addobject (gdb_module, "UnwindInfo",
685  (PyObject *) &unwind_info_object_type);
686 }
687 
688 static PyMethodDef pending_frame_object_methods[] =
689 {
690  { "read_register", pending_framepy_read_register, METH_VARARGS,
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"
697  "to identify it." },
698  {NULL} /* Sentinel */
699 };
700 
702 {
703  PyVarObject_HEAD_INIT (NULL, 0)
704  "gdb.PendingFrame", /* tp_name */
705  sizeof (pending_frame_object), /* tp_basicsize */
706  0, /* tp_itemsize */
707  0, /* tp_dealloc */
708  0, /* tp_print */
709  0, /* tp_getattr */
710  0, /* tp_setattr */
711  0, /* tp_compare */
712  0, /* tp_repr */
713  0, /* tp_as_number */
714  0, /* tp_as_sequence */
715  0, /* tp_as_mapping */
716  0, /* tp_hash */
717  0, /* tp_call */
718  pending_framepy_str, /* tp_str */
719  0, /* tp_getattro */
720  0, /* tp_setattro */
721  0, /* tp_as_buffer */
722  Py_TPFLAGS_DEFAULT, /* tp_flags */
723  "GDB PendingFrame object", /* tp_doc */
724  0, /* tp_traverse */
725  0, /* tp_clear */
726  0, /* tp_richcompare */
727  0, /* tp_weaklistoffset */
728  0, /* tp_iter */
729  0, /* tp_iternext */
730  pending_frame_object_methods, /* tp_methods */
731  0, /* tp_members */
732  0, /* tp_getset */
733  0, /* tp_base */
734  0, /* tp_dict */
735  0, /* tp_descr_get */
736  0, /* tp_descr_set */
737  0, /* tp_dictoffset */
738  0, /* tp_init */
739  0, /* tp_alloc */
740 };
741 
742 static PyMethodDef unwind_info_object_methods[] =
743 {
744  { "add_saved_register",
745  unwind_infopy_add_saved_register, METH_VARARGS,
746  "add_saved_register (REG, VALUE) -> None\n"
747  "Set the value of the REG in the previous frame to VALUE." },
748  { NULL } /* Sentinel */
749 };
750 
751 PyTypeObject unwind_info_object_type =
752 {
753  PyVarObject_HEAD_INIT (NULL, 0)
754  "gdb.UnwindInfo", /* tp_name */
755  sizeof (unwind_info_object), /* tp_basicsize */
756  0, /* tp_itemsize */
757  unwind_infopy_dealloc, /* tp_dealloc */
758  0, /* tp_print */
759  0, /* tp_getattr */
760  0, /* tp_setattr */
761  0, /* tp_compare */
762  0, /* tp_repr */
763  0, /* tp_as_number */
764  0, /* tp_as_sequence */
765  0, /* tp_as_mapping */
766  0, /* tp_hash */
767  0, /* tp_call */
768  unwind_infopy_str, /* tp_str */
769  0, /* tp_getattro */
770  0, /* tp_setattro */
771  0, /* tp_as_buffer */
772  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
773  "GDB UnwindInfo object", /* tp_doc */
774  0, /* tp_traverse */
775  0, /* tp_clear */
776  0, /* tp_richcompare */
777  0, /* tp_weaklistoffset */
778  0, /* tp_iter */
779  0, /* tp_iternext */
780  unwind_info_object_methods, /* tp_methods */
781  0, /* tp_members */
782  0, /* tp_getset */
783  0, /* tp_base */
784  0, /* tp_dict */
785  0, /* tp_descr_get */
786  0, /* tp_descr_set */
787  0, /* tp_dictoffset */
788  0, /* tp_init */
789  0, /* tp_alloc */
790 };
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
Definition: py-utils.c:437
static struct gdbarch_data * pyuw_gdbarch_data
Definition: py-unwind.c:106
const char * user_reg_map_regnum_to_name(struct gdbarch *gdbarch, int regnum)
Definition: user-regs.c:190
#define Py_DECREF(op)
#define PyObject_GetAttrString(obj, attr)
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition: frame.c:554
struct value * frame_unwind_got_bytes(struct frame_info *frame, int regnum, gdb_byte *buf)
Definition: frame-unwind.c:255
PyObject * gdb_python_module
Definition: python.c:113
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2217
void value_print(struct value *val, struct ui_file *stream, const struct value_print_options *options)
Definition: valprint.c:870
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)
Definition: cli-decode.c:763
bfd_vma CORE_ADDR
Definition: common-types.h:41
DEF_VEC_O(saved_reg)
enum frame_type type
Definition: frame-unwind.h:147
int gdbpy_initialize_unwind(void)
Definition: py-unwind.c:660
void xfree(void *)
Definition: common-utils.c:97
CORE_ADDR unpack_pointer(struct type *type, const gdb_byte *valaddr)
Definition: value.c:2914
int gdbpy_is_string(PyObject *obj)
Definition: py-utils.c:228
char * ui_file_xstrdup(struct ui_file *file, long *length)
Definition: ui-file.c:345
void ui_file_delete(struct ui_file *file)
Definition: ui-file.c:76
void * gdbarch_data(struct gdbarch *gdbarch, struct gdbarch_data *data)
Definition: gdbarch.c:4845
char * gdbpy_obj_to_string(PyObject *obj)
Definition: py-utils.c:242
static void pyuw_on_new_gdbarch(struct gdbarch *newarch)
Definition: py-unwind.c:635
static void * pyuw_gdbarch_data_init(struct gdbarch *gdbarch)
Definition: py-unwind.c:626
CORE_ADDR get_frame_sp(struct frame_info *this_frame)
Definition: frame.c:2577
frame_prev_register_ftype * prev_register
Definition: frame-unwind.h:152
frame_sniffer_ftype * sniffer
Definition: frame-unwind.h:154
frame_dealloc_cache_ftype * dealloc_cache
Definition: frame-unwind.h:155
#define VEC_safe_push(T, V, O)
Definition: vec.h:260
#define VEC(T)
Definition: vec.h:398
#define _(String)
Definition: gdb_locale.h:40
static unsigned int pyuw_debug
Definition: py-unwind.c:104
int number
Definition: py-unwind.c:50
PyObject * value
Definition: py-unwind.c:51
#define END_CATCH
void frame_unwind_prepend_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
Definition: frame-unwind.c:64
static void pyuw_dealloc_cache(struct frame_info *this_frame, void *cache)
Definition: py-unwind.c:613
PyObject_HEAD struct frame_info * frame_info
Definition: py-unwind.c:40
#define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE)
Definition: gdbarch.h:1615
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: utils.c:2743
static PyObject * pyuw_create_unwind_info(PyObject *pyo_pending_frame, struct frame_id frame_id)
Definition: py-unwind.c:258
#define GDB_PY_HANDLE_EXCEPTION(Exception)
#define TRY
#define VEC_iterate(T, V, I, P)
Definition: vec.h:165
struct value * get_frame_register_value(struct frame_info *frame, int regnum)
Definition: frame.c:1158
const gdb_byte * value_contents(struct value *value)
Definition: value.c:1329
#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)
Definition: py-unwind.c:437
struct frame_id frame_id
Definition: py-unwind.c:87
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2361
static void unwind_infopy_dealloc(PyObject *self)
Definition: py-unwind.c:352
frame_unwind_stop_reason_ftype * stop_reason
Definition: frame-unwind.h:150
struct gdbarch * gdbarch
Definition: py-unwind.c:90
struct frame_id frame_id_build_special(CORE_ADDR stack_addr, CORE_ADDR code_addr, CORE_ADDR special_addr)
Definition: frame.c:510
#define VEC_length(T, V)
Definition: vec.h:124
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
Definition: cleanups.c:117
static PyObject * unwind_infopy_str(PyObject *self)
Definition: py-unwind.c:200
struct frame_id frame_id
Definition: py-unwind.c:66
static PyMethodDef pending_frame_object_methods[]
Definition: py-unwind.c:688
#define TRACE_PY_UNWIND(level, args...)
Definition: py-unwind.c:32
struct cleanup * ensure_python_env(struct gdbarch *gdbarch, const struct language_defn *language)
Definition: python.c:247
#define gdb_assert(expr)
Definition: gdb_assert.h:33
PyTypeObject pending_frame_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("pending_frame_object")
PyObject * value_to_value_object(struct value *val)
Definition: py-value.c:1523
int regnum
Definition: aarch64-tdep.c:69
#define VEC_alloc(T, N)
Definition: vec.h:173
struct cmd_list_element * setdebuglist
Definition: cli-cmds.c:173
struct gdbarch * gdbarch
Definition: py-unwind.c:43
int user_reg_map_name_to_regnum(struct gdbarch *gdbarch, const char *name, int len)
Definition: user-regs.c:129
int number
Definition: py-unwind.c:78
void * xmalloc(YYSIZE_T)
struct ui_file * gdb_stdlog
Definition: main.c:73
struct ui_file * mem_fileopen(void)
Definition: ui-file.c:427
Definition: regdef.h:22
Definition: value.c:172
struct value * frame_unwind_got_optimized(struct frame_info *frame, int regnum)
Definition: frame-unwind.c:197
static struct value * pyuw_prev_register(struct frame_info *this_frame, void **cache_ptr, int regnum)
Definition: py-unwind.c:498
const char const char int
Definition: command.h:229
bfd_byte gdb_byte
Definition: common-types.h:38
static int pyuw_object_attribute_to_pointer(PyObject *pyo, const char *attr_name, CORE_ADDR *addr)
Definition: py-unwind.c:172
static PyObject * pending_framepy_str(PyObject *self)
Definition: py-unwind.c:369
const struct language_defn * current_language
Definition: language.c:85
PyTypeObject pending_frame_object_type
Definition: py-unwind.c:701
static int pyuw_sniffer(const struct frame_unwind *self, struct frame_info *this_frame, void **cache_ptr)
Definition: py-unwind.c:519
void gdbpy_convert_exception(struct gdb_exception exception)
Definition: py-utils.c:295
static PyObject * pending_framepy_read_register(PyObject *self, PyObject *args)
Definition: py-unwind.c:395
static void pyuw_this_id(struct frame_info *this_frame, void **cache_ptr, struct frame_id *this_id)
Definition: py-unwind.c:483
static PyObject * unwind_infopy_add_saved_register(PyObject *self, PyObject *args)
Definition: py-unwind.c:281
void gdbpy_print_stack(void)
Definition: python.c:1199
void get_user_print_options(struct value_print_options *opts)
Definition: valprint.c:129
#define VEC_free(T, V)
Definition: vec.h:180
void fprint_frame_id(struct ui_file *file, struct frame_id id)
Definition: frame.c:318
PyObject_HEAD PyObject * pending_frame
Definition: py-unwind.c:63
enum unwind_stop_reason default_frame_unwind_stop_reason(struct frame_info *this_frame, void **this_cache)
Definition: frame-unwind.c:180
int gdb_py_int_as_long(PyObject *obj, long *result)
Definition: py-utils.c:407
int register_size(struct gdbarch *gdbarch, int regnum)
Definition: regcache.c:169
struct reg_info reg[]
Definition: py-unwind.c:95
struct type * value_type(const struct value *value)
Definition: value.c:1021
frame_this_id_ftype * this_id
Definition: frame-unwind.h:151
struct cmd_list_element * showdebuglist
Definition: cli-cmds.c:175
PyObject * gdb_module
Definition: python.c:112
struct frame_id frame_id_build_wild(CORE_ADDR stack_addr)
Definition: frame.c:566
struct value * value_object_to_value(PyObject *self)
Definition: py-value.c:1544
const struct frame_data * unwind_data
Definition: frame-unwind.h:153
#define TYPE_LENGTH(thistype)
Definition: gdbtypes.h:1237
struct cleanup * make_cleanup_py_decref(PyObject *py)
Definition: py-utils.c:41
static void pending_frame_invalidate(void *pyo_pending_frame)
Definition: py-unwind.c:474
static int pyuw_parse_register_id(struct gdbarch *gdbarch, PyObject *pyo_reg_id, int *reg_num)
Definition: py-unwind.c:112
struct frame_id frame_id
Definition: value.c:266
void error(const char *fmt,...)
Definition: errors.c:38
struct gdbarch_data * gdbarch_data_register_post_init(gdbarch_data_post_init_ftype *post_init)
Definition: gdbarch.c:4812
gdb_byte data[MAX_REGISTER_SIZE]
Definition: py-unwind.c:81
#define Py_TYPE(ob)
#define PyObject_HasAttrString(obj, attr)
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:175
static int pyuw_value_obj_to_pointer(PyObject *pyo_value, CORE_ADDR *addr)
Definition: py-unwind.c:143
#define PyVarObject_HEAD_INIT(type, size)