(Fframe_parameters) [!MULTI_FRAME]: Unstub it again.
[emacs.git] / lisp / gud.el
blobaaf289667779b99b033880a887d61bc507d3c5c4
1 ;;; gud.el --- Grand Unified Debugger mode for gdb, sdb, dbx, or xdb
2 ;;; under Emacs
4 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
5 ;; Maintainer: FSF
6 ;; Version: 1.3
7 ;; Keywords: unix, tools
9 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 ;;; Commentary:
29 ;; The ancestral gdb.el was by W. Schelter <wfs@rascal.ics.utexas.edu>
30 ;; It was later rewritten by rms. Some ideas were due to Masanobu.
31 ;; Grand Unification (sdb/dbx support) by Eric S. Raymond <esr@thyrsus.com>
32 ;; The overloading code was then rewritten by Barry Warsaw <bwarsaw@cen.com>,
33 ;; who also hacked the mode to use comint.el. Shane Hartman <shane@spr.com>
34 ;; added support for xdb (HPUX debugger). Rick Sladkey <jrs@world.std.com>
35 ;; wrote the GDB command completion code.
37 ;;; Code:
39 (require 'comint)
40 (require 'etags)
42 ;; ======================================================================
43 ;; GUD commands must be visible in C buffers visited by GUD
45 (defvar gud-key-prefix "\C-x\C-a"
46 "Prefix of all GUD commands valid in C buffers.")
48 (global-set-key (concat gud-key-prefix "\C-l") 'gud-refresh)
49 (global-set-key "\C-x " 'gud-break) ;; backward compatibility hack
51 ;; ======================================================================
52 ;; the overloading mechanism
54 (defun gud-overload-functions (gud-overload-alist)
55 "Overload functions defined in GUD-OVERLOAD-ALIST.
56 This association list has elements of the form
57 (ORIGINAL-FUNCTION-NAME OVERLOAD-FUNCTION)"
58 (mapcar
59 (function (lambda (p) (fset (car p) (symbol-function (cdr p)))))
60 gud-overload-alist))
62 (defun gud-massage-args (file args)
63 (error "GUD not properly entered."))
65 (defun gud-marker-filter (str)
66 (error "GUD not properly entered."))
68 (defun gud-find-file (f)
69 (error "GUD not properly entered."))
71 ;; ======================================================================
72 ;; command definition
74 ;; This macro is used below to define some basic debugger interface commands.
75 ;; Of course you may use `gud-def' with any other debugger command, including
76 ;; user defined ones.
78 ;; A macro call like (gud-def FUNC NAME KEY DOC) expands to a form
79 ;; which defines FUNC to send the command NAME to the debugger, gives
80 ;; it the docstring DOC, and binds that function to KEY in the GUD
81 ;; major mode. The function is also bound in the global keymap with the
82 ;; GUD prefix.
84 (defmacro gud-def (func cmd key &optional doc)
85 "Define FUNC to be a command sending STR and bound to KEY, with
86 optional doc string DOC. Certain %-escapes in the string arguments
87 are interpreted specially if present. These are:
89 %f name (without directory) of current source file.
90 %d directory of current source file.
91 %l number of current source line
92 %e text of the C lvalue or function-call expression surrounding point.
93 %a text of the hexadecimal address surrounding point
94 %p prefix argument to the command (if any) as a number
96 The `current' source file is the file of the current buffer (if
97 we're in a C file) or the source file current at the last break or
98 step (if we're in the GUD buffer).
99 The `current' line is that of the current buffer (if we're in a
100 source file) or the source line number at the last break or step (if
101 we're in the GUD buffer)."
102 (list 'progn
103 (list 'defun func '(arg)
104 (or doc "")
105 '(interactive "p")
106 (list 'gud-call cmd 'arg))
107 (if key
108 (list 'define-key
109 '(current-local-map)
110 (concat "\C-c" key)
111 (list 'quote func)))
112 (if key
113 (list 'global-set-key
114 (list 'concat 'gud-key-prefix key)
115 (list 'quote func)))))
117 ;; Where gud-display-frame should put the debugging arrow. This is
118 ;; set by the marker-filter, which scans the debugger's output for
119 ;; indications of the current program counter.
120 (defvar gud-last-frame nil)
122 ;; Used by gud-refresh, which should cause gud-display-frame to redisplay
123 ;; the last frame, even if it's been called before and gud-last-frame has
124 ;; been set to nil.
125 (defvar gud-last-last-frame nil)
127 ;; All debugger-specific information is collected here.
128 ;; Here's how it works, in case you ever need to add a debugger to the mode.
130 ;; Each entry must define the following at startup:
132 ;;<name>
133 ;; comint-prompt-regexp
134 ;; gud-<name>-massage-args
135 ;; gud-<name>-marker-filter
136 ;; gud-<name>-find-file
138 ;; The job of the massage-args method is to modify the given list of
139 ;; debugger arguments before running the debugger.
141 ;; The job of the marker-filter method is to detect file/line markers in
142 ;; strings and set the global gud-last-frame to indicate what display
143 ;; action (if any) should be triggered by the marker. Note that only
144 ;; whatever the method *returns* is displayed in the buffer; thus, you
145 ;; can filter the debugger's output, interpreting some and passing on
146 ;; the rest.
148 ;; The job of the find-file method is to visit and return the buffer indicated
149 ;; by the car of gud-tag-frame. This may be a file name, a tag name, or
150 ;; something else.
152 ;; ======================================================================
153 ;; gdb functions
155 ;;; History of argument lists passed to gdb.
156 (defvar gud-gdb-history nil)
158 (defun gud-gdb-massage-args (file args)
159 (cons "-fullname" (cons file args)))
161 ;; There's no guarantee that Emacs will hand the filter the entire
162 ;; marker at once; it could be broken up across several strings. We
163 ;; might even receive a big chunk with several markers in it. If we
164 ;; receive a chunk of text which looks like it might contain the
165 ;; beginning of a marker, we save it here between calls to the
166 ;; filter.
167 (defvar gud-gdb-marker-acc "")
169 (defun gud-gdb-marker-filter (string)
170 (save-match-data
171 (setq gud-gdb-marker-acc (concat gud-gdb-marker-acc string))
172 (let ((output ""))
174 ;; Process all the complete markers in this chunk.
175 (while (string-match "^\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
176 gud-gdb-marker-acc)
177 (setq
179 ;; Extract the frame position from the marker.
180 gud-last-frame
181 (cons (substring gud-gdb-marker-acc (match-beginning 1) (match-end 1))
182 (string-to-int (substring gud-gdb-marker-acc
183 (match-beginning 2)
184 (match-end 2))))
186 ;; Append any text before the marker to the output we're going
187 ;; to return - we don't include the marker in this text.
188 output (concat output
189 (substring gud-gdb-marker-acc 0 (match-beginning 0)))
191 ;; Set the accumulator to the remaining text.
192 gud-gdb-marker-acc (substring gud-gdb-marker-acc (match-end 0))))
194 ;; Does the remaining text look like it might end with the
195 ;; beginning of another marker? If it does, then keep it in
196 ;; gud-gdb-marker-acc until we receive the rest of it. Since we
197 ;; know the full marker regexp above failed, it's pretty simple to
198 ;; test for marker starts.
199 (if (string-match "^\032.*\\'" gud-gdb-marker-acc)
200 (progn
201 ;; Everything before the potential marker start can be output.
202 (setq output (concat output (substring gud-gdb-marker-acc
203 0 (match-beginning 0))))
205 ;; Everything after, we save, to combine with later input.
206 (setq gud-gdb-marker-acc
207 (substring gud-gdb-marker-acc (match-beginning 0))))
209 (setq output (concat output gud-gdb-marker-acc)
210 gud-gdb-marker-acc ""))
212 output)))
214 (defun gud-gdb-find-file (f)
215 (find-file-noselect f))
217 (defvar gdb-minibuffer-local-map nil
218 "Keymap for minibuffer prompting of gdb startup command.")
219 (if gdb-minibuffer-local-map
221 (setq gdb-minibuffer-local-map (copy-keymap minibuffer-local-map))
222 (define-key
223 gdb-minibuffer-local-map "\C-i" 'comint-dynamic-complete-filename))
225 ;;;###autoload
226 (defun gdb (command-line)
227 "Run gdb on program FILE in buffer *gud-FILE*.
228 The directory containing FILE becomes the initial working directory
229 and source-file directory for your debugger."
230 (interactive
231 (list (read-from-minibuffer "Run gdb (like this): "
232 (if (consp gud-gdb-history)
233 (car gud-gdb-history)
234 "gdb ")
235 gdb-minibuffer-local-map nil
236 '(gud-gdb-history . 1))))
237 (gud-overload-functions '((gud-massage-args . gud-gdb-massage-args)
238 (gud-marker-filter . gud-gdb-marker-filter)
239 (gud-find-file . gud-gdb-find-file)
242 (gud-common-init command-line)
244 (gud-def gud-break "break %f:%l" "\C-b" "Set breakpoint at current line.")
245 (gud-def gud-tbreak "tbreak %f:%l" "\C-t" "Set breakpoint at current line.")
246 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
247 (gud-def gud-step "step %p" "\C-s" "Step one source line with display.")
248 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
249 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).")
250 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
251 (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
252 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
253 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
254 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
256 (local-set-key "\C-i" 'gud-gdb-complete-command)
257 (setq comint-prompt-regexp "^(.*gdb[+]?) *")
258 (setq paragraph-start comint-prompt-regexp)
259 (run-hooks 'gdb-mode-hook)
262 ;; One of the nice features of GDB is its impressive support for
263 ;; context-sensitive command completion. We preserve that feature
264 ;; in the GUD buffer by using a GDB command designed just for Emacs.
266 ;; The completion process filter indicates when it is finished.
267 (defvar gud-gdb-complete-in-progress)
269 ;; Since output may arrive in fragments we accumulate partials strings here.
270 (defvar gud-gdb-complete-string)
272 ;; We need to know how much of the completion to chop off.
273 (defvar gud-gdb-complete-break)
275 ;; The completion list is constructed by the process filter.
276 (defvar gud-gdb-complete-list)
278 (defvar gud-comint-buffer nil)
280 (defun gud-gdb-complete-command ()
281 "Perform completion on the GDB command preceding point.
282 This is implemented using the GDB `complete' command which isn't
283 available with older versions of GDB."
284 (interactive)
285 (let* ((end (point))
286 (command (save-excursion
287 (beginning-of-line)
288 (and (looking-at comint-prompt-regexp)
289 (goto-char (match-end 0)))
290 (buffer-substring (point) end)))
291 command-word)
292 ;; Find the word break. This match will always succeed.
293 (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command)
294 (setq gud-gdb-complete-break (match-beginning 2)
295 command-word (substring command gud-gdb-complete-break))
296 (unwind-protect
297 (progn
298 ;; Temporarily install our filter function.
299 (gud-overload-functions
300 '((gud-marker-filter . gud-gdb-complete-filter)))
301 ;; Issue the command to GDB.
302 (gud-basic-call (concat "complete " command))
303 (setq gud-gdb-complete-in-progress t
304 gud-gdb-complete-string nil
305 gud-gdb-complete-list nil)
306 ;; Slurp the output.
307 (while gud-gdb-complete-in-progress
308 (accept-process-output (get-buffer-process gud-comint-buffer))))
309 ;; Restore the old filter function.
310 (gud-overload-functions '((gud-marker-filter . gud-gdb-marker-filter))))
311 ;; Protect against old versions of GDB.
312 (and gud-gdb-complete-list
313 (string-match "^Undefined command: \"complete\""
314 (car gud-gdb-complete-list))
315 (error "This version of GDB doesn't support the `complete' command."))
316 ;; Sort the list like readline.
317 (setq gud-gdb-complete-list
318 (sort gud-gdb-complete-list (function string-lessp)))
319 ;; Remove duplicates.
320 (let ((first gud-gdb-complete-list)
321 (second (cdr gud-gdb-complete-list)))
322 (while second
323 (if (string-equal (car first) (car second))
324 (setcdr first (setq second (cdr second)))
325 (setq first second
326 second (cdr second)))))
327 ;; Let comint handle the rest.
328 (comint-dynamic-simple-complete command-word gud-gdb-complete-list)))
330 ;; The completion process filter is installed temporarily to slurp the
331 ;; output of GDB up to the next prompt and build the completion list.
332 (defun gud-gdb-complete-filter (string)
333 (setq string (concat gud-gdb-complete-string string))
334 (while (string-match "\n" string)
335 (setq gud-gdb-complete-list
336 (cons (substring string gud-gdb-complete-break (match-beginning 0))
337 gud-gdb-complete-list))
338 (setq string (substring string (match-end 0))))
339 (if (string-match comint-prompt-regexp string)
340 (progn
341 (setq gud-gdb-complete-in-progress nil)
342 string)
343 (progn
344 (setq gud-gdb-complete-string string)
345 "")))
348 ;; ======================================================================
349 ;; sdb functions
351 ;;; History of argument lists passed to sdb.
352 (defvar gud-sdb-history nil)
354 (defvar gud-sdb-needs-tags (not (file-exists-p "/var"))
355 "If nil, we're on a System V Release 4 and don't need the tags hack.")
357 (defvar gud-sdb-lastfile nil)
359 (defun gud-sdb-massage-args (file args)
360 (cons file args))
362 (defun gud-sdb-marker-filter (string)
363 (cond
364 ;; System V Release 3.2 uses this format
365 ((string-match "\\(^0x\\w* in \\|^\\|\n\\)\\([^:\n]*\\):\\([0-9]*\\):.*\n"
366 string)
367 (setq gud-last-frame
368 (cons
369 (substring string (match-beginning 2) (match-end 2))
370 (string-to-int
371 (substring string (match-beginning 3) (match-end 3))))))
372 ;; System V Release 4.0
373 ((string-match "^\\(BREAKPOINT\\|STEPPED\\) process [0-9]+ function [^ ]+ in \\(.+\\)\n"
374 string)
375 (setq gud-sdb-lastfile
376 (substring string (match-beginning 2) (match-end 2))))
377 ((and gud-sdb-lastfile (string-match "^\\([0-9]+\\):" string))
378 (setq gud-last-frame
379 (cons
380 gud-sdb-lastfile
381 (string-to-int
382 (substring string (match-beginning 1) (match-end 1))))))
384 (setq gud-sdb-lastfile nil)))
385 string)
387 (defun gud-sdb-find-file (f)
388 (if gud-sdb-needs-tags
389 (find-tag-noselect f)
390 (find-file-noselect f)))
392 ;;;###autoload
393 (defun sdb (command-line)
394 "Run sdb on program FILE in buffer *gud-FILE*.
395 The directory containing FILE becomes the initial working directory
396 and source-file directory for your debugger."
397 (interactive
398 (list (read-from-minibuffer "Run sdb (like this): "
399 (if (consp gud-sdb-history)
400 (car gud-sdb-history)
401 "sdb ")
402 nil nil
403 '(gud-sdb-history . 1))))
404 (if (and gud-sdb-needs-tags
405 (not (and (boundp 'tags-file-name) (file-exists-p tags-file-name))))
406 (error "The sdb support requires a valid tags table to work."))
407 (gud-overload-functions '((gud-massage-args . gud-sdb-massage-args)
408 (gud-marker-filter . gud-sdb-marker-filter)
409 (gud-find-file . gud-sdb-find-file)
412 (gud-common-init command-line)
414 (gud-def gud-break "%l b" "\C-b" "Set breakpoint at current line.")
415 (gud-def gud-tbreak "%l c" "\C-t" "Set temporary breakpoint at current line.")
416 (gud-def gud-remove "%l d" "\C-d" "Remove breakpoint at current line")
417 (gud-def gud-step "s %p" "\C-s" "Step one source line with display.")
418 (gud-def gud-stepi "i %p" "\C-i" "Step one instruction with display.")
419 (gud-def gud-next "S %p" "\C-n" "Step one line (skip functions).")
420 (gud-def gud-cont "c" "\C-r" "Continue with display.")
421 (gud-def gud-print "%e/" "\C-p" "Evaluate C expression at point.")
423 (setq comint-prompt-regexp "\\(^\\|\n\\)\\*")
424 (setq paragraph-start comint-prompt-regexp)
425 (run-hooks 'sdb-mode-hook)
428 ;; ======================================================================
429 ;; dbx functions
431 ;;; History of argument lists passed to dbx.
432 (defvar gud-dbx-history nil)
434 (defun gud-dbx-massage-args (file args)
435 (cons file args))
437 (defun gud-dbx-marker-filter (string)
438 (if (or (string-match
439 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
440 string)
441 (string-match
442 "signal .* in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
443 string))
444 (setq gud-last-frame
445 (cons
446 (substring string (match-beginning 2) (match-end 2))
447 (string-to-int
448 (substring string (match-beginning 1) (match-end 1))))))
449 string)
451 ;; Functions for dbx on Mips/Ultrix.
452 ;; This is very similar to the code for gdb. The trick is to start dbx
453 ;; with the (undocumented) option `-emacs'.
455 ;; Are we running on a Mips system under Ultrix?
456 (defvar gud-dbx-mips-p (file-exists-p "/usr/include/mips"))
458 (defun gud-mipsdbx-massage-args (file args)
459 (cons "-emacs" (cons file args)))
461 ;; There's no guarantee that Emacs will hand the filter the entire
462 ;; marker at once; it could be broken up across several strings. We
463 ;; might even receive a big chunk with several markers in it. If we
464 ;; receive a chunk of text which looks like it might contain the
465 ;; beginning of a marker, we save it here between calls to the
466 ;; filter.
467 (defvar gud-mipsdbx-marker-acc "")
469 (defun gud-mipsdbx-marker-filter (string)
470 (save-match-data
471 (setq gud-mipsdbx-marker-acc (concat gud-mipsdbx-marker-acc string))
472 (let ((output ""))
474 ;; Process all the complete markers in this chunk.
475 (while (string-match
476 "^[] [0-9]*\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
477 gud-mipsdbx-marker-acc)
478 (setq
480 ;; Extract the frame position from the marker.
481 gud-last-frame (cons
482 (substring gud-mipsdbx-marker-acc
483 (match-beginning 1) (match-end 1))
484 (string-to-int
485 (substring gud-mipsdbx-marker-acc
486 (match-beginning 2) (match-end 2))))
488 ;; Append any text before the marker to the output we're going
489 ;; to return - we don't include the marker in this text.
490 output (concat output (substring gud-mipsdbx-marker-acc
491 0 (match-beginning 0)))
493 ;; Set the accumulator to the remaining text.
494 gud-mipsdbx-marker-acc (substring gud-mipsdbx-marker-acc
495 (match-end 0))))
497 ;; Does the remaining text look like it might end with the
498 ;; beginning of another marker? If it does, then keep it in
499 ;; gud-mipsdbx-marker-acc until we receive the rest of it.
500 ;; Since we know the full marker regexp above failed, it's pretty
501 ;; simple to test for marker starts.
502 (if (string-match "^[] [0-9]*\032.*\\'" gud-mipsdbx-marker-acc)
503 (setq
504 ;; Everything before the potential marker start can be output.
505 output (concat output (substring gud-mipsdbx-marker-acc
506 0 (match-beginning 0)))
507 ;; Everything after, we save, to combine with later input.
508 gud-mipsdbx-marker-acc (substring gud-mipsdbx-marker-acc
509 (match-beginning 0)))
510 (setq output (concat output gud-mipsdbx-marker-acc)
511 gud-mipsdbx-marker-acc ""))
513 output)))
515 (defun gud-dbx-find-file (f)
516 (find-file-noselect f))
518 ;;;###autoload
519 (defun dbx (command-line)
520 "Run dbx on program FILE in buffer *gud-FILE*.
521 The directory containing FILE becomes the initial working directory
522 and source-file directory for your debugger."
523 (interactive
524 (list (read-from-minibuffer "Run dbx (like this): "
525 (if (consp gud-dbx-history)
526 (car gud-dbx-history)
527 "dbx ")
528 nil nil
529 '(gud-dbx-history . 1))))
531 (gud-overload-functions
532 (cond
533 (gud-dbx-mips-p
534 '((gud-massage-args . gud-mipsdbx-massage-args)
535 (gud-marker-filter . gud-mipsdbx-marker-filter)
536 (gud-find-file . gud-dbx-find-file)))
538 '((gud-massage-args . gud-dbx-massage-args)
539 (gud-marker-filter . gud-dbx-marker-filter)
540 (gud-find-file . gud-dbx-find-file)))))
542 (gud-common-init command-line)
544 (cond
545 (gud-dbx-mips-p
546 (gud-def gud-break "stop at \"%f\":%l"
547 "\C-b" "Set breakpoint at current line.")
548 (gud-def gud-finish "return" "\C-f" "Finish executing current function."))
550 (gud-def gud-break "file \"%d%f\"\nstop at %l"
551 "\C-b" "Set breakpoint at current line.")))
553 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
554 (gud-def gud-step "step %p" "\C-s" "Step one line with display.")
555 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
556 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).")
557 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
558 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
559 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
560 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
562 (setq comint-prompt-regexp "^[^)\n]*dbx) *")
563 (setq paragraph-start comint-prompt-regexp)
564 (run-hooks 'dbx-mode-hook)
567 ;; ======================================================================
568 ;; xdb (HP PARISC debugger) functions
570 ;;; History of argument lists passed to xdb.
571 (defvar gud-xdb-history nil)
573 (defvar gud-xdb-directories nil
574 "*A list of directories that xdb should search for source code.
575 If nil, only source files in the program directory
576 will be known to xdb.
578 The file names should be absolute, or relative to the directory
579 containing the executable being debugged.")
581 (defun gud-xdb-massage-args (file args)
582 (nconc (let ((directories gud-xdb-directories)
583 (result nil))
584 (while directories
585 (setq result (cons (car directories) (cons "-d" result)))
586 (setq directories (cdr directories)))
587 (nreverse (cons file result)))
588 args))
590 (defun gud-xdb-file-name (f)
591 "Transform a relative pathname to a full pathname in xdb mode"
592 (let ((result nil))
593 (if (file-exists-p f)
594 (setq result (expand-file-name f))
595 (let ((directories gud-xdb-directories))
596 (while directories
597 (let ((path (concat (car directories) "/" f)))
598 (if (file-exists-p path)
599 (setq result (expand-file-name path)
600 directories nil)))
601 (setq directories (cdr directories)))))
602 result))
604 ;; xdb does not print the lines all at once, so we have to accumulate them
605 (defvar gud-xdb-accumulation "")
607 (defun gud-xdb-marker-filter (string)
608 (let (result)
609 (if (or (string-match comint-prompt-regexp string)
610 (string-match ".*\012" string))
611 (setq result (concat gud-xdb-accumulation string)
612 gud-xdb-accumulation "")
613 (setq gud-xdb-accumulation (concat gud-xdb-accumulation string)))
614 (if result
615 (if (or (string-match "\\([^\n \t:]+\\): [^:]+: \\([0-9]+\\):" result)
616 (string-match "[^: \t]+:[ \t]+\\([^:]+\\): [^:]+: \\([0-9]+\\):"
617 result))
618 (let ((line (string-to-int
619 (substring result (match-beginning 2) (match-end 2))))
620 (file (gud-xdb-file-name
621 (substring result (match-beginning 1) (match-end 1)))))
622 (if file
623 (setq gud-last-frame (cons file line))))))
624 (or result "")))
626 (defun gud-xdb-find-file (f)
627 (let ((realf (gud-xdb-file-name f)))
628 (if realf (find-file-noselect realf))))
630 ;;;###autoload
631 (defun xdb (command-line)
632 "Run xdb on program FILE in buffer *gud-FILE*.
633 The directory containing FILE becomes the initial working directory
634 and source-file directory for your debugger.
636 You can set the variable 'gud-xdb-directories' to a list of program source
637 directories if your program contains sources from more than one directory."
638 (interactive
639 (list (read-from-minibuffer "Run xdb (like this): "
640 (if (consp gud-xdb-history)
641 (car gud-xdb-history)
642 "xdb ")
643 nil nil
644 '(gud-xdb-history . 1))))
645 (gud-overload-functions '((gud-massage-args . gud-xdb-massage-args)
646 (gud-marker-filter . gud-xdb-marker-filter)
647 (gud-find-file . gud-xdb-find-file)))
649 (gud-common-init command-line)
651 (gud-def gud-break "b %f:%l" "\C-b" "Set breakpoint at current line.")
652 (gud-def gud-tbreak "b %f:%l\\t" "\C-t"
653 "Set temporary breakpoint at current line.")
654 (gud-def gud-remove "db" "\C-d" "Remove breakpoint at current line")
655 (gud-def gud-step "s %p" "\C-s" "Step one line with display.")
656 (gud-def gud-next "S %p" "\C-n" "Step one line (skip functions).")
657 (gud-def gud-cont "c" "\C-r" "Continue with display.")
658 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
659 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
660 (gud-def gud-finish "bu\\t" "\C-f" "Finish executing current function.")
661 (gud-def gud-print "p %e" "\C-p" "Evaluate C expression at point.")
663 (setq comint-prompt-regexp "^>")
664 (setq paragraph-start comint-prompt-regexp)
665 (make-local-variable 'gud-xdb-accumulation)
666 (setq gud-xdb-accumulation "")
667 (run-hooks 'xdb-mode-hook))
669 ;; ======================================================================
670 ;; perldb functions
672 ;;; History of argument lists passed to perldb.
673 (defvar gud-perldb-history nil)
675 (defun gud-perldb-massage-args (file args)
676 (cons "-d" (cons file (cons "-emacs" args))))
678 ;; There's no guarantee that Emacs will hand the filter the entire
679 ;; marker at once; it could be broken up across several strings. We
680 ;; might even receive a big chunk with several markers in it. If we
681 ;; receive a chunk of text which looks like it might contain the
682 ;; beginning of a marker, we save it here between calls to the
683 ;; filter.
684 (defvar gud-perldb-marker-acc "")
686 (defun gud-perldb-marker-filter (string)
687 (save-match-data
688 (setq gud-perldb-marker-acc (concat gud-perldb-marker-acc string))
689 (let ((output ""))
691 ;; Process all the complete markers in this chunk.
692 (while (string-match "^\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
693 gud-perldb-marker-acc)
694 (setq
696 ;; Extract the frame position from the marker.
697 gud-last-frame
698 (cons (substring gud-perldb-marker-acc (match-beginning 1) (match-end 1))
699 (string-to-int (substring gud-perldb-marker-acc
700 (match-beginning 2)
701 (match-end 2))))
703 ;; Append any text before the marker to the output we're going
704 ;; to return - we don't include the marker in this text.
705 output (concat output
706 (substring gud-perldb-marker-acc 0 (match-beginning 0)))
708 ;; Set the accumulator to the remaining text.
709 gud-perldb-marker-acc (substring gud-perldb-marker-acc (match-end 0))))
711 ;; Does the remaining text look like it might end with the
712 ;; beginning of another marker? If it does, then keep it in
713 ;; gud-perldb-marker-acc until we receive the rest of it. Since we
714 ;; know the full marker regexp above failed, it's pretty simple to
715 ;; test for marker starts.
716 (if (string-match "^\032.*\\'" gud-perldb-marker-acc)
717 (progn
718 ;; Everything before the potential marker start can be output.
719 (setq output (concat output (substring gud-perldb-marker-acc
720 0 (match-beginning 0))))
722 ;; Everything after, we save, to combine with later input.
723 (setq gud-perldb-marker-acc
724 (substring gud-perldb-marker-acc (match-beginning 0))))
726 (setq output (concat output gud-perldb-marker-acc)
727 gud-perldb-marker-acc ""))
729 output)))
731 (defun gud-perldb-find-file (f)
732 (find-file-noselect f))
734 ;;;###autoload
735 (defun perldb (command-line)
736 "Run perldb on program FILE in buffer *gud-FILE*.
737 The directory containing FILE becomes the initial working directory
738 and source-file directory for your debugger."
739 (interactive
740 (list (read-from-minibuffer "Run perldb (like this): "
741 (if (consp gud-perldb-history)
742 (car gud-perldb-history)
743 "perl ")
744 nil nil
745 '(gud-perldb-history . 1))))
746 (gud-overload-functions '((gud-massage-args . gud-perldb-massage-args)
747 (gud-marker-filter . gud-perldb-marker-filter)
748 (gud-find-file . gud-perldb-find-file)
751 (gud-common-init command-line)
753 (gud-def gud-break "b %l" "\C-b" "Set breakpoint at current line.")
754 (gud-def gud-remove "d %l" "\C-d" "Remove breakpoint at current line")
755 (gud-def gud-step "s" "\C-s" "Step one source line with display.")
756 (gud-def gud-next "n" "\C-n" "Step one line (skip functions).")
757 (gud-def gud-cont "c" "\C-r" "Continue with display.")
758 ; (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
759 ; (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
760 ; (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
761 (gud-def gud-print "%e" "\C-p" "Evaluate perl expression at point.")
763 (setq comint-prompt-regexp "^ DB<[0-9]+> ")
764 (setq paragraph-start comint-prompt-regexp)
765 (run-hooks 'perldb-mode-hook)
769 ;; End of debugger-specific information
773 ;;; When we send a command to the debugger via gud-call, it's annoying
774 ;;; to see the command and the new prompt inserted into the debugger's
775 ;;; buffer; we have other ways of knowing the command has completed.
777 ;;; If the buffer looks like this:
778 ;;; --------------------
779 ;;; (gdb) set args foo bar
780 ;;; (gdb) -!-
781 ;;; --------------------
782 ;;; (the -!- marks the location of point), and we type `C-x SPC' in a
783 ;;; source file to set a breakpoint, we want the buffer to end up like
784 ;;; this:
785 ;;; --------------------
786 ;;; (gdb) set args foo bar
787 ;;; Breakpoint 1 at 0x92: file make-docfile.c, line 49.
788 ;;; (gdb) -!-
789 ;;; --------------------
790 ;;; Essentially, the old prompt is deleted, and the command's output
791 ;;; and the new prompt take its place.
793 ;;; Not echoing the command is easy enough; you send it directly using
794 ;;; process-send-string, and it never enters the buffer. However,
795 ;;; getting rid of the old prompt is trickier; you don't want to do it
796 ;;; when you send the command, since that will result in an annoying
797 ;;; flicker as the prompt is deleted, redisplay occurs while Emacs
798 ;;; waits for a response from the debugger, and the new prompt is
799 ;;; inserted. Instead, we'll wait until we actually get some output
800 ;;; from the subprocess before we delete the prompt. If the command
801 ;;; produced no output other than a new prompt, that prompt will most
802 ;;; likely be in the first chunk of output received, so we will delete
803 ;;; the prompt and then replace it with an identical one. If the
804 ;;; command produces output, the prompt is moving anyway, so the
805 ;;; flicker won't be annoying.
807 ;;; So - when we want to delete the prompt upon receipt of the next
808 ;;; chunk of debugger output, we position gud-delete-prompt-marker at
809 ;;; the start of the prompt; the process filter will notice this, and
810 ;;; delete all text between it and the process output marker. If
811 ;;; gud-delete-prompt-marker points nowhere, we leave the current
812 ;;; prompt alone.
813 (defvar gud-delete-prompt-marker nil)
816 (defun gud-mode ()
817 "Major mode for interacting with an inferior debugger process.
819 You start it up with one of the commands M-x gdb, M-x sdb, M-x dbx,
820 or M-x xdb. Each entry point finishes by executing a hook; `gdb-mode-hook',
821 `sdb-mode-hook', `dbx-mode-hook' or `xdb-mode-hook' respectively.
823 After startup, the following commands are available in both the GUD
824 interaction buffer and any source buffer GUD visits due to a breakpoint stop
825 or step operation:
827 \\[gud-break] sets a breakpoint at the current file and line. In the
828 GUD buffer, the current file and line are those of the last breakpoint or
829 step. In a source buffer, they are the buffer's file and current line.
831 \\[gud-remove] removes breakpoints on the current file and line.
833 \\[gud-refresh] displays in the source window the last line referred to
834 in the gud buffer.
836 \\[gud-step], \\[gud-next], and \\[gud-stepi] do a step-one-line,
837 step-one-line (not entering function calls), and step-one-instruction
838 and then update the source window with the current file and position.
839 \\[gud-cont] continues execution.
841 \\[gud-print] tries to find the largest C lvalue or function-call expression
842 around point, and sends it to the debugger for value display.
844 The above commands are common to all supported debuggers except xdb which
845 does not support stepping instructions.
847 Under gdb, sdb and xdb, \\[gud-tbreak] behaves exactly like \\[gud-break],
848 except that the breakpoint is temporary; that is, it is removed when
849 execution stops on it.
851 Under gdb, dbx, and xdb, \\[gud-up] pops up through an enclosing stack
852 frame. \\[gud-down] drops back down through one.
854 If you are using gdb or xdb, \\[gud-finish] runs execution to the return from
855 the current function and stops.
857 All the keystrokes above are accessible in the GUD buffer
858 with the prefix C-c, and in all buffers through the prefix C-x C-a.
860 All pre-defined functions for which the concept make sense repeat
861 themselves the appropriate number of times if you give a prefix
862 argument.
864 You may use the `gud-def' macro in the initialization hook to define other
865 commands.
867 Other commands for interacting with the debugger process are inherited from
868 comint mode, which see."
869 (interactive)
870 (comint-mode)
871 (setq major-mode 'gud-mode)
872 (setq mode-name "Debugger")
873 (setq mode-line-process '(":%s"))
874 (use-local-map (copy-keymap comint-mode-map))
875 (define-key (current-local-map) "\C-c\C-l" 'gud-refresh)
876 (make-local-variable 'gud-last-frame)
877 (setq gud-last-frame nil)
878 (make-local-variable 'comint-prompt-regexp)
879 (make-local-variable 'paragraph-start)
880 (make-local-variable 'gud-delete-prompt-marker)
881 (setq gud-delete-prompt-marker (make-marker))
882 (run-hooks 'gud-mode-hook)
885 ;; Chop STRING into words separated by SPC or TAB and return a list of them.
886 (defun gud-chop-words (string)
887 (let ((i 0) (beg 0)
888 (len (length string))
889 (words nil))
890 (while (< i len)
891 (if (memq (aref string i) '(?\t ? ))
892 (progn
893 (setq words (cons (substring string beg i) words)
894 beg (1+ i))
895 (while (and (< beg len) (memq (aref string beg) '(?\t ? )))
896 (setq beg (1+ beg)))
897 (setq i (1+ beg)))
898 (setq i (1+ i))))
899 (if (< beg len)
900 (setq words (cons (substring string beg) words)))
901 (nreverse words)))
903 ;; Perform initializations common to all debuggers.
904 (defun gud-common-init (command-line)
905 (let* ((words (gud-chop-words command-line))
906 (program (car words))
907 (file-word (let ((w (cdr words)))
908 (while (and w (= ?- (aref (car w) 0)))
909 (setq w (cdr w)))
910 (car w)))
911 (args (delq file-word (cdr words)))
912 (file (and file-word
913 (expand-file-name (substitute-in-file-name file-word))))
914 (filepart (and file-word (file-name-nondirectory file))))
915 (switch-to-buffer (concat "*gud-" filepart "*"))
916 (and file-word (setq default-directory (file-name-directory file)))
917 (or (bolp) (newline))
918 (insert "Current directory is " default-directory "\n")
919 (apply 'make-comint (concat "gud-" filepart) program nil
920 (if file-word (gud-massage-args file args))))
921 (gud-mode)
922 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter)
923 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel)
924 (gud-set-buffer)
927 (defun gud-set-buffer ()
928 (cond ((eq major-mode 'gud-mode)
929 (setq gud-comint-buffer (current-buffer)))))
931 ;; These functions are responsible for inserting output from your debugger
932 ;; into the buffer. The hard work is done by the method that is
933 ;; the value of gud-marker-filter.
935 (defun gud-filter (proc string)
936 ;; Here's where the actual buffer insertion is done
937 (let ((inhibit-quit t)
938 output)
939 (save-excursion
940 (set-buffer (process-buffer proc))
941 ;; If we have been so requested, delete the debugger prompt.
942 (if (marker-buffer gud-delete-prompt-marker)
943 (progn
944 (delete-region (process-mark proc) gud-delete-prompt-marker)
945 (set-marker gud-delete-prompt-marker nil)))
946 ;; Save the process output, checking for source file markers.
947 (setq output (gud-marker-filter string))
948 ;; Check for a filename-and-line number.
949 ;; Don't display the specified file
950 ;; unless (1) point is at or after the position where output appears
951 ;; and (2) this buffer is on the screen.
952 (if (and gud-last-frame
953 (>= (point) (process-mark proc))
954 (get-buffer-window (current-buffer)))
955 (gud-display-frame))
956 ;; Let the comint filter do the actual insertion.
957 ;; That lets us inherit various comint features.
958 (comint-output-filter proc output))))
960 (defun gud-sentinel (proc msg)
961 (cond ((null (buffer-name (process-buffer proc)))
962 ;; buffer killed
963 ;; Stop displaying an arrow in a source file.
964 (setq overlay-arrow-position nil)
965 (set-process-buffer proc nil))
966 ((memq (process-status proc) '(signal exit))
967 ;; Stop displaying an arrow in a source file.
968 (setq overlay-arrow-position nil)
969 ;; Fix the mode line.
970 (setq mode-line-process
971 (concat ":"
972 (symbol-name (process-status proc))))
973 (let* ((obuf (current-buffer)))
974 ;; save-excursion isn't the right thing if
975 ;; process-buffer is current-buffer
976 (unwind-protect
977 (progn
978 ;; Write something in *compilation* and hack its mode line,
979 (set-buffer (process-buffer proc))
980 ;; Force mode line redisplay soon
981 (set-buffer-modified-p (buffer-modified-p))
982 (if (eobp)
983 (insert ?\n mode-name " " msg)
984 (save-excursion
985 (goto-char (point-max))
986 (insert ?\n mode-name " " msg)))
987 ;; If buffer and mode line will show that the process
988 ;; is dead, we can delete it now. Otherwise it
989 ;; will stay around until M-x list-processes.
990 (delete-process proc))
991 ;; Restore old buffer, but don't restore old point
992 ;; if obuf is the gud buffer.
993 (set-buffer obuf))))))
995 (defun gud-display-frame ()
996 "Find and obey the last filename-and-line marker from the debugger.
997 Obeying it means displaying in another window the specified file and line."
998 (interactive)
999 (if gud-last-frame
1000 (progn
1001 (gud-set-buffer)
1002 (gud-display-line (car gud-last-frame) (cdr gud-last-frame))
1003 (setq gud-last-last-frame gud-last-frame
1004 gud-last-frame nil))))
1006 ;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen
1007 ;; and that its line LINE is visible.
1008 ;; Put the overlay-arrow on the line LINE in that buffer.
1009 ;; Most of the trickiness in here comes from wanting to preserve the current
1010 ;; region-restriction if that's possible. We use an explicit display-buffer
1011 ;; to get around the fact that this is called inside a save-excursion.
1013 (defun gud-display-line (true-file line)
1014 (let* ((buffer (gud-find-file true-file))
1015 (window (display-buffer buffer))
1016 (pos))
1017 ;;; (if (equal buffer (current-buffer))
1018 ;;; nil
1019 ;;; (setq buffer-read-only nil))
1020 (save-excursion
1021 ;;; (setq buffer-read-only t)
1022 (set-buffer buffer)
1023 (save-restriction
1024 (widen)
1025 (goto-line line)
1026 (setq pos (point))
1027 (setq overlay-arrow-string "=>")
1028 (or overlay-arrow-position
1029 (setq overlay-arrow-position (make-marker)))
1030 (set-marker overlay-arrow-position (point) (current-buffer)))
1031 (cond ((or (< pos (point-min)) (> pos (point-max)))
1032 (widen)
1033 (goto-char pos))))
1034 (set-window-point window overlay-arrow-position)))
1036 ;;; The gud-call function must do the right thing whether its invoking
1037 ;;; keystroke is from the GUD buffer itself (via major-mode binding)
1038 ;;; or a C buffer. In the former case, we want to supply data from
1039 ;;; gud-last-frame. Here's how we do it:
1041 (defun gud-format-command (str arg)
1042 (let ((insource (not (eq (current-buffer) gud-comint-buffer)))
1043 (frame (or gud-last-frame gud-last-last-frame))
1044 result)
1045 (while (and str (string-match "\\([^%]*\\)%\\([adeflp]\\)" str))
1046 (let ((key (string-to-char (substring str (match-beginning 2))))
1047 subst)
1048 (cond
1049 ((eq key ?f)
1050 (setq subst (file-name-nondirectory (if insource
1051 (buffer-file-name)
1052 (car frame)))))
1053 ((eq key ?d)
1054 (setq subst (file-name-directory (if insource
1055 (buffer-file-name)
1056 (car frame)))))
1057 ((eq key ?l)
1058 (setq subst (if insource
1059 (save-excursion
1060 (beginning-of-line)
1061 (save-restriction (widen)
1062 (1+ (count-lines 1 (point)))))
1063 (cdr frame))))
1064 ((eq key ?e)
1065 (setq subst (find-c-expr)))
1066 ((eq key ?a)
1067 (setq subst (gud-read-address)))
1068 ((eq key ?p)
1069 (setq subst (if arg (int-to-string arg) ""))))
1070 (setq result (concat result
1071 (substring str (match-beginning 1) (match-end 1))
1072 subst)))
1073 (setq str (substring str (match-end 2))))
1074 ;; There might be text left in STR when the loop ends.
1075 (concat result str)))
1077 (defun gud-read-address ()
1078 "Return a string containing the core-address found in the buffer at point."
1079 (save-excursion
1080 (let ((pt (point)) found begin)
1081 (setq found (if (search-backward "0x" (- pt 7) t) (point)))
1082 (cond
1083 (found (forward-char 2)
1084 (buffer-substring found
1085 (progn (re-search-forward "[^0-9a-f]")
1086 (forward-char -1)
1087 (point))))
1088 (t (setq begin (progn (re-search-backward "[^0-9]")
1089 (forward-char 1)
1090 (point)))
1091 (forward-char 1)
1092 (re-search-forward "[^0-9]")
1093 (forward-char -1)
1094 (buffer-substring begin (point)))))))
1096 (defun gud-call (fmt &optional arg)
1097 (let ((msg (gud-format-command fmt arg)))
1098 (message "Command: %s" msg)
1099 (sit-for 0)
1100 (gud-basic-call msg)))
1102 (defun gud-basic-call (command)
1103 "Invoke the debugger COMMAND displaying source in other window."
1104 (interactive)
1105 (gud-set-buffer)
1106 (let ((command (concat command "\n"))
1107 (proc (get-buffer-process gud-comint-buffer)))
1109 ;; Arrange for the current prompt to get deleted.
1110 (save-excursion
1111 (set-buffer gud-comint-buffer)
1112 (goto-char (process-mark proc))
1113 (beginning-of-line)
1114 (if (looking-at comint-prompt-regexp)
1115 (set-marker gud-delete-prompt-marker (point))))
1116 (process-send-string proc command)))
1118 (defun gud-refresh (&optional arg)
1119 "Fix up a possibly garbled display, and redraw the arrow."
1120 (interactive "P")
1121 (recenter arg)
1122 (or gud-last-frame (setq gud-last-frame gud-last-last-frame))
1123 (gud-display-frame))
1125 ;;; Code for parsing expressions out of C code. The single entry point is
1126 ;;; find-c-expr, which tries to return an lvalue expression from around point.
1128 ;;; The rest of this file is a hacked version of gdbsrc.el by
1129 ;;; Debby Ayers <ayers@asc.slb.com>,
1130 ;;; Rich Schaefer <schaefer@asc.slb.com> Schlumberger, Austin, Tx.
1132 (defun find-c-expr ()
1133 "Returns the C expr that surrounds point."
1134 (interactive)
1135 (save-excursion
1136 (let ((p) (expr) (test-expr))
1137 (setq p (point))
1138 (setq expr (expr-cur))
1139 (setq test-expr (expr-prev))
1140 (while (expr-compound test-expr expr)
1141 (setq expr (cons (car test-expr) (cdr expr)))
1142 (goto-char (car expr))
1143 (setq test-expr (expr-prev)))
1144 (goto-char p)
1145 (setq test-expr (expr-next))
1146 (while (expr-compound expr test-expr)
1147 (setq expr (cons (car expr) (cdr test-expr)))
1148 (setq test-expr (expr-next))
1150 (buffer-substring (car expr) (cdr expr)))))
1152 (defun expr-cur ()
1153 "Returns the expr that point is in; point is set to beginning of expr.
1154 The expr is represented as a cons cell, where the car specifies the point in
1155 the current buffer that marks the beginning of the expr and the cdr specifies
1156 the character after the end of the expr."
1157 (let ((p (point)) (begin) (end))
1158 (expr-backward-sexp)
1159 (setq begin (point))
1160 (expr-forward-sexp)
1161 (setq end (point))
1162 (if (>= p end)
1163 (progn
1164 (setq begin p)
1165 (goto-char p)
1166 (expr-forward-sexp)
1167 (setq end (point))
1170 (goto-char begin)
1171 (cons begin end)))
1173 (defun expr-backward-sexp ()
1174 "Version of `backward-sexp' that catches errors."
1175 (condition-case nil
1176 (backward-sexp)
1177 (error t)))
1179 (defun expr-forward-sexp ()
1180 "Version of `forward-sexp' that catches errors."
1181 (condition-case nil
1182 (forward-sexp)
1183 (error t)))
1185 (defun expr-prev ()
1186 "Returns the previous expr, point is set to beginning of that expr.
1187 The expr is represented as a cons cell, where the car specifies the point in
1188 the current buffer that marks the beginning of the expr and the cdr specifies
1189 the character after the end of the expr"
1190 (let ((begin) (end))
1191 (expr-backward-sexp)
1192 (setq begin (point))
1193 (expr-forward-sexp)
1194 (setq end (point))
1195 (goto-char begin)
1196 (cons begin end)))
1198 (defun expr-next ()
1199 "Returns the following expr, point is set to beginning of that expr.
1200 The expr is represented as a cons cell, where the car specifies the point in
1201 the current buffer that marks the beginning of the expr and the cdr specifies
1202 the character after the end of the expr."
1203 (let ((begin) (end))
1204 (expr-forward-sexp)
1205 (expr-forward-sexp)
1206 (setq end (point))
1207 (expr-backward-sexp)
1208 (setq begin (point))
1209 (cons begin end)))
1211 (defun expr-compound-sep (span-start span-end)
1212 "Returns '.' for '->' & '.', returns ' ' for white space,
1213 returns '?' for other punctuation."
1214 (let ((result ? )
1215 (syntax))
1216 (while (< span-start span-end)
1217 (setq syntax (char-syntax (char-after span-start)))
1218 (cond
1219 ((= syntax ? ) t)
1220 ((= syntax ?.) (setq syntax (char-after span-start))
1221 (cond
1222 ((= syntax ?.) (setq result ?.))
1223 ((and (= syntax ?-) (= (char-after (+ span-start 1)) ?>))
1224 (setq result ?.)
1225 (setq span-start (+ span-start 1)))
1226 (t (setq span-start span-end)
1227 (setq result ??)))))
1228 (setq span-start (+ span-start 1)))
1229 result))
1231 (defun expr-compound (first second)
1232 "Non-nil if concatenating FIRST and SECOND makes a single C token.
1233 The two exprs are represented as a cons cells, where the car
1234 specifies the point in the current buffer that marks the beginning of the
1235 expr and the cdr specifies the character after the end of the expr.
1236 Link exprs of the form:
1237 Expr -> Expr
1238 Expr . Expr
1239 Expr (Expr)
1240 Expr [Expr]
1241 (Expr) Expr
1242 [Expr] Expr"
1243 (let ((span-start (cdr first))
1244 (span-end (car second))
1245 (syntax))
1246 (setq syntax (expr-compound-sep span-start span-end))
1247 (cond
1248 ((= (car first) (car second)) nil)
1249 ((= (cdr first) (cdr second)) nil)
1250 ((= syntax ?.) t)
1251 ((= syntax ? )
1252 (setq span-start (char-after (- span-start 1)))
1253 (setq span-end (char-after span-end))
1254 (cond
1255 ((= span-start ?) ) t )
1256 ((= span-start ?] ) t )
1257 ((= span-end ?( ) t )
1258 ((= span-end ?[ ) t )
1259 (t nil))
1261 (t nil))))
1263 (provide 'gud)
1265 ;;; gud.el ends here