[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] add debugger command to quit Guile, allow evaluating (exit)

From: Derek Peschel
Subject: [PATCH] add debugger command to quit Guile, allow evaluating (exit)
Date: Sat, 22 Nov 2008 17:17:27 -0800
User-agent: Mutt/

This patch replaces my patch from a few days ago.  I've tested it with
Guile 1.8.4, except using (ice-9 debugging) from Guile 1.8.5.  Apply the
patch in the ice-9/debugging directory.  It allows the following to work
in the terminal debugger:

  quit-guile NONNEGINT          quits Guile process with given int
  quit-guile                    or uses 0 if not given
  evaluate (exit ARG)           like typing (exit ARG) in the REPL
  evaluate (exit)               like typing (exit) in the REPL

plus any synonyms for the "evaluate" command and the (exit) function.

When running the "quit-guile" command, the debugger checks the type of
the argument and always calls (quit) with a nonnegative integer.  When
running the "evaluate" command, the call to (quit) happens exactly as
typed.  All checks are left to the code in (ice-9 boot-9).  The different
metasynctactic variables emphasize this difference in behavior.

Compared to the REPL, the debugger adds its own exception handlers which
must rethrow any quit exceptions they get.  Rethrowing could threoretically
change the exception that (ice-9 boot-9) gets.  In practice the supported
input forms all work and I doubt the rethrowing will ever have any effect.

The patch doesn't affect the Emacs debugger.

--- command-loop.scm.orig       2008-11-21 13:15:21.000000000 -0800
+++ command-loop.scm    2008-11-21 12:37:41.000000000 -0800
@@ -45,6 +45,8 @@
      ;; Restore stack
      (fluid-set! the-last-stack (fluid-ref before-signal-stack))
      (apply display-error #f (current-error-port) args))
+    ((quit)
+     (apply throw key args))
      (display "Internal debugger error:\n")
      (save-stack debugger-handler)
@@ -534,6 +536,8 @@
     "Exit the debugger."
+(define-command "quit-guile" '('optional exact-nonnegative-integer) 
 (define-command-alias "f" "frame")
 (define-command-alias '("info" "f") '("info" "frame"))
 (define-command-alias "bt" "backtrace")
--- commands.scm.orig   2008-11-21 12:36:28.000000000 -0800
+++ commands.scm        2008-11-21 12:41:39.000000000 -0800
@@ -28,7 +28,8 @@
-           frame))
+           frame
+           quit-guile))
 (define (backtrace state n-frames)
   "Print backtrace of all stack frames, or innermost COUNT frames.
@@ -55,6 +56,8 @@
               (values (+ end n-frames) end)))))))
 (define (eval-handler key . args)
+  (if (eq? key 'quit)
+      (apply throw key args))
   (let ((stack (make-stack #t eval-handler)))
     (if (= (length args) 4)
        (apply display-error stack (current-error-port) args)
@@ -143,4 +146,9 @@
   (if n (set-stack-index! state (frame-number->index n (state-stack state))))
   (write-state-short state))
+(define (quit-guile state arg)
+  "Exit Guile with status @var{arg}.
+With no argument, exit with status 0."
+  (quit (or arg 0)))
 ;;; (ice-9 debugger commands) ends here.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]