Previous: Associating Buffers with Clients, Up: Using Guile in Emacs

3.5.8 An Example GDS Session

Create a file, testgds.scm say, for experimenting with GDS and Scheme code, and type this into it:

     (use-modules (ice-9 debugging traps)
                  (ice-9 gds-client)
                  (ice-9 debugging example-fns))
     (install-trap (make <procedure-trap>
                     #:behaviour gds-debug-trap
                     #:procedure fact1))

Now select all of this code and type C-c C-r to send the selected region to Guile for evaluation. GDS will ask you which Guile process to use; unless you know that you already have another Guile application running and connected to GDS, choose the “Start a new Guile” option, which starts one of the “utility” processes described in GDS Getting Started.

The results of the evaluation pop up in a window like this:

     (use-modules (ice-9 debugging traps)\n    ...
     ;;; Evaluating subexpression 1 in current module (guile-user)
      ⇒ no (or unspecified) value
     ;;; Evaluating subexpression 2 in current module (guile-user)
      ⇒ no (or unspecified) value
     --:**  *Guile Evaluation*     (Scheme:ready)--All------------

this tells you that the evaluation was successful but that the return values were unspecified. Its effect was to load a module of example functions and set a trap on one of these functions, fact1, that calculates the factorial of its argument.

If you now call fact1, you can see the trap and GDS's stack display in action. To do this add

     (fact1 4)

to your testgds.scm buffer and type C-x C-e (which evaluates the expression that the cursor is just after the end of). The result should be that a GDS stack window like the following appears:

     Calling procedure:
     => s  [fact1 4]
        s  [primitive-eval (fact1 4)]
     --:**  PID 28729         (Guile-Debug)--All------------

This stack tells you that Guile is about to call the fact1 procedure, with argument 4, and you can step through this call in detail by pressing i once and then <SPC> (see Continuing Execution).

(i is needed as the first keystroke rather than <SPC>, because the aim here is to step through code in the (ice-9 debugging example-fns) module, whose source file is .../ice-9/debugging/example-fns.scm, but the initial (fact1 4) call comes from the Guile session, whose “source file” Guile presents as standard input. If the user starts by pressing <SPC> instead of i, the effect is that the program runs until it hits the first recursive call (fact1 (- n 1)), where it stops because of the trap on fact1 firing again. At this point, the source file is .../ice-9/debugging/example-fns.scm, because the recursive (fact1 (- n 1)) call comes from code in that file, so further pressing of <SPC> successfully single-steps through this file.)