1 ;;; Copyright (C) 2010-2011, 2013-2015 Rocky Bernstein <rocky@gnu.org>
2 (require 'load-relative)
3 (require-relative-list '("send" "core") "realgud-")
4 (require-relative-list '("buffer/command") "realgud-buffer-")
5 (require-relative-list '("buffer/source") "realgud-buffer-")
7 (declare-function buffer-killed? 'helper)
8 (declare-function realgud-cmdbuf-info-in-srcbuf?= 'realgud-buffer-command)
9 (declare-function realgud-cmdbuf? 'realgud-buffer-command)
10 (declare-function realgud-command 'realgud-cmd)
11 (declare-function realgud-get-cmdbuf 'realgud-buffer-helper)
12 (declare-function realgud-get-command 'realgud-buffer-command)
13 (declare-function realgud-get-bpnum-from-line-num 'realgud-buffer-source)
15 (declare-function realgud:terminate 'realgud-core)
16 (declare-function realgud:terminate-srcbuf 'realdgud-core)
18 (defun realgud:cmd-remap(arg cmd-name default-cmd-template key
19 &optional no-record? frame-switch?
21 "Run debugger command CMD-NAME using DEFAULT-CMD-TEMPLATE
22 if none has been set in the command hash. If key is given we'll set
23 a shortcut for that key."
24 (let ((buffer (current-buffer))
25 (cmdbuf (realgud-get-cmdbuf))
29 (with-current-buffer-safe cmdbuf
30 (realgud-cmdbuf-info-in-srcbuf?= (not (realgud-cmdbuf? buffer)))
31 (setq cmd-hash (realgud-cmdbuf-info-cmd-hash realgud-cmdbuf-info))
32 (unless (and cmd-hash (setq cmd (gethash cmd-name cmd-hash)))
33 (setq cmd default-cmd-template))
35 (realgud-command cmd arg no-record? frame-switch? realgud-prompts?)
36 ;; FIXME: Figure out how to update the position if the source
37 ;; buffer is displayed.
39 ;; (let* ((src-buffer (realgud-get-srcbuf-from-cmdbuf cmdbuf))
40 ;; (src-window (get-buffer-window src-buffer))
42 ;; (with-selected-window src-window
43 ;; (message "recentering...")
44 ;; (realgud-recenter-arrow)
47 ;; FIXME: this is a one-time thing. Put in caller.
49 (local-set-key (format "\C-c%s" key)
50 (intern (format "realgud:cmd-%s" cmd-name)))
54 (defun realgud:cmd-backtrace(arg)
55 "Show the current call stack"
57 (realgud:cmd-remap arg "backtrace" "backtrace" "T")
60 (defun realgud:cmd-break(arg)
61 "Set a breakpoint at the current line"
63 (realgud:cmd-remap arg "break" "break %X:%l" "b"))
65 (defun realgud:cmd-clear(line-num)
66 "Delete breakpoint at the current line"
68 (realgud:cmd-remap line-num "clear" "clear %l" "X"))
70 (defun realgud:cmd-continue(&optional arg)
72 (interactive "MContinue args: ")
73 (realgud:cmd-remap arg "continue" "continue" "c")
76 (defun realgud:cmd-delete(&optional arg)
77 "Delete breakpoint by number."
78 (interactive "pBreakpoint number: ")
79 (let* ((line-num (line-number-at-pos))
80 (arg (realgud-get-bpnum-from-line-num line-num)))
82 (realgud:cmd-remap arg "delete" "delete %p" "D")
83 (message "Can't find breakpoint at line %d" line-num))
87 (defun realgud:cmd-disable(&optional arg)
89 (interactive "NBreakpoint number: ")
90 (realgud:cmd-remap arg "disable" "disable %p" "-")
93 (defun realgud:cmd-enable(&optional arg)
95 (interactive "NBreakpoint number: ")
96 (realgud:cmd-remap arg "enable" "enable %p" "+")
99 (defun realgud:cmd-eval(arg)
100 "Exaluate an expression."
101 (interactive "MEval expesssion: ")
102 (realgud:cmd-remap arg "eval" "eval %s" "e")
105 (defun realgud:cmd-eval-region(start end)
107 (let ((text (buffer-substring-no-properties start end)))
108 (realgud:cmd-remap text "eval" "eval %s" "e")
112 (defun realgud:cmd-finish(&optional arg)
113 "Run until the completion of the current stack frame.
115 This command is often referred to as 'step out' as opposed to
116 'step over' or 'step into'.
119 (realgud:cmd-remap arg "finish" "finish" ".")
122 (defun realgud:cmd-frame(arg)
123 "Change the current frame number to the value of the numeric argument.
124 If no argument specified use 0 or the most recent frame."
126 (realgud:cmd-remap arg "frame" "frame %p" "f" t t)
129 (defun realgud:cmd-kill(arg)
130 "kill debugger process"
132 (realgud:cmd-remap arg "kill" "kill" "k" nil nil 't)
135 (defun realgud:cmd-newer-frame(&optional arg)
136 "Move the current frame to a newer (more recent) frame.
137 With a numeric argument move that many levels forward."
139 (realgud:cmd-remap arg "down" "down %p" "<" t t)
142 (defun realgud:cmd-next(&optional arg)
143 "Step one source line at current call level.
145 With a numeric argument, step that many times. This command is
146 often referred to as 'step through' as opposed to 'step into' or
149 The definition of 'next' is debugger specific so, see the
150 debugger documentation for a more complete definition of what is
153 (realgud:cmd-remap arg "next" "next %p" "n")
156 (defun realgud:cmd-next-no-arg(&optional arg)
157 "Step one source line at current call level.
159 The definition of 'next' is debugger specific so, see the
160 debugger documentation for a more complete definition of what is
163 (realgud:cmd-remap nil "next" "next" "n")
166 (defun realgud:cmd-older-frame(&optional arg)
167 "Move the current frame to an older (less recent) frame.
168 With a numeric argument move that many levels back."
170 (realgud:cmd-remap arg "up" "up %p" ">" t t)
173 (defun realgud:cmd-restart(&optional arg)
175 (interactive "MRestart args: ")
176 (realgud:cmd-remap arg "restart" "run" "R" 't nil 't)
179 (defun realgud:cmd-shell(&optional arg)
182 (realgud:cmd-remap arg "shell" "shell" "S")
185 (defun realgud:cmd-step(&optional arg)
186 "Step one source line.
188 With a numeric argument, step that many times.
189 This command is often referred to as 'step into' as opposed to
190 'step over' or 'step out'.
192 The definition of 'step' is debugger specific so, see the
193 debugger documentation for a more complete definition of what is
196 (realgud:cmd-remap arg "step" "step %p" "s")
199 (defun realgud:cmd-step-no-arg()
200 "Step one source line.
202 The definition of 'step' is debugger specific so, see the
203 debugger documentation for a more complete definition of what is
206 (realgud:cmd-remap nil "step" "step" "s")
209 (defun realgud:cmd-terminate (&optional arg)
210 "Gently terminate source and command buffers without possibly
211 issuing a command to the underlying debuger. Use this if the
212 underlying debugger has died or you want to get out of all
213 shortkey modes in the source window and possibly restart
214 debugging after editing source."
216 (realgud:terminate (current-buffer))
219 (defun realgud:cmd-until(&optional arg)
220 "Run until the completion of the current stack frame.
222 Continue until the current line. In some cases this is really
223 two commands - setting a temporary breakpoint on the line and
224 continuing execution."
226 (realgud:cmd-remap arg "until" "until" "u")
229 (defun realgud:cmd-quit (&optional arg)
230 "Gently terminate execution of the debugged program."
232 (let ((buffer (current-buffer))
233 (cmdbuf (realgud-get-cmdbuf))
239 (with-current-buffer cmdbuf
240 (realgud-cmdbuf-info-in-srcbuf?= (not (realgud-cmdbuf? buffer)))
241 (setq cmd-hash (realgud-cmdbuf-info-cmd-hash realgud-cmdbuf-info))
242 (unless (and cmd-hash (setq cmd (gethash "quit" cmd-hash)))
245 (realgud-command cmd arg 't)
246 (if cmdbuf (realgud:terminate cmdbuf))
249 (realgud:terminate-srcbuf buffer)
254 (local-set-key "\C-cq" 'realgud:cmd-quit)
256 (provide-me "realgud-")