When the debugged program stops, GDB is able to analyze its call
stack (see Stack frames). The
represents a frame in the stack. A
gdb.Frame object is only valid
while its corresponding frame exists in the inferior’s stack. If you try
to use an invalid frame object, GDB will throw a
exception (see Exception Handling).
gdb.Frame objects can be compared for equality with the
(gdb) python print gdb.newest_frame() == gdb.selected_frame () True
The following frame-related functions are available in the
reasoncode (an integer, see the
unwind_stop_reasonmethod further down in this section).
GDB internally keeps a cache of the frames that have been unwound. This function invalidates this cache.
This function should not generally be called by ordinary Python code. It is documented for the sake of completeness.
gdb.Frame object has the following methods:
gdb.Frameobject is valid, false if not. A frame object can become invalid if the frame it refers to doesn’t exist anymore in the inferior. All
gdb.Framemethods will throw an exception if it is invalid at the time the method is called.
Noneif it can’t be obtained.
gdb.Architectureobject corresponding to the frame’s architecture. See Architectures In Python.
gdb.NORMAL_FRAMEthat is older than this one.
gdb.NORMAL_FRAME, but it is only used for the newest frame.
Return an integer representing the reason why it’s not possible to find
more frames toward the outermost frame. Use
gdb.frame_stop_reason_string to convert the value returned by this
function to a string. The value can be one of:
No particular reason (older frames should be available).
The previous frame’s analyzer returns an invalid result. This is no longer used by GDB, and is kept only for backward compatibility.
This frame is the outermost.
Cannot unwind further, because that would require knowing the values of registers or memory that have not been collected.
This frame ID looks like it ought to belong to a NEXT frame, but we got it for a PREV frame. Normally, this is a sign of unwinder failure. It could also indicate stack corruption.
This frame has the same ID as the previous one. That means that unwinding further would almost certainly give us another frame with exactly the same ID, so break the chain. Normally, this is a sign of unwinder failure. It could also indicate stack corruption.
The frame unwinder did not find any saved PC, but we needed one to unwind further.
The frame unwinder caused an error while trying to access memory.
Any stop reason greater or equal to this value indicates some kind of error. This special value facilitates writing code that tests for errors in unwinding in a way that will work correctly even if the list of the other values is modified in future GDB versions. Using it, you could write:
reason = gdb.selected_frame().unwind_stop_reason () reason_str = gdb.frame_stop_reason_string (reason) if reason >= gdb.FRAME_UNWIND_FIRST_ERROR: print "An error occured: %s" % reason_str
Return the value of
register in this frame. Returns a
Gdb.Value object. Throws an exception if
not exist. The
register argument must be one of the following:
gdb.RegisterDescriptorobject (see Registers In Python).
platform-tdep.hfile in the GDB source tree.
Using a string to access registers will be slightly slower than the
other two methods as GDB must look up the mapping between
name and internal register number. If performance is critical
consider looking up and caching a
variablein this frame. If the optional argument
blockis provided, search for the variable from that block; otherwise start at the frame’s current block (which is determined by the frame’s current program counter). The
variableargument must be a string or a
blockmust be a