-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdebug.el
328 lines (252 loc) · 10.9 KB
/
rdebug.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
;;; rdebug.el --- Ruby debugger user interface, startup file.
;; Copyright (C) 2006, 2007, 2008, 2010 Rocky Bernstein ([email protected])
;; Copyright (C) 2007, 2008 Anders Lindgren
;; $Id: rdebug.el 409 2007-12-14 02:36:37Z rockyb $
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;
;; Introduction:
;;
;; This is a full-blown debugger user interface to the Ruby rdebug
;; debugger shell.
;;
;; The main features are:
;;
;; * Window layout with dedicated windows for:
;; + Local and member variables
;; + Stack trace
;; + Display expressions
;; + Breakpoints
;; + Output
;; + Debugger Shell
;;
;; * Source-level debugging:
;; + The current source file is shown and current line is marked.
;; + Function keys bindings for effective stepping in the source code.
;; + A "Debugger" menu for easy access to all features.
;;
;; * A number of predefined window layouts and key bindings are
;; supplied, including binding that emulate Eclipse and NetBeans.
;; The user can easily provide their own window layout and
;; settings.
;;
;; The default window layout looks like the following:
;;
;; +----------------------------------------------------------------------+
;; | Toolbar |
;; +-----------------------------------+----------------------------------+
;; | Debugger Stack Buffer | Local Variables buffer |
;; +-----------------------------------+----------------------------------+
;; | |
;; | Source buffer |
;; | |
;; +----------------------------------------------------------------------+
;; | Debugger Command Buffer |
;; +----------------------------------------------------------------------+
;;
;;
;; Installation:
;;
;; To use this package, place the either of following lines in an
;; appropriate init file (for example ~/.emacs):
;;
;; (require 'rdebug)
;; or
;; (autoload 'rdebug "rdebug" "ruby-debug interface" t)
;;
;; History and Future:
;;
;; The design of this debugger user interface was inspired by
;; `gdb-ui', a similar user interface to GDB.
;;
;; Hopefully, rdebug, gdb-ui, and other emacs user interfaces could
;; join forces to create a common user-level look and feel, and a
;; battery of underlying support functions.
;;
;;
;; This file contains only user-customizable variables and code to
;; load the other files when needed.
;;
;;; Code:
;; -------------------------------------------------------------------
;; Consistency checks.
;;
(if (< emacs-major-version 22)
(error
"This version of rdebug.el needs at least Emacs 22 or greater - you have version %d."
emacs-major-version))
;; -------------------------------------------------------------------
;; Support functions.
;;
(defun rdebug-directory ()
"The directory of this file, or nil."
(let ((file-name (or load-file-name
(symbol-file 'rdebug-directory))))
(if file-name
(file-name-directory file-name)
nil)))
(defun rdebug-compare-filenames (f1 f2)
"Canonicalize and compare file names."
;; Canonicalize by:
;; 1) file-truename ensures that the file has got the correct case,
;; and that "..":s in the path are eliminated.
;; 2) file-name-as-directory ensures "/foo" and "/foo/" becomes equal.
;; Note: for some reason, when the `comp-elisp' external program is
;; used, `nil' is part of `load-path'.
(if f1
(setq f1 (file-name-as-directory (file-truename f1))))
(if f2
(setq f2 (file-name-as-directory (file-truename f2))))
(equal f1 f2))
;; Add the directory of `rdebug.el' to the load-path. This ensures
;; that all the user have do to use this package is to load this file.
(let ((dir (rdebug-directory)))
(if dir
(add-to-list 'load-path dir nil 'rdebug-compare-filenames)))
;; -------------------------------------------------------------------
;; Autoloads.
;;
(autoload 'rdebug "rdebug-core"
"Run the rdebug Ruby debugger and start the Emacs user interface.
By default, the \"standard\" user window layout looks like the following:
+----------------------------------------------------------------------+
| Toolbar |
+-----------------------------------+----------------------------------+
| Debugger shell | Variables buffer |
+-----------------------------------+----------------------------------+
| | |
| Source buffer | Output buffer |
| | |
+-----------------------------------+----------------------------------+
| Stack buffer | Breakpoints buffer |
+-----------------------------------+----------------------------------+
The variable `rdebug-many-windows-layout-function' can be
customized so that another layout is used. In addition to a
number of predefined layouts it's possible to define a function
to perform a custom layout.
If `rdebug-many-windows' is nil, only a traditional debugger
shell and source window is opened.
The directory containing the debugged script becomes the initial
working directory and source-file directory for your debugger.
The custom variable `gud-rdebug-command-name' sets the command
and options used to invoke rdebug." t)
(autoload 'rdebug-turn-on-debugger-support "rdebug-source"
"Enable extra source buffer support for the `rdebug' Ruby debugger.
This includes a 'Debugger' menu and special key bindings when the
debugger is active."
t)
(autoload 'rdebug-track-attach "rdebug-track"
"Do things to make the current process buffer work like a
rdebug command buffer." t)
(autoload 'turn-on-rdebug-track-mode "rdebug-track"
"Turn on rdebugtrack mode.
This function is designed to be added to hooks, for example:
(add-hook 'comint-mode-hook 'turn-on-rdebugtrack-mode)"
t)
(add-hook 'ruby-mode-hook 'rdebug-turn-on-debugger-support)
;; This is needed, or at least the docstring part of it is needed to
;; get the customization menu to work in Emacs 23.
(defgroup rdebug nil
"The Ruby debugger"
:group 'processes
:group 'tools)
;; -------------------------------------------------------------------
;; User definable variables
;;
(defcustom gud-rdebug-command-name
"rdebug --emacs 3"
"File name for executing the Ruby debugger and command options.
This should be an executable on your path, or an absolute file name."
:type 'string
:group 'gud)
(defcustom rdebug-line-width 120
"Length of line before truncation occurs.
This value limits output in secondary buffers."
:type 'integer
:group 'rdebug)
(defcustom rdebug-many-windows t
"*If non-nil, use the full debugger user interface, see `rdebug'.
However only set to the multi-window display if the rdebug
command invocation has an annotate options (\"--annotate 3\")."
:type 'boolean
:group 'rdebug)
(defcustom rdebug-use-separate-io-buffer t
"*If non-nil, output goes to a dedicated windows.
This only applies when `rdebug-many-windows' is non-nil."
:type 'boolean
:group 'rdebug)
(defcustom rdebug-populate-common-keys-function
'rdebug-populate-common-keys-standard
"The function to call to populate key bindings common to all rdebug windows.
This includes the secondary windows, the debugger shell, and all
Ruby source buffers when the debugger is active.
This variable can be bound to the following:
* nil -- Don't bind any keys.
* `rdebug-populate-common-keys-standard' -- Bind according to a widely used
debugger convention:
\\{rdebug-example-map-standard}
* `rdebug-populate-common-keys-eclipse' -- Bind according to Eclipse.
\\{rdebug-example-map-eclipse}
* `rdebug-populate-common-keys-netbeans' -- Bind according to NetBeans.
\\{rdebug-example-map-netbeans}
* Any other value is expected to be a callable function that takes one
argument, the keymap, and populates it with suitable keys."
:type 'function
:group 'rdebug)
(defcustom rdebug-restore-original-window-configuration :many
"*Control if the original window layout is restored when the debugger exits.
The value can be t, nil, or :many.
A value of t means that the original layout is always restored,
nil means that it's never restored.
:many means that the original layout is restored only when
`rdebug-many-windows' is used."
:type '(choice (const :tag "Always restore" t)
(const :tag "Never restore" nil)
(const :tag "Restore in many windows mode" :many))
:group 'rdebug)
(defcustom rdebug-use-separate-io-buffer t
"Non-nil means display output from the debugged program in a separate buffer."
:type 'boolean
:group 'gud)
(defcustom rdebug-window-layout-function
'rdebug-window-layout-standard
"*A function that performs the window layout of `rdebug'.
This is only used in `rdebug-many-windows' mode. This should be
bound to a function that performs the actual window layout. The
function should takes two arguments, the first is the source
buffer and the second the name of the script to debug.
Rdebug provides the following predefined layout functions:
* `rdebug-window-layout-standard' -- See `rdebug'
* `rdebug-window-layout-no-shell' -- Standard + Display, no Shell
* `rdebug-window-layout-conservative' -- Source + Shell + Output
* `rdebug-window-layout-stack-of-windows' -- Extra windows to the right
* `rdebug-window-layout-rocky' -- Rocky's own layout"
:type
'(choice
(function :tag "Standard" rdebug-window-layout-standard)
(function :tag "Conservative" rdebug-window-layout-conservative)
(function :tag "Stack of windows" rdebug-window-layout-stack-of-windows)
(function :tag "Rocky's own" rdebug-window-layout-rocky)
(function :tag "Rocky's II" rdebug-window-layout-rocky2)
(function :tag "Other" function))
:group 'rdebug)
(defcustom rdebug-source-location-ring-size 150
"Size of rdebug position history ring."
:type 'integer
:group 'rdebug)
;; -------------------------------------------------------------------
;; The end.
;;
(provide 'rdebug)
;;; rdebug.el ends here