Next: Blocks In Python, Previous: Objfiles In Python, Up: Python API
When the debugged program stops, gdb is able to analyze its call
stack (see Stack frames). The gdb.Frame
class
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 gdb.error
exception (see Exception Handling).
Two gdb.Frame
objects can be compared for equality with the ==
operator, like:
(gdb) python print gdb.newest_frame() == gdb.selected_frame () True
The following frame-related functions are available in the gdb
module:
Return a string explaining the reason why gdb stopped unwinding frames, as expressed by the given reason code (an integer, see the
unwind_stop_reason
method further down in this section).
A gdb.Frame
object has the following methods:
Returns true if the
gdb.Frame
object is valid, false if not. A frame object can become invalid if the frame it refers to doesn't exist anymore in the inferior. Allgdb.Frame
methods will throw an exception if it is invalid at the time the method is called.
Returns the
gdb.Architecture
object corresponding to the frame's architecture. See Architectures In Python.
Returns the type of the frame. The value can be one of:
gdb.NORMAL_FRAME
- An ordinary stack frame.
gdb.DUMMY_FRAME
- A fake stack frame that was created by gdb when performing an inferior function call.
gdb.INLINE_FRAME
- A frame representing an inlined function. The function was inlined into a
gdb.NORMAL_FRAME
that is older than this one.gdb.TAILCALL_FRAME
- A frame representing a tail call. See Tail Call Frames.
gdb.SIGTRAMP_FRAME
- A signal trampoline frame. This is the frame created by the OS when it calls into a signal handler.
gdb.ARCH_FRAME
- A fake stack frame representing a cross-architecture call.
gdb.SENTINEL_FRAME
- This is like
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:
gdb.FRAME_UNWIND_NO_REASON
- No particular reason (older frames should be available).
gdb.FRAME_UNWIND_NULL_ID
- The previous frame's analyzer returns an invalid result. This is no longer used by gdb, and is kept only for backward compatibility.
gdb.FRAME_UNWIND_OUTERMOST
- This frame is the outermost.
gdb.FRAME_UNWIND_UNAVAILABLE
- Cannot unwind further, because that would require knowing the values of registers or memory that have not been collected.
gdb.FRAME_UNWIND_INNER_ID
- 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.
gdb.FRAME_UNWIND_SAME_ID
- 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.
gdb.FRAME_UNWIND_NO_SAVED_PC
- The frame unwinder did not find any saved PC, but we needed one to unwind further.
gdb.FRAME_UNWIND_MEMORY_ERROR
- The frame unwinder caused an error while trying to access memory.
gdb.FRAME_UNWIND_FIRST_ERROR
- 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 symbol for the function corresponding to this frame. See Symbols In Python.
Return the frame's symtab and line object. See Symbol Tables In Python.
Return the value of register in this frame. The register argument must be a string (e.g.,
'sp'
or'rax'
). Returns aGdb.Value
object. Throws an exception if register does not exist.
Return the value of variable in this frame. If the optional argument block is 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 variable argument must be a string or a
gdb.Symbol
object; block must be agdb.Block
object.