1<html lang="en"> 2<head> 3<title>Frames In Python - Debugging with GDB</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Debugging with GDB"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Python-API.html#Python-API" title="Python API"> 9<link rel="prev" href="Objfiles-In-Python.html#Objfiles-In-Python" title="Objfiles In Python"> 10<link rel="next" href="Blocks-In-Python.html#Blocks-In-Python" title="Blocks In Python"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 141998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 15Free Software Foundation, Inc. 16 17Permission is granted to copy, distribute and/or modify this document 18under the terms of the GNU Free Documentation License, Version 1.3 or 19any later version published by the Free Software Foundation; with the 20Invariant Sections being ``Free Software'' and ``Free Software Needs 21Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' 22and with the Back-Cover Texts as in (a) below. 23 24(a) The FSF's Back-Cover Text is: ``You are free to copy and modify 25this GNU Manual. Buying copies from GNU Press supports the FSF in 26developing GNU and promoting software freedom.''--> 27<meta http-equiv="Content-Style-Type" content="text/css"> 28<style type="text/css"><!-- 29 pre.display { font-family:inherit } 30 pre.format { font-family:inherit } 31 pre.smalldisplay { font-family:inherit; font-size:smaller } 32 pre.smallformat { font-family:inherit; font-size:smaller } 33 pre.smallexample { font-size:smaller } 34 pre.smalllisp { font-size:smaller } 35 span.sc { font-variant:small-caps } 36 span.roman { font-family:serif; font-weight:normal; } 37 span.sansserif { font-family:sans-serif; font-weight:normal; } 38--></style> 39<link rel="stylesheet" type="text/css" href="../cs.css"> 40</head> 41<body> 42<div class="node"> 43<a name="Frames-In-Python"></a> 44<p> 45Next: <a rel="next" accesskey="n" href="Blocks-In-Python.html#Blocks-In-Python">Blocks In Python</a>, 46Previous: <a rel="previous" accesskey="p" href="Objfiles-In-Python.html#Objfiles-In-Python">Objfiles In Python</a>, 47Up: <a rel="up" accesskey="u" href="Python-API.html#Python-API">Python API</a> 48<hr> 49</div> 50 51<h5 class="subsubsection">23.2.2.15 Accessing inferior stack frames from Python.</h5> 52 53<p><a name="index-frames-in-python-1817"></a>When the debugged program stops, <span class="sc">gdb</span> is able to analyze its call 54stack (see <a href="Frames.html#Frames">Stack frames</a>). The <code>gdb.Frame</code> class 55represents a frame in the stack. A <code>gdb.Frame</code> object is only valid 56while its corresponding frame exists in the inferior's stack. If you try 57to use an invalid frame object, <span class="sc">gdb</span> will throw a <code>RuntimeError</code> 58exception. 59 60 <p>Two <code>gdb.Frame</code> objects can be compared for equality with the <code>==</code> 61operator, like: 62 63<pre class="smallexample"> (gdb) python print gdb.newest_frame() == gdb.selected_frame () 64 True 65</pre> 66 <p>The following frame-related functions are available in the <code>gdb</code> module: 67 68 <p><a name="index-gdb_002eselected_005fframe-1818"></a> 69 70<div class="defun"> 71— Function: <b>selected_frame</b><var><a name="index-selected_005fframe-1819"></a></var><br> 72<blockquote><p>Return the selected frame object. (see <a href="Selection.html#Selection">Selecting a Frame</a>). 73</p></blockquote></div> 74 75<div class="defun"> 76— Function: <b>frame_stop_reason_string</b><var> reason<a name="index-frame_005fstop_005freason_005fstring-1820"></a></var><br> 77<blockquote><p>Return a string explaining the reason why <span class="sc">gdb</span> stopped unwinding 78frames, as expressed by the given <var>reason</var> code (an integer, see the 79<code>unwind_stop_reason</code> method further down in this section). 80</p></blockquote></div> 81 82 <p>A <code>gdb.Frame</code> object has the following methods: 83 84 <dl> 85 86 <div class="defun"> 87— Method on Frame: <b>is_valid</b><var><a name="index-is_005fvalid-on-Frame-1821"></a></var><br> 88<blockquote> <p>Returns true if the <code>gdb.Frame</code> object is valid, false if not. 89A frame object can become invalid if the frame it refers to doesn't 90exist anymore in the inferior. All <code>gdb.Frame</code> methods will throw 91an exception if it is invalid at the time the method is called. 92</p></blockquote></div> 93 94 <div class="defun"> 95— Method on Frame: <b>name</b><var><a name="index-name-on-Frame-1822"></a></var><br> 96<blockquote> <p>Returns the function name of the frame, or <code>None</code> if it can't be 97obtained. 98</p></blockquote></div> 99 100 <div class="defun"> 101— Method on Frame: <b>type</b><var><a name="index-type-on-Frame-1823"></a></var><br> 102<blockquote> <p>Returns the type of the frame. The value can be one of 103<code>gdb.NORMAL_FRAME</code>, <code>gdb.DUMMY_FRAME</code>, <code>gdb.SIGTRAMP_FRAME</code> 104or <code>gdb.SENTINEL_FRAME</code>. 105</p></blockquote></div> 106 107 <div class="defun"> 108— Method on Frame: <b>unwind_stop_reason</b><var><a name="index-unwind_005fstop_005freason-on-Frame-1824"></a></var><br> 109<blockquote> <p>Return an integer representing the reason why it's not possible to find 110more frames toward the outermost frame. Use 111<code>gdb.frame_stop_reason_string</code> to convert the value returned by this 112function to a string. 113</p></blockquote></div> 114 115 <div class="defun"> 116— Method on Frame: <b>pc</b><var><a name="index-pc-on-Frame-1825"></a></var><br> 117<blockquote> <p>Returns the frame's resume address. 118</p></blockquote></div> 119 120 <div class="defun"> 121— Method on Frame: <b>block</b><var><a name="index-block-on-Frame-1826"></a></var><br> 122<blockquote> <p>Return the frame's code block. See <a href="Blocks-In-Python.html#Blocks-In-Python">Blocks In Python</a>. 123</p></blockquote></div> 124 125 <div class="defun"> 126— Method on Frame: <b>function</b><var><a name="index-function-on-Frame-1827"></a></var><br> 127<blockquote> <p>Return the symbol for the function corresponding to this frame. 128See <a href="Symbols-In-Python.html#Symbols-In-Python">Symbols In Python</a>. 129</p></blockquote></div> 130 131 <div class="defun"> 132— Method on Frame: <b>older</b><var><a name="index-older-on-Frame-1828"></a></var><br> 133<blockquote> <p>Return the frame that called this frame. 134</p></blockquote></div> 135 136 <div class="defun"> 137— Method on Frame: <b>newer</b><var><a name="index-newer-on-Frame-1829"></a></var><br> 138<blockquote> <p>Return the frame called by this frame. 139</p></blockquote></div> 140 141 <div class="defun"> 142— Method on Frame: <b>find_sal</b><var><a name="index-find_005fsal-on-Frame-1830"></a></var><br> 143<blockquote> <p>Return the frame's symtab and line object. 144See <a href="Symbol-Tables-In-Python.html#Symbol-Tables-In-Python">Symbol Tables In Python</a>. 145</p></blockquote></div> 146 147 <div class="defun"> 148— Method on Frame: <b>read_var</b><var> variable </var><span class="roman">[</span><var>block</var><span class="roman">]</span><var><a name="index-read_005fvar-on-Frame-1831"></a></var><br> 149<blockquote> <p>Return the value of <var>variable</var> in this frame. If the optional 150argument <var>block</var> is provided, search for the variable from that 151block; otherwise start at the frame's current block (which is 152determined by the frame's current program counter). <var>variable</var> 153must be a string or a <code>gdb.Symbol</code> object. <var>block</var> must be a 154<code>gdb.Block</code> object. 155</p></blockquote></div> 156 157 <div class="defun"> 158— Method on Frame: <b>select</b><var><a name="index-select-on-Frame-1832"></a></var><br> 159<blockquote> <p>Set this frame to be the selected frame. See <a href="Stack.html#Stack">Examining the Stack</a>. 160</p></blockquote></div> 161 </dl> 162 163 </body></html> 164 165