1 ;;; gud.el --- Grand Unified Debugger mode for gdb, sdb, or dbx under Emacs
3 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
5 ;; Keywords: unix, tools
7 ;; Copyright (C) 1992 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 ;; The ancestral gdb.el was by W. Schelter <wfs@rascal.ics.utexas.edu>
28 ;; It was later rewritten by rms. Some ideas were due to Masanobu.
29 ;; Grand Unification (sdb/dbx support) by Eric S. Raymond <esr@thyrsus.com>
30 ;; The overloading code was then rewritten by Barry Warsaw <bwarsaw@cen.com>,
31 ;; who also hacked the mode to use comint.el.
38 ;; ======================================================================
39 ;; GUD commands must be visible in C buffers visited by GUD
41 (defvar gud-key-prefix "\C-x\C-a"
42 "Prefix of all GUD commands valid in C buffers.")
44 (global-set-key (concat gud-key-prefix "\C-l") 'gud-refresh)
45 (global-set-key "\C-x " 'gud-break) ;; backward compatibility hack
47 ;; ======================================================================
48 ;; the overloading mechanism
50 (defun gud-overload-functions (gud-overload-alist)
51 "Overload functions defined in GUD-OVERLOAD-ALIST.
52 This association list has elements of the form
53 (ORIGINAL-FUNCTION-NAME OVERLOAD-FUNCTION)"
55 (function (lambda (p) (fset (car p) (symbol-function (cdr p)))))
58 (defun gud-debugger-startup (file args)
59 (error "GUD not properly entered."))
61 (defun gud-marker-filter (str)
62 (error "GUD not properly entered."))
64 (defun gud-find-file (f)
65 (error "GUD not properly entered."))
67 ;; ======================================================================
70 ;; This macro is used below to define some basic debugger interface commands.
71 ;; Of course you may use `gud-def' with any other debugger command, including
74 ;; A macro call like (gud-def FUNC NAME KEY DOC) expands to a form
75 ;; which defines FUNC to send the command NAME to the debugger, gives
76 ;; it the docstring DOC, and binds that function to KEY in the GUD
77 ;; major mode. The function is also bound in the global keymap with the
80 (defmacro gud-def (func cmd key &optional doc)
81 "Define FUNC to be a command sending STR and bound to KEY, with
82 optional doc string DOC. Certain %-escapes in the string arguments
83 are interpreted specially if present. These are:
85 %f name of current source file.
86 %l number of current source line
87 %e text of the C lvalue or function-call expression surrounding point.
88 %a text of the hexadecimal address surrounding point
89 %p prefix argument to the command (if any) as a number
91 The `current' source file is the file of the current buffer (if
92 we're in a C file) or the source file current at the last break or
93 step (if we're in the GUD buffer).
94 The `current' line is that of the current buffer (if we're in a
95 source file) or the source line number at the last break or step (if
96 we're in the GUD buffer)."
98 (list 'defun func '(arg)
101 (list 'gud-call cmd 'arg))
108 (list 'global-set-key
109 (concat gud-key-prefix key)
113 ;; Where gud-display-frame should put the debugging arrow. This is
114 ;; set by the marker-filter, which scans the debugger's output for
115 ;; indications of the current program counter.
116 (defvar gud-last-frame nil)
118 ;; All debugger-specific information is collected here.
119 ;; Here's how it works, in case you ever need to add a debugger to the mode.
121 ;; Each entry must define the following at startup:
124 ;; comint-prompt-regexp
125 ;; gud-<name>-debugger-startup
126 ;; gud-<name>-marker-filter
127 ;; gud-<name>-find-file
129 ;; The job of the startup-command method is to fire up a copy of the debugger,
130 ;; given a list of debugger arguments.
132 ;; The job of the marker-filter method is to detect file/line markers in
133 ;; strings and set the global gud-last-frame to indicate what display
134 ;; action (if any) should be triggered by the marker. Note that only
135 ;; whetever the method *returns* is displayed in the buffer; thus, you
136 ;; can filter the debugger's output, interpreting some and passing on
139 ;; The job of the find-file method is to visit and return the buffer indicated
140 ;; by the car of gud-tag-frame. This may be a file name, a tag name, or
143 ;; ======================================================================
146 (defun gud-gdb-debugger-startup (file args)
147 (apply 'make-comint (concat "gud-" file) "gdb" nil "-fullname" args))
149 (defun gud-gdb-marker-filter (string)
150 (if (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n" string)
154 (substring string (match-beginning 1) (match-end 1))
156 (substring string (match-beginning 2) (match-end 2)))))
157 ;; this computation means the ^Z^Z-initiated marker in the
158 ;; input string is never emitted.
160 (substring string 0 (match-beginning 0))
161 (substring string (match-end 0))
165 (defun gud-gdb-find-file (f)
166 (find-file-noselect f))
170 "Run gdb on program FILE in buffer *gud-FILE*.
171 The directory containing FILE becomes the initial working directory
172 and source-file directory for your debugger."
173 (interactive "sRun gdb (like this): gdb ")
174 (gud-overload-functions '((gud-debugger-startup . gud-gdb-debugger-startup)
175 (gud-marker-filter . gud-gdb-marker-filter)
176 (gud-find-file . gud-gdb-find-file)
179 (gud-common-init args)
181 (gud-def gud-break "break %f:%l" "b" "Set breakpoint at current line.")
182 (gud-def gud-tbreak "tbreak %f:%l" "t" "Set breakpoint at current line.")
183 (gud-def gud-remove "clear %l" "d" "Remove breakpoint at current line")
184 (gud-def gud-step "step %p" "s" "Step one source line with display.")
185 (gud-def gud-stepi "stepi %p" "i" "Step one instruction with display.")
186 (gud-def gud-next "next %p" "n" "Step one line (skip functions).")
187 (gud-def gud-cont "cont" "r" "Continue with display.")
188 (gud-def gud-finish "finish" "f" "Finish executing current function.")
189 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
190 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
191 (gud-def gud-print "print %e" "p" "Evaluate C expression at point.")
193 (setq comint-prompt-regexp "^(.*gdb[+]?) *")
194 (run-hooks 'gdb-mode-hook)
198 ;; ======================================================================
201 (defvar gud-sdb-needs-tags (not (file-exists-p "/var"))
202 "If nil, we're on a System V Release 4 and don't need the tags hack.")
204 (defvar gud-sdb-lastfile nil)
206 (defun gud-sdb-debugger-startup (file args)
207 (apply 'make-comint (concat "gud-" file) "sdb" nil args))
209 (defun gud-sdb-marker-filter (string)
211 ;; System V Release 3.2 uses this format
212 ((string-match "\\(^0x\\w* in \\|^\\|\n\\)\\([^:\n]*\\):\\([0-9]*\\):.*\n"
216 (substring string (match-beginning 2) (match-end 2))
218 (substring string (match-beginning 3) (match-end 3))))))
219 ;; System V Release 4.0
220 ((string-match "^\\(BREAKPOINT\\|STEPPED\\) process [0-9]+ function [^ ]+ in \\(.+\\)\n"
222 (setq gud-sdb-lastfile
223 (substring string (match-beginning 2) (match-end 2))))
224 ((and gud-sdb-lastfile (string-match "^\\([0-9]+\\):" string))
229 (substring string (match-beginning 1) (match-end 1))))))
231 (setq gud-sdb-lastfile nil)))
234 (defun gud-sdb-find-file (f)
235 (if gud-sdb-needs-tags
236 (find-tag-noselect f)
237 (find-file-noselect f)))
241 "Run sdb on program FILE in buffer *gud-FILE*.
242 The directory containing FILE becomes the initial working directory
243 and source-file directory for your debugger."
244 (interactive "sRun sdb (like this): sdb ")
245 (if (and gud-sdb-needs-tags
246 (not (and (boundp 'tags-file-name) (file-exists-p tags-file-name))))
247 (error "The sdb support requires a valid tags table to work."))
248 (gud-overload-functions '((gud-debugger-startup . gud-sdb-debugger-startup)
249 (gud-marker-filter . gud-sdb-marker-filter)
250 (gud-find-file . gud-sdb-find-file)
253 (gud-common-init args)
255 (gud-def gud-break "%l b" "b" "Set breakpoint at current line.")
256 (gud-def gud-tbreak "%l c" "t" "Set temporary breakpoint at current line.")
257 (gud-def gud-remove "%l d" "d" "Remove breakpoint at current line")
258 (gud-def gud-step "s %p" "s" "Step one source line with display.")
259 (gud-def gud-stepi "i %p" "i" "Step one instruction with display.")
260 (gud-def gud-next "S %p" "n" "Step one line (skip functions).")
261 (gud-def gud-cont "c" "r" "Continue with display.")
262 (gud-def gud-print "%e/" "p" "Evaluate C expression at point.")
264 (setq comint-prompt-regexp "\\(^\\|\n\\)\\*")
265 (run-hooks 'sdb-mode-hook)
268 ;; ======================================================================
271 (defun gud-dbx-debugger-startup (file args)
272 (apply 'make-comint (concat "gud-" file) "dbx" nil args))
274 (defun gud-dbx-marker-filter (string)
276 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\"" string)
279 (substring string (match-beginning 2) (match-end 2))
281 (substring string (match-beginning 1) (match-end 1))))))
284 (defun gud-dbx-find-file (f)
285 (find-file-noselect f))
289 "Run dbx on program FILE in buffer *gud-FILE*.
290 The directory containing FILE becomes the initial working directory
291 and source-file directory for your debugger."
292 (interactive "sRun dbx (like this): dbx")
293 (gud-overload-functions '((gud-debugger-startup . gud-dbx-debugger-startup)
294 (gud-marker-filter . gud-dbx-marker-filter)
295 (gud-find-file . gud-dbx-find-file)
298 (gud-common-init args)
300 (gud-def gud-break "stop at \"%f\":%l"
301 "b" "Set breakpoint at current line.")
302 (gud-def gud-remove "clear %l" "d" "Remove breakpoint at current line")
303 (gud-def gud-step "step %p" "s" "Step one line with display.")
304 (gud-def gud-stepi "stepi %p" "i" "Step one instruction with display.")
305 (gud-def gud-next "next %p" "n" "Step one line (skip functions).")
306 (gud-def gud-cont "cont" "r" "Continue with display.")
307 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
308 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
309 (gud-def gud-print "print %e" "p" "Evaluate C expression at point.")
311 (setq comint-prompt-regexp "^[^)]*dbx) *")
312 (run-hooks 'dbx-mode-hook)
316 ;; End of debugger-specific information
319 ;;; When we send a command to the debugger via gud-call, it's annoying
320 ;;; to see the command and the new prompt inserted into the debugger's
321 ;;; buffer; we have other ways of knowing the command has completed.
323 ;;; If the buffer looks like this:
324 ;;; --------------------
325 ;;; (gdb) set args foo bar
327 ;;; --------------------
328 ;;; (the -!- marks the location of point), and we type `C-x SPC' in a
329 ;;; source file to set a breakpoint, we want the buffer to end up like
331 ;;; --------------------
332 ;;; (gdb) set args foo bar
333 ;;; Breakpoint 1 at 0x92: file make-docfile.c, line 49.
335 ;;; --------------------
336 ;;; Essentially, the old prompt is deleted, and the command's output
337 ;;; and the new prompt take its place.
339 ;;; Not echoing the command is easy enough; you send it directly using
340 ;;; process-send-string, and it never enters the buffer. However,
341 ;;; getting rid of the old prompt is trickier; you don't want to do it
342 ;;; when you send the command, since that will result in an annoying
343 ;;; flicker as the prompt is deleted, redisplay occurs while Emacs
344 ;;; waits for a response from the debugger, and the new prompt is
345 ;;; inserted. Instead, we'll wait until we actually get some output
346 ;;; from the subprocess before we delete the prompt. If the command
347 ;;; produced no output other than a new prompt, that prompt will most
348 ;;; likely be in the first chunk of output received, so we will delete
349 ;;; the prompt and then replace it with an identical one. If the
350 ;;; command produces output, the prompt is moving anyway, so the
351 ;;; flicker won't be annoying.
353 ;;; So - when we want to delete the prompt upon receipt of the next
354 ;;; chunk of debugger output, we position gud-delete-prompt-marker at
355 ;;; the start of the prompt; the process filter will notice this, and
356 ;;; delete all text between it and the process output marker. If
357 ;;; gud-delete-prompt-marker points nowhere, we leave the current
359 (defvar gud-delete-prompt-marker nil)
363 "Major mode for interacting with an inferior debugger process.
365 You start it up with one of the commands M-x gdb, M-x sdb, or
366 M-x dbx. Each entry point finishes by executing a hook; gdb-mode-hook,
367 sdb-mode-hook or dbx-mode-hook respectively.
369 After startup, the following commands are available in both the GUD
370 interaction buffer and any source buffer GUD visits due to a breakpoint stop
373 \\[gud-break] sets a breakpoint at the current file and line. In the
374 GUD buffer, the current file and line are those of the last breakpoint or
375 step. In a source buffer, they are the buffer's file and current line.
377 \\[gud-remove] removes breakpoints on the current file and line.
379 \\[gud-refresh] displays in the source window the last line referred to
382 \\[gud-step], \\[gud-next], and \\[gud-stepi] do a step-one-line,
383 step-one-line (not entering function calls), and step-one-instruction
384 and then update the source window with the current file and position.
385 \\[gud-cont] continues execution.
387 \\[gud-print] tries to find the largest C lvalue or function-call expression
388 around point, and sends it to the debugger for value display.
390 The above commands are common to all supported debuggers.
392 Under gdb and sdb, \\[gud-tbreak] behaves exactly like \\[gud-break],
393 except that the breakpoint is temporary; that is, it is removed when
394 execution stops on it.
396 Under gdb and dbx, \\[gud-up] pops up through an enclosing stack
397 frame. \\[gud-down] drops back down through one.
399 If you are using gdb, \\[gdb-finish] runs execution to the return from
400 the current function and stops.
402 All the keystrokes above have synonyms (in the GUD buffer only) with
403 a prefix of C-c (this is for backward compatibility with old gdb.el).
405 All pre-defined functions for which the concept make sense repeat
406 themselves the appropriate number of times if you give a prefix
409 You may use the gud-def macro in the initialization hook to define other
412 Other commands for interacting with the debugger process are inherited from
413 comint mode, which see."
416 (setq major-mode 'gud-mode)
417 (setq mode-name "Debugger")
418 (setq mode-line-process '(": %s"))
419 (use-local-map (copy-keymap comint-mode-map))
420 (make-local-variable 'gud-last-frame)
421 (setq gud-last-frame nil)
422 (make-local-variable 'comint-prompt-regexp)
423 (make-local-variable 'gud-delete-prompt-marker)
424 (setq gud-delete-prompt-marker (make-marker))
425 (run-hooks 'gud-mode-hook)
428 (defvar gud-comint-buffer nil)
430 (defun gud-common-init (args)
431 ;; Perform initializations common to all debuggers
432 ;; There *must* be a cleaner way to lex the arglist...
434 (if (string= args "")
436 (set-buffer (get-buffer-create "*gud-scratch*"))
439 (goto-char (point-max))
441 (goto-char (point-min))
443 (while (re-search-forward " +" nil t)
444 (replace-match "\" \"" nil nil))
445 (goto-char (point-min))
446 (while (re-search-forward "\"\"" nil t)
447 (replace-match "" nil nil))
448 (setq args (read (buffer-string)))
449 (kill-buffer (current-buffer)))
450 (setq i (1- (length args)))
451 (while (and (>= i 0) (not (= (aref (nth i args) 0) ?-)))
452 (setq file (nth i args)) (setq i (1- i)))
453 (let* ((path (expand-file-name file))
454 (filepart (file-name-nondirectory path)))
455 (switch-to-buffer (concat "*gud-" filepart "*"))
456 (setq default-directory (file-name-directory path))
457 (or (bolp) (newline))
458 (insert "Current directory is " default-directory "\n")
459 (gud-debugger-startup filepart args)))
461 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter)
462 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel)
466 (defun gud-set-buffer ()
467 (cond ((eq major-mode 'gud-mode)
468 (setq gud-comint-buffer (current-buffer)))))
470 ;; These functions are responsible for inserting output from your debugger
471 ;; into the buffer. The hard work is done by the method that is
472 ;; the value of gud-marker-filter.
474 (defun gud-filter (proc string)
475 ;; Here's where the actual buffer insertion is done
476 (let ((inhibit-quit t))
478 (set-buffer (process-buffer proc))
479 (let ((moving (= (point) (process-mark proc)))
480 (output-after-point (< (point) (process-mark proc))))
482 (goto-char (process-mark proc))
483 ;; If we have been so requested, delete the debugger prompt.
484 (if (marker-buffer gud-delete-prompt-marker)
486 (delete-region (point) gud-delete-prompt-marker)
487 (set-marker gud-delete-prompt-marker nil)))
488 (insert-before-markers (gud-marker-filter string))
489 ;; Check for a filename-and-line number.
490 ;; Don't display the specified file
491 ;; unless (1) point is at or after the position where output appears
492 ;; and (2) this buffer is on the screen.
493 (if (and gud-last-frame
494 (not output-after-point)
495 (get-buffer-window (current-buffer)))
496 (gud-display-frame)))
497 (if moving (goto-char (process-mark proc)))))))
499 (defun gud-sentinel (proc msg)
500 (cond ((null (buffer-name (process-buffer proc)))
502 ;; Stop displaying an arrow in a source file.
503 (setq overlay-arrow-position nil)
504 (set-process-buffer proc nil))
505 ((memq (process-status proc) '(signal exit))
506 ;; Stop displaying an arrow in a source file.
507 (setq overlay-arrow-position nil)
508 ;; Fix the mode line.
509 (setq mode-line-process
511 (symbol-name (process-status proc))))
512 (let* ((obuf (current-buffer)))
513 ;; save-excursion isn't the right thing if
514 ;; process-buffer is current-buffer
517 ;; Write something in *compilation* and hack its mode line,
518 (set-buffer (process-buffer proc))
519 ;; Force mode line redisplay soon
520 (set-buffer-modified-p (buffer-modified-p))
522 (insert ?\n mode-name " " msg)
524 (goto-char (point-max))
525 (insert ?\n mode-name " " msg)))
526 ;; If buffer and mode line will show that the process
527 ;; is dead, we can delete it now. Otherwise it
528 ;; will stay around until M-x list-processes.
529 (delete-process proc))
530 ;; Restore old buffer, but don't restore old point
531 ;; if obuf is the gud buffer.
532 (set-buffer obuf))))))
534 (defun gud-display-frame ()
535 "Find and obey the last filename-and-line marker from the debugger.
536 Obeying it means displaying in another window the specified file and line."
541 (gud-display-line (car gud-last-frame) (cdr gud-last-frame))
542 (setq gud-last-frame nil))))
544 ;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen
545 ;; and that its line LINE is visible.
546 ;; Put the overlay-arrow on the line LINE in that buffer.
547 ;; Most of the trickiness in here comes from wanting to preserve the current
548 ;; region-restriction if that's possible. We use an explicit display-buffer
549 ;; to get around the fact that this is called inside a save-excursion.
551 (defun gud-display-line (true-file line)
552 (let* ((buffer (gud-find-file true-file))
553 (window (display-buffer buffer))
555 (if (equal buffer (current-buffer))
557 (setq buffer-read-only nil))
560 (setq buffer-read-only t)
565 (setq overlay-arrow-string "=>")
566 (or overlay-arrow-position
567 (setq overlay-arrow-position (make-marker)))
568 (set-marker overlay-arrow-position (point) (current-buffer)))
569 (cond ((or (< pos (point-min)) (> pos (point-max)))
572 (set-window-point window overlay-arrow-position)))
574 ;;; The gud-call function must do the right thing whether its invoking
575 ;;; keystroke is from the GUD buffer itself (via major-mode binding)
576 ;;; or a C buffer. In the former case, we want to supply data from
577 ;;; gud-last-frame. Here's how we do it:
579 (defun gud-format-command (str arg)
580 (let ((insource (not (eq (current-buffer) gud-comint-buffer))))
581 (if (string-match "\\(.*\\)%f\\(.*\\)" str)
584 (substring str (match-beginning 1) (match-end 1))
585 (file-name-nondirectory (if insource
587 (car gud-last-frame)))
588 (substring str (match-beginning 2) (match-end 2))))))
589 (if (string-match "\\(.*\\)%l\\(.*\\)" str)
592 (substring str (match-beginning 1) (match-end 1))
596 (save-restriction (widen)
597 (1+ (count-lines 1 (point)))))
598 (cdr gud-last-frame))
599 (substring str (match-beginning 2) (match-end 2))))))
600 (if (string-match "\\(.*\\)%e\\(.*\\)" str)
603 (substring str (match-beginning 1) (match-end 1))
605 (substring str (match-beginning 2) (match-end 2))))))
606 (if (string-match "\\(.*\\)%a\\(.*\\)" str)
609 (substring str (match-beginning 1) (match-end 1))
611 (substring str (match-beginning 2) (match-end 2))))))
612 (if (string-match "\\(.*\\)%p\\(.*\\)" str)
615 (substring str (match-beginning 1) (match-end 1))
616 (if arg (int-to-string arg) "")
617 (substring str (match-beginning 2) (match-end 2))))))
622 (defun gud-read-address ()
623 "Return a string containing the core-address found in the buffer at point."
625 (let ((pt (point)) found begin)
626 (setq found (if (search-backward "0x" (- pt 7) t) (point)))
628 (found (forward-char 2)
629 (buffer-substring found
630 (progn (re-search-forward "[^0-9a-f]")
633 (t (setq begin (progn (re-search-backward "[^0-9]")
637 (re-search-forward "[^0-9]")
639 (buffer-substring begin (point)))))))
641 (defun gud-call (fmt &optional arg)
642 (let ((msg (gud-format-command fmt arg)))
643 (message "Command: %s" msg)
645 (gud-basic-call msg)))
647 (defun gud-basic-call (command)
648 "Invoke the debugger COMMAND displaying source in other window."
651 (let ((command (concat command "\n"))
652 (proc (get-buffer-process gud-comint-buffer)))
654 ;; Arrange for the current prompt to get deleted.
656 (set-buffer gud-comint-buffer)
657 (goto-char (process-mark proc))
659 (if (looking-at comint-prompt-regexp)
660 (set-marker gud-delete-prompt-marker (point))))
661 (process-send-string proc command)))
663 (defun gud-refresh (&optional arg)
664 "Fix up a possibly garbled display, and redraw the arrow."
669 ;;; Code for parsing expressions out of C code. The single entry point is
670 ;;; find-c-expr, which tries to return an lvalue expression from around point.
672 ;;; The rest of this file is a hacked version of gdbsrc.el by
673 ;;; Debby Ayers <ayers@asc.slb.com>,
674 ;;; Rich Schaefer <schaefer@asc.slb.com> Schlumberger, Austin, Tx.
675 ;;; ??? We're waiting on papers from these people
677 (defun find-c-expr ()
678 "Returns the C expr that surrounds point."
681 (let ((p) (expr) (test-expr))
683 (setq expr (expr-cur))
684 (setq test-expr (expr-prev))
685 (while (expr-compound test-expr expr)
686 (setq expr (cons (car test-expr) (cdr expr)))
687 (goto-char (car expr))
688 (setq test-expr (expr-prev))
691 (setq test-expr (expr-next))
692 (while (expr-compound expr test-expr)
693 (setq expr (cons (car expr) (cdr test-expr)))
694 (setq test-expr (expr-next))
696 (buffer-substring (car expr) (cdr expr))
702 "Returns the expr that point is in; point is set to beginning of expr.
703 The expr is represented as a cons cell, where the car specifies the point in
704 the current buffer that marks the beginning of the expr and the cdr specifies
705 the character after the end of the expr"
706 (let ((p (point)) (begin) (end))
725 "Version of backward-sexp that catches errors"
731 "Version of forward-sexp that catches errors"
737 "Returns the previous expr, point is set to beginning of that expr.
738 The expr is represented as a cons cell, where the car specifies the point in
739 the current buffer that marks the beginning of the expr and the cdr specifies
740 the character after the end of the expr"
750 "Returns the following expr, point is set to beginning of that expr.
751 The expr is represented as a cons cell, where the car specifies the point in
752 the current buffer that marks the beginning of the expr and the cdr specifies
753 the character after the end of the expr"
764 (defun expr-compound-sep (span-start span-end)
765 "Returns '.' for '->' & '.', returns ' ' for white space,
766 returns '?' for other puctuation."
769 (while (< span-start span-end)
770 (setq syntax (char-syntax (char-after span-start)))
773 ((= syntax ?.) (setq syntax (char-after span-start))
775 ((= syntax ?.) (setq result ?.))
776 ((and (= syntax ?-) (= (char-after (+ span-start 1)) ?>))
778 (setq span-start (+ span-start 1)))
779 (t (setq span-start span-end)
781 (setq span-start (+ span-start 1)))
786 (defun expr-compound (first second)
787 "Returns non-nil if the concatenation of two exprs results in a single C
788 token. The two exprs are represented as a cons cells, where the car
789 specifies the point in the current buffer that marks the beginning of the
790 expr and the cdr specifies the character after the end of the expr
791 Link exprs of the form:
798 (let ((span-start (cdr first))
799 (span-end (car second))
801 (setq syntax (expr-compound-sep span-start span-end))
803 ((= (car first) (car second)) nil)
804 ((= (cdr first) (cdr second)) nil)
807 (setq span-start (char-after (- span-start 1)))
808 (setq span-end (char-after span-end))
810 ((= span-start ?) ) t )
811 ((= span-start ?] ) t )
812 ((= span-end ?( ) t )
813 ((= span-end ?[ ) t )
820 ;;; There appears to be a bug in the byte compiler somewhere near macro
821 ;;; handling that (a) generates a spurious message about gud-key-prefix
822 ;;; when the global-set-key clause in gud-def is compiled, (b) generates
823 ;;; incorrect bytecode for gud-def. The symptom of this incorrectness
824 ;;; is that loading gud.elc brings in a compiled gud-def that doesn't
825 ;;; properly perform both global (C-x C-a) and local (C-c) bindings.
826 ;;; The workaround is to always load from source. Consequently, we try
827 ;;; to disable byte-compilation here.
830 ;;; no-byte-compile: t