1 ;;;; (ice-9 debugger commands) -- debugger commands
3 ;;; Copyright (C) 2002, 2006 Free Software Foundation, Inc.
5 ;; This library is free software; you can redistribute it and/or
6 ;; modify it under the terms of the GNU Lesser General Public
7 ;; License as published by the Free Software Foundation; either
8 ;; version 2.1 of the License, or (at your option) any later version.
10 ;; This library is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;; Lesser General Public License for more details.
15 ;; You should have received a copy of the GNU Lesser General Public
16 ;; License along with this library; if not, write to the Free Software
17 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 (define-module (ice-9 debugger commands)
20 #:use-module (ice-9 debug)
21 #:use-module (ice-9 debugger)
22 #:use-module (ice-9 debugger state)
23 #:use-module (ice-9 debugger utils)
33 (define (backtrace state n-frames)
34 "Print backtrace of all stack frames, or innermost COUNT frames.
35 With a negative argument, print outermost -COUNT frames.
36 If the number of frames isn't explicitly given, the debug option
37 `depth' determines the maximum number of frames printed."
38 (let ((stack (state-stack state)))
39 ;; Kludge around lack of call-with-values.
42 (display-backtrace stack
44 (if (memq 'backwards (debug-options))
49 (let ((end (stack-length stack)))
50 (cond ((not n-frames) ;(>= (abs n-frames) end))
51 (values 0 (min end (cadr (memq 'depth (debug-options))))))
55 (values (+ end n-frames) end)))))))
57 (define (eval-handler key . args)
58 (let ((stack (make-stack #t eval-handler)))
59 (if (= (length args) 4)
60 (apply display-error stack (current-error-port) args)
61 ;; We want display-error to be the "final common pathway"
64 (apply bad-throw key args))
66 (apply display-error stack (current-error-port) args)))))
69 (define (evaluate state expression)
70 "Evaluate an expression.
71 The expression must appear on the same line as the command,
72 however it may be continued over multiple lines."
73 (let ((source (frame-source (stack-ref (state-stack state)
74 (state-index state)))))
76 (display "No environment for this frame.\n")
82 ;; We assume that no one will
83 ;; really want to evaluate a
84 ;; string (since it is
85 ;; self-evaluating); so if we
86 ;; have a string here, read the
87 ;; expression to evaluate from
89 (if (string? expression)
90 (with-input-from-string expression
93 (env (memoized-environment source))
94 (value (local-eval expr env)))
100 (lambda args args)))))
102 (define (info-args state)
103 "Argument variables of current stack frame."
104 (let ((index (state-index state)))
105 (let ((frame (stack-ref (state-stack state) index)))
106 (write-frame-index-long frame)
107 (write-frame-args-long frame))))
109 (define (info-frame state)
110 "All about selected stack frame."
111 (write-state-long state))
113 (define (position state)
114 "Display the position of the current expression."
115 (let* ((frame (stack-ref (state-stack state) (state-index state)))
116 (source (frame-source frame)))
118 (display "No source available for this frame.")
119 (let ((position (source-position source)))
121 (display "No position information available for this frame.")
122 (display-position position)))))
126 "Move @var{n} frames up the stack. For positive @var{n}, this
127 advances toward the outermost frame, to higher frame numbers, to
128 frames that have existed longer. @var{n} defaults to one."
129 (set-stack-index! state (+ (state-index state) (or n 1)))
130 (write-state-short state))
132 (define (down state n)
133 "Move @var{n} frames down the stack. For positive @var{n}, this
134 advances toward the innermost frame, to lower frame numbers, to frames
135 that were created more recently. @var{n} defaults to one."
136 (set-stack-index! state (- (state-index state) (or n 1)))
137 (write-state-short state))
139 (define (frame state n)
140 "Select and print a stack frame.
141 With no argument, print the selected stack frame. (See also \"info frame\").
142 An argument specifies the frame to select; it must be a stack-frame number."
143 (if n (set-stack-index! state (frame-number->index n (state-stack state))))
144 (write-state-short state))
146 ;;; (ice-9 debugger commands) ends here.