]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/python/py-frame.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / python / py-frame.c
1 /* Python interface to stack frames
2
3 Copyright (C) 2008-2024 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 "language.h"
22 #include "charset.h"
23 #include "block.h"
24 #include "frame.h"
25 #include "symtab.h"
26 #include "stack.h"
27 #include "value.h"
28 #include "python-internal.h"
29 #include "symfile.h"
30 #include "objfiles.h"
31
32 struct frame_object {
33 PyObject_HEAD
34 struct frame_id frame_id;
35 struct gdbarch *gdbarch;
36
37 /* Marks that the FRAME_ID member actually holds the ID of the frame next
38 to this, and not this frames' ID itself. This is a hack to permit Python
39 frame objects which represent invalid frames (i.e., the last frame_info
40 in a corrupt stack). The problem arises from the fact that this code
41 relies on FRAME_ID to uniquely identify a frame, which is not always true
42 for the last "frame" in a corrupt stack (it can have a null ID, or the same
43 ID as the previous frame). Whenever get_prev_frame returns NULL, we
44 record the frame_id of the next frame and set FRAME_ID_IS_NEXT to 1. */
45 int frame_id_is_next;
46 };
47
48 /* Require a valid frame. This must be called inside a TRY_CATCH, or
49 another context in which a gdb exception is allowed. */
50 #define FRAPY_REQUIRE_VALID(frame_obj, frame) \
51 do { \
52 frame = frame_object_to_frame_info (frame_obj); \
53 if (frame == NULL) \
54 error (_("Frame is invalid.")); \
55 } while (0)
56
57 /* Returns the frame_info object corresponding to the given Python Frame
58 object. If the frame doesn't exist anymore (the frame id doesn't
59 correspond to any frame in the inferior), returns NULL. */
60
61 frame_info_ptr
62 frame_object_to_frame_info (PyObject *obj)
63 {
64 frame_object *frame_obj = (frame_object *) obj;
65 frame_info_ptr frame;
66
67 frame = frame_find_by_id (frame_obj->frame_id);
68 if (frame == NULL)
69 return NULL;
70
71 if (frame_obj->frame_id_is_next)
72 frame = get_prev_frame (frame);
73
74 return frame;
75 }
76
77 /* Called by the Python interpreter to obtain string representation
78 of the object. */
79
80 static PyObject *
81 frapy_str (PyObject *self)
82 {
83 const frame_id &fid = ((frame_object *) self)->frame_id;
84 return PyUnicode_FromString (fid.to_string ().c_str ());
85 }
86
87 /* Implement repr() for gdb.Frame. */
88
89 static PyObject *
90 frapy_repr (PyObject *self)
91 {
92 frame_object *frame_obj = (frame_object *) self;
93 frame_info_ptr f_info = frame_find_by_id (frame_obj->frame_id);
94 if (f_info == nullptr)
95 return gdb_py_invalid_object_repr (self);
96
97 const frame_id &fid = frame_obj->frame_id;
98 return PyUnicode_FromFormat ("<%s level=%d frame-id=%s>",
99 Py_TYPE (self)->tp_name,
100 frame_relative_level (f_info),
101 fid.to_string ().c_str ());
102 }
103
104 /* Implementation of gdb.Frame.is_valid (self) -> Boolean.
105 Returns True if the frame corresponding to the frame_id of this
106 object still exists in the inferior. */
107
108 static PyObject *
109 frapy_is_valid (PyObject *self, PyObject *args)
110 {
111 frame_info_ptr frame = NULL;
112
113 try
114 {
115 frame = frame_object_to_frame_info (self);
116 }
117 catch (const gdb_exception &except)
118 {
119 GDB_PY_HANDLE_EXCEPTION (except);
120 }
121
122 if (frame == NULL)
123 Py_RETURN_FALSE;
124
125 Py_RETURN_TRUE;
126 }
127
128 /* Implementation of gdb.Frame.name (self) -> String.
129 Returns the name of the function corresponding to this frame. */
130
131 static PyObject *
132 frapy_name (PyObject *self, PyObject *args)
133 {
134 frame_info_ptr frame;
135 gdb::unique_xmalloc_ptr<char> name;
136 enum language lang;
137 PyObject *result;
138
139 try
140 {
141 FRAPY_REQUIRE_VALID (self, frame);
142
143 name = find_frame_funname (frame, &lang, NULL);
144 }
145 catch (const gdb_exception &except)
146 {
147 GDB_PY_HANDLE_EXCEPTION (except);
148 }
149
150 if (name)
151 {
152 result = PyUnicode_Decode (name.get (), strlen (name.get ()),
153 host_charset (), NULL);
154 }
155 else
156 {
157 result = Py_None;
158 Py_INCREF (Py_None);
159 }
160
161 return result;
162 }
163
164 /* Implementation of gdb.Frame.type (self) -> Integer.
165 Returns the frame type, namely one of the gdb.*_FRAME constants. */
166
167 static PyObject *
168 frapy_type (PyObject *self, PyObject *args)
169 {
170 frame_info_ptr frame;
171 enum frame_type type = NORMAL_FRAME;/* Initialize to appease gcc warning. */
172
173 try
174 {
175 FRAPY_REQUIRE_VALID (self, frame);
176
177 type = get_frame_type (frame);
178 }
179 catch (const gdb_exception &except)
180 {
181 GDB_PY_HANDLE_EXCEPTION (except);
182 }
183
184 return gdb_py_object_from_longest (type).release ();
185 }
186
187 /* Implementation of gdb.Frame.architecture (self) -> gdb.Architecture.
188 Returns the frame's architecture as a gdb.Architecture object. */
189
190 static PyObject *
191 frapy_arch (PyObject *self, PyObject *args)
192 {
193 frame_info_ptr frame = NULL; /* Initialize to appease gcc warning. */
194 frame_object *obj = (frame_object *) self;
195
196 try
197 {
198 FRAPY_REQUIRE_VALID (self, frame);
199 }
200 catch (const gdb_exception &except)
201 {
202 GDB_PY_HANDLE_EXCEPTION (except);
203 }
204
205 return gdbarch_to_arch_object (obj->gdbarch);
206 }
207
208 /* Implementation of gdb.Frame.unwind_stop_reason (self) -> Integer.
209 Returns one of the gdb.FRAME_UNWIND_* constants. */
210
211 static PyObject *
212 frapy_unwind_stop_reason (PyObject *self, PyObject *args)
213 {
214 frame_info_ptr frame = NULL; /* Initialize to appease gcc warning. */
215 enum unwind_stop_reason stop_reason;
216
217 try
218 {
219 FRAPY_REQUIRE_VALID (self, frame);
220 }
221 catch (const gdb_exception &except)
222 {
223 GDB_PY_HANDLE_EXCEPTION (except);
224 }
225
226 stop_reason = get_frame_unwind_stop_reason (frame);
227
228 return gdb_py_object_from_longest (stop_reason).release ();
229 }
230
231 /* Implementation of gdb.Frame.pc (self) -> Long.
232 Returns the frame's resume address. */
233
234 static PyObject *
235 frapy_pc (PyObject *self, PyObject *args)
236 {
237 CORE_ADDR pc = 0; /* Initialize to appease gcc warning. */
238 frame_info_ptr frame;
239
240 try
241 {
242 FRAPY_REQUIRE_VALID (self, frame);
243
244 pc = get_frame_pc (frame);
245 }
246 catch (const gdb_exception &except)
247 {
248 GDB_PY_HANDLE_EXCEPTION (except);
249 }
250
251 return gdb_py_object_from_ulongest (pc).release ();
252 }
253
254 /* Implementation of gdb.Frame.read_register (self, register) -> gdb.Value.
255 Returns the value of a register in this frame. */
256
257 static PyObject *
258 frapy_read_register (PyObject *self, PyObject *args, PyObject *kw)
259 {
260 PyObject *pyo_reg_id;
261 PyObject *result = nullptr;
262
263 static const char *keywords[] = { "register", nullptr };
264 if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O", keywords, &pyo_reg_id))
265 return nullptr;
266
267 try
268 {
269 scoped_value_mark free_values;
270 frame_info_ptr frame;
271 int regnum;
272
273 FRAPY_REQUIRE_VALID (self, frame);
274
275 if (!gdbpy_parse_register_id (get_frame_arch (frame), pyo_reg_id,
276 &regnum))
277 return nullptr;
278
279 gdb_assert (regnum >= 0);
280 value *val
281 = value_of_register (regnum, get_next_frame_sentinel_okay (frame));
282
283 if (val == NULL)
284 PyErr_SetString (PyExc_ValueError, _("Can't read register."));
285 else
286 result = value_to_value_object (val);
287 }
288 catch (const gdb_exception &except)
289 {
290 GDB_PY_HANDLE_EXCEPTION (except);
291 }
292
293 return result;
294 }
295
296 /* Implementation of gdb.Frame.block (self) -> gdb.Block.
297 Returns the frame's code block. */
298
299 static PyObject *
300 frapy_block (PyObject *self, PyObject *args)
301 {
302 frame_info_ptr frame;
303 const struct block *block = NULL, *fn_block;
304
305 try
306 {
307 FRAPY_REQUIRE_VALID (self, frame);
308 block = get_frame_block (frame, NULL);
309 }
310 catch (const gdb_exception &except)
311 {
312 GDB_PY_HANDLE_EXCEPTION (except);
313 }
314
315 for (fn_block = block;
316 fn_block != NULL && fn_block->function () == NULL;
317 fn_block = fn_block->superblock ())
318 ;
319
320 if (block == NULL || fn_block == NULL || fn_block->function () == NULL)
321 {
322 PyErr_SetString (PyExc_RuntimeError,
323 _("Cannot locate block for frame."));
324 return NULL;
325 }
326
327 return block_to_block_object (block, fn_block->function ()->objfile ());
328 }
329
330
331 /* Implementation of gdb.Frame.function (self) -> gdb.Symbol.
332 Returns the symbol for the function corresponding to this frame. */
333
334 static PyObject *
335 frapy_function (PyObject *self, PyObject *args)
336 {
337 struct symbol *sym = NULL;
338 frame_info_ptr frame;
339
340 try
341 {
342 enum language funlang;
343
344 FRAPY_REQUIRE_VALID (self, frame);
345
346 gdb::unique_xmalloc_ptr<char> funname
347 = find_frame_funname (frame, &funlang, &sym);
348 }
349 catch (const gdb_exception &except)
350 {
351 GDB_PY_HANDLE_EXCEPTION (except);
352 }
353
354 if (sym)
355 return symbol_to_symbol_object (sym);
356
357 Py_RETURN_NONE;
358 }
359
360 /* Convert a frame_info struct to a Python Frame object.
361 Sets a Python exception and returns NULL on error. */
362
363 PyObject *
364 frame_info_to_frame_object (frame_info_ptr frame)
365 {
366 gdbpy_ref<frame_object> frame_obj (PyObject_New (frame_object,
367 &frame_object_type));
368 if (frame_obj == NULL)
369 return NULL;
370
371 try
372 {
373
374 /* Try to get the previous frame, to determine if this is the last frame
375 in a corrupt stack. If so, we need to store the frame_id of the next
376 frame and not of this one (which is possibly invalid). */
377 if (get_prev_frame (frame) == NULL
378 && get_frame_unwind_stop_reason (frame) != UNWIND_NO_REASON
379 && get_next_frame (frame) != NULL)
380 {
381 frame_obj->frame_id = get_frame_id (get_next_frame (frame));
382 frame_obj->frame_id_is_next = 1;
383 }
384 else
385 {
386 frame_obj->frame_id = get_frame_id (frame);
387 frame_obj->frame_id_is_next = 0;
388 }
389 frame_obj->gdbarch = get_frame_arch (frame);
390 }
391 catch (const gdb_exception &except)
392 {
393 gdbpy_convert_exception (except);
394 return NULL;
395 }
396
397 return (PyObject *) frame_obj.release ();
398 }
399
400 /* Implementation of gdb.Frame.older (self) -> gdb.Frame.
401 Returns the frame immediately older (outer) to this frame, or None if
402 there isn't one. */
403
404 static PyObject *
405 frapy_older (PyObject *self, PyObject *args)
406 {
407 frame_info_ptr frame, prev = NULL;
408 PyObject *prev_obj = NULL; /* Initialize to appease gcc warning. */
409
410 try
411 {
412 FRAPY_REQUIRE_VALID (self, frame);
413
414 prev = get_prev_frame (frame);
415 }
416 catch (const gdb_exception &except)
417 {
418 GDB_PY_HANDLE_EXCEPTION (except);
419 }
420
421 if (prev)
422 prev_obj = frame_info_to_frame_object (prev);
423 else
424 {
425 Py_INCREF (Py_None);
426 prev_obj = Py_None;
427 }
428
429 return prev_obj;
430 }
431
432 /* Implementation of gdb.Frame.newer (self) -> gdb.Frame.
433 Returns the frame immediately newer (inner) to this frame, or None if
434 there isn't one. */
435
436 static PyObject *
437 frapy_newer (PyObject *self, PyObject *args)
438 {
439 frame_info_ptr frame, next = NULL;
440 PyObject *next_obj = NULL; /* Initialize to appease gcc warning. */
441
442 try
443 {
444 FRAPY_REQUIRE_VALID (self, frame);
445
446 next = get_next_frame (frame);
447 }
448 catch (const gdb_exception &except)
449 {
450 GDB_PY_HANDLE_EXCEPTION (except);
451 }
452
453 if (next)
454 next_obj = frame_info_to_frame_object (next);
455 else
456 {
457 Py_INCREF (Py_None);
458 next_obj = Py_None;
459 }
460
461 return next_obj;
462 }
463
464 /* Implementation of gdb.Frame.find_sal (self) -> gdb.Symtab_and_line.
465 Returns the frame's symtab and line. */
466
467 static PyObject *
468 frapy_find_sal (PyObject *self, PyObject *args)
469 {
470 frame_info_ptr frame;
471 PyObject *sal_obj = NULL; /* Initialize to appease gcc warning. */
472
473 try
474 {
475 FRAPY_REQUIRE_VALID (self, frame);
476
477 symtab_and_line sal = find_frame_sal (frame);
478 sal_obj = symtab_and_line_to_sal_object (sal);
479 }
480 catch (const gdb_exception &except)
481 {
482 GDB_PY_HANDLE_EXCEPTION (except);
483 }
484
485 return sal_obj;
486 }
487
488 /* Implementation of gdb.Frame.read_var_value (self, variable,
489 [block]) -> gdb.Value. If the optional block argument is provided
490 start the search from that block, otherwise search from the frame's
491 current block (determined by examining the resume address of the
492 frame). The variable argument must be a string or an instance of a
493 gdb.Symbol. The block argument must be an instance of gdb.Block. Returns
494 NULL on error, with a python exception set. */
495 static PyObject *
496 frapy_read_var (PyObject *self, PyObject *args, PyObject *kw)
497 {
498 frame_info_ptr frame;
499 PyObject *sym_obj, *block_obj = NULL;
500 struct symbol *var = NULL; /* gcc-4.3.2 false warning. */
501 const struct block *block = NULL;
502
503 static const char *keywords[] = { "variable", "block", nullptr };
504 if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O|O!", keywords,
505 &sym_obj, &block_object_type,
506 &block_obj))
507 return nullptr;
508
509 if (PyObject_TypeCheck (sym_obj, &symbol_object_type))
510 var = symbol_object_to_symbol (sym_obj);
511 else if (gdbpy_is_string (sym_obj))
512 {
513 gdb::unique_xmalloc_ptr<char>
514 var_name (python_string_to_target_string (sym_obj));
515
516 if (!var_name)
517 return NULL;
518
519 if (block_obj != nullptr)
520 {
521 /* This call should only fail if the type of BLOCK_OBJ is wrong,
522 and we ensure the type is correct when we parse the arguments,
523 so we can just assert the return value is not nullptr. */
524 block = block_object_to_block (block_obj);
525 gdb_assert (block != nullptr);
526 }
527
528 try
529 {
530 struct block_symbol lookup_sym;
531 FRAPY_REQUIRE_VALID (self, frame);
532
533 if (!block)
534 block = get_frame_block (frame, NULL);
535 lookup_sym = lookup_symbol (var_name.get (), block, VAR_DOMAIN, NULL);
536 var = lookup_sym.symbol;
537 block = lookup_sym.block;
538 }
539 catch (const gdb_exception &except)
540 {
541 gdbpy_convert_exception (except);
542 return NULL;
543 }
544
545 if (!var)
546 {
547 PyErr_Format (PyExc_ValueError,
548 _("Variable '%s' not found."), var_name.get ());
549
550 return NULL;
551 }
552 }
553 else
554 {
555 PyErr_Format (PyExc_TypeError,
556 _("argument 1 must be gdb.Symbol or str, not %s"),
557 Py_TYPE (sym_obj)->tp_name);
558 return NULL;
559 }
560
561 PyObject *result = nullptr;
562 try
563 {
564 FRAPY_REQUIRE_VALID (self, frame);
565
566 scoped_value_mark free_values;
567 struct value *val = read_var_value (var, block, frame);
568 result = value_to_value_object (val);
569 }
570 catch (const gdb_exception &except)
571 {
572 GDB_PY_HANDLE_EXCEPTION (except);
573 }
574
575 return result;
576 }
577
578 /* Select this frame. */
579
580 static PyObject *
581 frapy_select (PyObject *self, PyObject *args)
582 {
583 frame_info_ptr fi;
584
585 try
586 {
587 FRAPY_REQUIRE_VALID (self, fi);
588
589 select_frame (fi);
590 }
591 catch (const gdb_exception &except)
592 {
593 GDB_PY_HANDLE_EXCEPTION (except);
594 }
595
596 Py_RETURN_NONE;
597 }
598
599 /* The stack frame level for this frame. */
600
601 static PyObject *
602 frapy_level (PyObject *self, PyObject *args)
603 {
604 frame_info_ptr fi;
605
606 try
607 {
608 FRAPY_REQUIRE_VALID (self, fi);
609
610 return gdb_py_object_from_longest (frame_relative_level (fi)).release ();
611 }
612 catch (const gdb_exception &except)
613 {
614 GDB_PY_HANDLE_EXCEPTION (except);
615 }
616
617 Py_RETURN_NONE;
618 }
619
620 /* The language for this frame. */
621
622 static PyObject *
623 frapy_language (PyObject *self, PyObject *args)
624 {
625 try
626 {
627 frame_info_ptr fi;
628 FRAPY_REQUIRE_VALID (self, fi);
629
630 enum language lang = get_frame_language (fi);
631 const language_defn *lang_def = language_def (lang);
632
633 return host_string_to_python_string (lang_def->name ()).release ();
634 }
635 catch (const gdb_exception &except)
636 {
637 GDB_PY_HANDLE_EXCEPTION (except);
638 }
639
640 Py_RETURN_NONE;
641 }
642
643 /* The static link for this frame. */
644
645 static PyObject *
646 frapy_static_link (PyObject *self, PyObject *args)
647 {
648 frame_info_ptr link;
649
650 try
651 {
652 FRAPY_REQUIRE_VALID (self, link);
653
654 link = frame_follow_static_link (link);
655 }
656 catch (const gdb_exception &except)
657 {
658 GDB_PY_HANDLE_EXCEPTION (except);
659 }
660
661 if (link == nullptr)
662 Py_RETURN_NONE;
663
664 return frame_info_to_frame_object (link);
665 }
666
667 /* Implementation of gdb.newest_frame () -> gdb.Frame.
668 Returns the newest frame object. */
669
670 PyObject *
671 gdbpy_newest_frame (PyObject *self, PyObject *args)
672 {
673 frame_info_ptr frame = NULL;
674
675 try
676 {
677 frame = get_current_frame ();
678 }
679 catch (const gdb_exception &except)
680 {
681 GDB_PY_HANDLE_EXCEPTION (except);
682 }
683
684 return frame_info_to_frame_object (frame);
685 }
686
687 /* Implementation of gdb.selected_frame () -> gdb.Frame.
688 Returns the selected frame object. */
689
690 PyObject *
691 gdbpy_selected_frame (PyObject *self, PyObject *args)
692 {
693 frame_info_ptr frame = NULL;
694
695 try
696 {
697 frame = get_selected_frame ("No frame is currently selected.");
698 }
699 catch (const gdb_exception &except)
700 {
701 GDB_PY_HANDLE_EXCEPTION (except);
702 }
703
704 return frame_info_to_frame_object (frame);
705 }
706
707 /* Implementation of gdb.stop_reason_string (Integer) -> String.
708 Return a string explaining the unwind stop reason. */
709
710 PyObject *
711 gdbpy_frame_stop_reason_string (PyObject *self, PyObject *args)
712 {
713 int reason;
714 const char *str;
715
716 if (!PyArg_ParseTuple (args, "i", &reason))
717 return NULL;
718
719 if (reason < UNWIND_FIRST || reason > UNWIND_LAST)
720 {
721 PyErr_SetString (PyExc_ValueError,
722 _("Invalid frame stop reason."));
723 return NULL;
724 }
725
726 str = unwind_stop_reason_to_string ((enum unwind_stop_reason) reason);
727 return PyUnicode_Decode (str, strlen (str), host_charset (), NULL);
728 }
729
730 /* Implements the equality comparison for Frame objects.
731 All other comparison operators will throw a TypeError Python exception,
732 as they aren't valid for frames. */
733
734 static PyObject *
735 frapy_richcompare (PyObject *self, PyObject *other, int op)
736 {
737 int result;
738
739 if (!PyObject_TypeCheck (other, &frame_object_type)
740 || (op != Py_EQ && op != Py_NE))
741 {
742 Py_INCREF (Py_NotImplemented);
743 return Py_NotImplemented;
744 }
745
746 frame_object *self_frame = (frame_object *) self;
747 frame_object *other_frame = (frame_object *) other;
748
749 if (self_frame->frame_id_is_next == other_frame->frame_id_is_next
750 && self_frame->frame_id == other_frame->frame_id)
751 result = Py_EQ;
752 else
753 result = Py_NE;
754
755 if (op == result)
756 Py_RETURN_TRUE;
757 Py_RETURN_FALSE;
758 }
759
760 /* Sets up the Frame API in the gdb module. */
761
762 static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
763 gdbpy_initialize_frames (void)
764 {
765 frame_object_type.tp_new = PyType_GenericNew;
766 if (PyType_Ready (&frame_object_type) < 0)
767 return -1;
768
769 /* Note: These would probably be best exposed as class attributes of
770 Frame, but I don't know how to do it except by messing with the
771 type's dictionary. That seems too messy. */
772 if (PyModule_AddIntConstant (gdb_module, "NORMAL_FRAME", NORMAL_FRAME) < 0
773 || PyModule_AddIntConstant (gdb_module, "DUMMY_FRAME", DUMMY_FRAME) < 0
774 || PyModule_AddIntConstant (gdb_module, "INLINE_FRAME", INLINE_FRAME) < 0
775 || PyModule_AddIntConstant (gdb_module, "TAILCALL_FRAME",
776 TAILCALL_FRAME) < 0
777 || PyModule_AddIntConstant (gdb_module, "SIGTRAMP_FRAME",
778 SIGTRAMP_FRAME) < 0
779 || PyModule_AddIntConstant (gdb_module, "ARCH_FRAME", ARCH_FRAME) < 0
780 || PyModule_AddIntConstant (gdb_module, "SENTINEL_FRAME",
781 SENTINEL_FRAME) < 0)
782 return -1;
783
784 #define SET(name, description) \
785 if (PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name) < 0) \
786 return -1;
787 #include "unwind_stop_reasons.def"
788 #undef SET
789
790 return gdb_pymodule_addobject (gdb_module, "Frame",
791 (PyObject *) &frame_object_type);
792 }
793
794 GDBPY_INITIALIZE_FILE (gdbpy_initialize_frames);
795
796 \f
797
798 static PyMethodDef frame_object_methods[] = {
799 { "is_valid", frapy_is_valid, METH_NOARGS,
800 "is_valid () -> Boolean.\n\
801 Return true if this frame is valid, false if not." },
802 { "name", frapy_name, METH_NOARGS,
803 "name () -> String.\n\
804 Return the function name of the frame, or None if it can't be determined." },
805 { "type", frapy_type, METH_NOARGS,
806 "type () -> Integer.\n\
807 Return the type of the frame." },
808 { "architecture", frapy_arch, METH_NOARGS,
809 "architecture () -> gdb.Architecture.\n\
810 Return the architecture of the frame." },
811 { "unwind_stop_reason", frapy_unwind_stop_reason, METH_NOARGS,
812 "unwind_stop_reason () -> Integer.\n\
813 Return the reason why it's not possible to find frames older than this." },
814 { "pc", frapy_pc, METH_NOARGS,
815 "pc () -> Long.\n\
816 Return the frame's resume address." },
817 { "read_register", (PyCFunction) frapy_read_register,
818 METH_VARARGS | METH_KEYWORDS,
819 "read_register (register_name) -> gdb.Value\n\
820 Return the value of the register in the frame." },
821 { "block", frapy_block, METH_NOARGS,
822 "block () -> gdb.Block.\n\
823 Return the frame's code block." },
824 { "function", frapy_function, METH_NOARGS,
825 "function () -> gdb.Symbol.\n\
826 Returns the symbol for the function corresponding to this frame." },
827 { "older", frapy_older, METH_NOARGS,
828 "older () -> gdb.Frame.\n\
829 Return the frame that called this frame." },
830 { "newer", frapy_newer, METH_NOARGS,
831 "newer () -> gdb.Frame.\n\
832 Return the frame called by this frame." },
833 { "find_sal", frapy_find_sal, METH_NOARGS,
834 "find_sal () -> gdb.Symtab_and_line.\n\
835 Return the frame's symtab and line." },
836 { "read_var", (PyCFunction) frapy_read_var, METH_VARARGS | METH_KEYWORDS,
837 "read_var (variable) -> gdb.Value.\n\
838 Return the value of the variable in this frame." },
839 { "select", frapy_select, METH_NOARGS,
840 "Select this frame as the user's current frame." },
841 { "level", frapy_level, METH_NOARGS,
842 "The stack level of this frame." },
843 { "language", frapy_language, METH_NOARGS,
844 "The language of this frame." },
845 { "static_link", frapy_static_link, METH_NOARGS,
846 "The static link of this frame, or None." },
847 {NULL} /* Sentinel */
848 };
849
850 PyTypeObject frame_object_type = {
851 PyVarObject_HEAD_INIT (NULL, 0)
852 "gdb.Frame", /* tp_name */
853 sizeof (frame_object), /* tp_basicsize */
854 0, /* tp_itemsize */
855 0, /* tp_dealloc */
856 0, /* tp_print */
857 0, /* tp_getattr */
858 0, /* tp_setattr */
859 0, /* tp_compare */
860 frapy_repr, /* tp_repr */
861 0, /* tp_as_number */
862 0, /* tp_as_sequence */
863 0, /* tp_as_mapping */
864 0, /* tp_hash */
865 0, /* tp_call */
866 frapy_str, /* tp_str */
867 0, /* tp_getattro */
868 0, /* tp_setattro */
869 0, /* tp_as_buffer */
870 Py_TPFLAGS_DEFAULT, /* tp_flags */
871 "GDB frame object", /* tp_doc */
872 0, /* tp_traverse */
873 0, /* tp_clear */
874 frapy_richcompare, /* tp_richcompare */
875 0, /* tp_weaklistoffset */
876 0, /* tp_iter */
877 0, /* tp_iternext */
878 frame_object_methods, /* tp_methods */
879 0, /* tp_members */
880 0, /* tp_getset */
881 0, /* tp_base */
882 0, /* tp_dict */
883 0, /* tp_descr_get */
884 0, /* tp_descr_set */
885 0, /* tp_dictoffset */
886 0, /* tp_init */
887 0, /* tp_alloc */
888 };