Next: , Previous: , Up: Guile API   [Contents][Index] Accessing inferior stack frames from Guile.

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:invalid-object exception (see Guile Exception Handling).

Two <gdb:frame> objects can be compared for equality with the equal? function, like:

(gdb) guile (equal? (newest-frame) (selected-frame))

The following frame-related procedures are provided by the (gdb) module:

Scheme Procedure: frame? object

Return #t if object is a <gdb:frame> object. Otherwise return #f.

Scheme Procedure: frame-valid? frame

Returns #t if frame is valid, #f if not. A frame object can become invalid if the frame it refers to doesn’t exist anymore in the inferior. All <gdb:frame> procedures will throw an exception if the frame is invalid at the time the procedure is called.

Scheme Procedure: frame-name frame

Return the function name of frame, or #f if it can’t be obtained.

Scheme Procedure: frame-arch frame

Return the <gdb:architecture> object corresponding to frame’s architecture. See Architectures In Guile.

Scheme Procedure: frame-type frame

Return the type of frame. The value can be one of:


An ordinary stack frame.


A fake stack frame that was created by GDB when performing an inferior function call.


A frame representing an inlined function. The function was inlined into a NORMAL_FRAME that is older than this one.


A frame representing a tail call. See Tail Call Frames.


A signal trampoline frame. This is the frame created by the OS when it calls into a signal handler.


A fake stack frame representing a cross-architecture call.


This is like NORMAL_FRAME, but it is only used for the newest frame.

Scheme Procedure: frame-unwind-stop-reason frame

Return an integer representing the reason why it’s not possible to find more frames toward the outermost frame. Use unwind-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 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:

(define reason (frame-unwind-stop-readon (selected-frame)))
(define reason-str (unwind-stop-reason-string reason))
    (format #t "An error occurred: ~s\n" reason-str))
Scheme Procedure: frame-pc frame

Return the frame’s resume address.

Scheme Procedure: frame-block frame

Return the frame’s code block as a <gdb:block> object. See Blocks In Guile.

Scheme Procedure: frame-function frame

Return the symbol for the function corresponding to this frame as a <gdb:symbol> object, or #f if there isn’t one. See Symbols In Guile.

Scheme Procedure: frame-older frame

Return the frame that called frame.

Scheme Procedure: frame-newer frame

Return the frame called by frame.

Scheme Procedure: frame-sal frame

Return the frame’s <gdb:sal> (symtab and line) object. See Symbol Tables In Guile.

Scheme Procedure: frame-read-register frame register

Return the value of register in frame. register should be a string, like ‘pc’.

Scheme Procedure: frame-read-var frame variable [#:block block]

Return the value of variable in 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 must be given as a string or a <gdb:symbol> object, and block must be a <gdb:block> object.

Scheme Procedure: frame-select frame

Set frame to be the selected frame. See Examining the Stack.

Scheme Procedure: selected-frame

Return the selected frame object. See Selecting a Frame.

Scheme Procedure: newest-frame

Return the newest frame object for the selected thread.

Scheme Procedure: unwind-stop-reason-string reason

Return a string explaining the reason why GDB stopped unwinding frames, as expressed by the given reason code (an integer, see the frame-unwind-stop-reason procedure above in this section).

Next: , Previous: , Up: Guile API   [Contents][Index]