annotate lisp/gud.el @ 746:1b0748ff6f65

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Tue, 07 Jul 1992 00:45:18 +0000
parents ab9a55b26bd4
children d42e1151eed8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
460
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1 ;; Grand Unified Debugger mode --- run gdb, sdb, dbx under Emacs control
477
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
2 ;; @(#)gud.el 1.10
460
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
3
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
4 ;; This file is part of GNU Emacs.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
5
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
7 ;; it under the terms of the GNU General Public License as published by
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
8 ;; the Free Software Foundation; either version 1, or (at your option)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
9 ;; any later version.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
10
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
11 ;; GNU Emacs is distributed in the hope that it will be useful,
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
14 ;; GNU General Public License for more details.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
15
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
19
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
20 ;; The ancestral gdb.el was by W. Schelter <wfs@rascal.ics.utexas.edu>
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
21 ;; It was later ewritten by rms. Some ideas were due to Masanobu.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
22 ;; Grand Unification (sdb/dbx support) by Eric S. Raymond <eric@thyrsus.com>
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
23 ;; The overloading code was then rewritten by Barry Warsaw <bwarsaw@cen.com>,
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
24 ;; who also hacked the mode to use comint.el.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
25
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
26 ;; Note: use of this package with sdb requires that your tags.el support
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
27 ;; the find-tag-noselect entry point. Stock distributions up to 18.57 do
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
28 ;; *not* include this feature; if it's not included with this file, email
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
29 ;; eric@snark.thyrsus.com for it or get 18.58.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
30
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
31 (require 'comint)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
32 (require 'tags)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
33
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
34 ;; ======================================================================
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
35 ;; the overloading mechanism
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
36
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
37 (defun gud-overload-functions (gud-overload-alist)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
38 "Overload functions defined in GUD-OVERLOAD-ALIST.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
39 This association list has elements of the form
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
40
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
41 (ORIGINAL-FUNCTION-NAME OVERLOAD-FUNCTION)"
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
42 (let ((binding nil)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
43 (overloads gud-overload-alist))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
44 (while overloads
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
45 (setq binding (car overloads)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
46 overloads (cdr overloads))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
47 (fset (car binding) (symbol-function (car (cdr binding))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
48 )))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
49
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
50 (defun gud-debugger-startup (f d)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
51 (error "GUD not properly entered."))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
52
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
53 (defun gud-marker-filter (proc s)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
54 (error "GUD not properly entered."))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
55
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
56 (defun gud-visit-file (f)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
57 (error "GUD not properly entered."))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
58
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
59 (defun gud-set-break (proc f n)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
60 (error "GUD not properly entered."))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
61
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
62 ;; This macro is used below to define some basic debugger interface commands.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
63 ;; Of course you may use `def-gud' with any other debugger command, including
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
64 ;; user defined ones.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
65
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
66 (defmacro def-gud (func name key &optional doc)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
67 (let* ((cstr (list 'if '(not (= 1 arg))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
68 (list 'format "%s %s" name 'arg) name)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
69 (list 'progn
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
70 (list 'defun func '(arg)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
71 (or doc "")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
72 '(interactive "p")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
73 (list 'gud-call cstr))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
74 (list 'define-key 'gud-mode-map key (list 'quote func)))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
75
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
76 ;; All debugger-specific information is collected here
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
77 ;; Here's how it works, in case you ever need to add a debugger to the table.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
78 ;;
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
79 ;; Each entry must define the following at startup:
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
80 ;;
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
81 ;;<name>
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
82 ;; comint-prompt-regexp
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
83 ;; gud-<name>-startup-command
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
84 ;; gud-<name>-marker-filter
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
85 ;; gud-<name>-file-visit
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
86 ;; gud-<name>-set-break
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
87 ;;
477
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
88 ;; The job of the startup-command method is to fire up a copy of the debugger,
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
89 ;; given an object file and source directory.
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
90 ;;
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
91 ;; The job of the marker-filter method is to detect file/line markers in
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
92 ;; strings and set the global gud-last-frame to indicate what display
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
93 ;; action (if any) should be triggered by the marker. Note that only
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
94 ;; whetever the method *returns* is displayed in the buffer; thus, you
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
95 ;; can filter the debugger's output, interpreting some and passing on
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
96 ;; the rest.
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
97 ;;
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
98 ;; The job of the visit-file method is to visit and return the buffer indicated
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
99 ;; by the car of gud-tag-frame. This may be a file name, a tag name, or
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
100 ;; something else.
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
101 ;;
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
102 ;; The job of the gud-set-break method is to send the commands necessary
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
103 ;; to set a breakpoint at a given line in a given source file.
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
104 ;;
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
105 ;; Debugger-specific information begins here:
460
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
106
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
107 ;; ======================================================================
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
108 ;; gdb functions
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
109
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
110 (defun gud-gdb-debugger-startup (f d)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
111 (make-comint (concat "gud-" f) "gdb" nil "-fullname" "-cd" d f))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
112
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
113 (defun gud-gdb-marker-filter (proc s)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
114 (if (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n" s)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
115 (progn
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
116 (setq gud-last-frame
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
117 (cons
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
118 (substring string (match-beginning 1) (match-end 1))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
119 (string-to-int
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
120 (substring string (match-beginning 2) (match-end 2)))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
121 ;; this computation means the ^Z^Z-initiated marker in the
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
122 ;; input string is never emitted.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
123 (concat
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
124 (substring string 0 (match-beginning 0))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
125 (substring string (match-end 0))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
126 ))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
127 string))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
128
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
129 (defun gud-gdb-visit-file (f)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
130 (find-file-noselect f))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
131
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
132 (defun gud-gdb-set-break (proc f n)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
133 (gud-call "break %s:%d" f n))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
134
477
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
135 ;;;###autoload
460
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
136 (defun gdb (path)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
137 "Run gdb on program FILE in buffer *gud-FILE*.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
138 The directory containing FILE becomes the initial working directory
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
139 and source-file directory for your debugger."
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
140 (interactive "fRun gdb on file: ")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
141 (gud-overload-functions '((gud-debugger-startup gud-gdb-debugger-startup)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
142 (gud-marker-filter gud-gdb-marker-filter)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
143 (gud-visit-file gud-gdb-visit-file)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
144 (gud-set-break gud-gdb-set-break)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
145
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
146 (def-gud gud-step "step" "\C-cs" "Step one source line with display")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
147 (def-gud gud-stepi "stepi" "\C-ci" "Step one instruction with display")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
148 (def-gud gud-next "next" "\C-cn" "Step one line (skip functions)")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
149 (def-gud gud-cont "cont" "\C-c\C-c" "Continue with display")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
150
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
151 (def-gud gud-finish "finish" "\C-c\C-f" "Finish executing current function")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
152 (def-gud gud-up "up" "\C-c<" "Up N stack frames (numeric arg)")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
153 (def-gud gud-down "down" "\C-c>" "Down N stack frames (numeric arg)")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
154
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
155 (gud-common-init path)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
156
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
157 (setq comint-prompt-regexp "^(.*gdb[+]?) *")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
158 (run-hooks 'gdb-mode-hook)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
159 )
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
160
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
161
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
162 ;; ======================================================================
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
163 ;; sdb functions
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
164
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
165 (defun gud-sdb-debugger-startup (f d)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
166 (make-comint (concat "gud-" f) "sdb" nil f "-" d))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
167
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
168 (defun gud-sdb-marker-filter (proc str)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
169 (if (string-match "\\(^0x\\w* in \\|^\\|\n\\)\\([^:\n]*\\):\\([0-9]*\\):.*\n"
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
170 str)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
171 (setq gud-last-frame
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
172 (cons
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
173 (substring string (match-beginning 2) (match-end 2))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
174 (string-to-int
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
175 (substring string (match-beginning 3) (match-end 3))))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
176 string)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
177
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
178 (defun gud-sdb-visit-file (f)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
179 (find-tag-noselect f t))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
180
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
181 (defun gud-sdb-set-break (proc f n)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
182 (gud-queue-send (format "e %s" f) (format "%d b" n)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
183
477
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
184 ;;;###autoload
460
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
185 (defun sdb (path)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
186 "Run sdb on program FILE in buffer *gud-FILE*.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
187 The directory containing FILE becomes the initial working directory
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
188 and source-file directory for your debugger."
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
189 (if (not (and (boundp 'tags-file-name) (file-exists-p tags-file-name)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
190 (error "The sdb support requires a valid tags table to work."))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
191 (interactive "fRun sdb on file: ")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
192 (gud-overload-functions '((gud-debugger-startup gud-sdb-debugger-startup)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
193 (gud-marker-filter gud-sdb-marker-filter)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
194 (gud-visit-file gud-sdb-visit-file)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
195 (gud-set-break gud-sdb-set-break)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
196
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
197 (def-gud gud-step "s" "\C-cs" "Step one source line with display")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
198 (def-gud gud-stepi "i" "\C-ci" "Step one instruction with display")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
199 (def-gud gud-next "S" "\C-cn" "Step one source line (skip functions)")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
200 (def-gud gud-cont "c" "\C-cc" "Continue with display")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
201
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
202 (gud-common-init path)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
203
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
204 (setq comint-prompt-pattern "\\(^\\|\n\\)\\*")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
205 (run-hooks 'sdb-mode-hook)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
206 )
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
207
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
208 ;; ======================================================================
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
209 ;; dbx functions
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
210
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
211 (defun gud-dbx-debugger-startup (f d)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
212 (make-comint (concat "gud-" file) "dbx" nil f))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
213
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
214 (defun gud-dbx-marker-filter (proc str)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
215 (if (string-match
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
216 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\"" str)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
217 (setq gud-last-frame
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
218 (cons
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
219 (substring string (match-beginning 2) (match-end 2))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
220 (string-to-int
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
221 (substring string (match-beginning 1) (match-end 1))))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
222 string)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
223
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
224 (defun gud-dbx-visit-file (f)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
225 (find-file-noselect f))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
226
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
227 (defun gud-dbx-set-break (proc f n)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
228 (gud-call "stop at \"%s\":%d" f n))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
229
477
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
230 ;;;###autoload
460
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
231 (defun dbx (path)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
232 "Run dbx on program FILE in buffer *gud-FILE*.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
233 The directory containing FILE becomes the initial working directory
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
234 and source-file directory for your debugger."
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
235 (interactive "fRun dbx on file: ")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
236 (gud-overload-functions '((gud-debugger-startup gud-dbx-debugger-startup)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
237 (gud-marker-filter gud-dbx-marker-filter)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
238 (gud-visit-file gud-dbx-visit-file)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
239 (gud-set-break gud-dbx-set-break)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
240
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
241 (make-local-variable 'comint-prompt-regexp)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
242 (setq comint-prompt-regexp "^[^)]*dbx) *")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
243
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
244 (gud-common-init path)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
245
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
246 (run-hooks 'dbx-mode-hook)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
247 )
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
248
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
249 ;;
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
250 ;; End of debugger-specific information
477
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
251 ;;
460
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
252
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
253 (defvar gud-mode-map nil
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
254 "Keymap for gud-mode.")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
255
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
256 (defvar gud-command-queue nil)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
257
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
258 (if gud-mode-map
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
259 nil
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
260 (setq gud-mode-map (copy-keymap comint-mode-map))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
261 (define-key gud-mode-map "\C-l" 'gud-refresh))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
262
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
263 (define-key ctl-x-map " " 'gud-break)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
264 (define-key ctl-x-map "&" 'send-gud-command)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
265
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
266
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
267 (defun gud-mode ()
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
268 "Major mode for interacting with an inferior debugger process.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
269 The following commands are available:
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
270
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
271 \\{gud-mode-map}
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
272
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
273 \\[gud-display-frame] displays in the other window
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
274 the last line referred to in the gud buffer.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
275
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
276 \\[gud-step],\\[gud-next], and \\[gud-nexti] in the gud window,
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
277 do a step-one-line, step-one-line (not entering function calls), and
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
278 step-one-instruction and then update the other window
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
279 with the current file and position. \\[gud-cont] continues
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
280 execution.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
281
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
282 If you are in a source file, you may set a breakpoint at the current
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
283 line in the current source file by doing \\[gud-break].
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
284
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
285 Commands:
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
286 Many commands are inherited from comint mode.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
287 Additionally we have:
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
288
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
289 \\[gud-display-frame] display frames file in other window
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
290 \\[gud-step] advance one line in program
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
291 \\[gud-next] advance one line in program (skip over calls).
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
292 \\[send-gud-command] used for special printing of an arg at the current point.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
293 C-x SPACE sets break point at current line."
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
294 (interactive)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
295 (comint-mode)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
296 ; (kill-all-local-variables)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
297 (setq major-mode 'gud-mode)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
298 (setq mode-name "Debugger")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
299 (setq mode-line-process '(": %s"))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
300 (use-local-map gud-mode-map)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
301 (make-local-variable 'gud-last-frame)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
302 (setq gud-last-frame nil)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
303 (make-local-variable 'comint-prompt-regexp)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
304 (run-hooks 'gud-mode-hook)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
305 )
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
306
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
307 (defvar current-gud-buffer nil)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
308
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
309 (defun gud-common-init (path)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
310 ;; perform initializations common to all debuggers
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
311 (setq path (expand-file-name path))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
312 (let ((file (file-name-nondirectory path)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
313 (switch-to-buffer (concat "*gud-" file "*"))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
314 (setq default-directory (file-name-directory path))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
315 (or (bolp) (newline))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
316 (insert "Current directory is " default-directory "\n")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
317 (gud-debugger-startup file default-directory))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
318 (gud-mode)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
319 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
320 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
321 (setq gud-command-queue nil)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
322 (gud-set-buffer)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
323 )
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
324
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
325 (defun gud-set-buffer ()
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
326 (cond ((eq major-mode 'gud-mode)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
327 (setq current-gud-buffer (current-buffer)))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
328
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
329 (defun gud-filter (proc string)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
330 ;; This function is responsible for inserting output from your debugger
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
331 ;; into the buffer. The hard work is done by the method that is
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
332 ;; the value of gud-marker-filter.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
333 (let ((inhibit-quit t))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
334 (gud-filter-insert proc (gud-marker-filter proc string))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
335 ;; If we've got queued commands and we see a prompt, pop one and send it.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
336 ;; In theory we should check that a prompt has been issued before sending
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
337 ;; queued commands. In practice, command responses from the first through
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
338 ;; penultimate elements of a command sequence are short enough that we
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
339 ;; don't really have to bother.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
340 (if gud-command-queue
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
341 (progn
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
342 (gud-call (car gud-command-queue))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
343 (setq gud-command-queue (cdr gud-command-queue))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
344 )
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
345 )))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
346
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
347 (defun gud-filter-insert (proc string)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
348 ;; Here's where the actual buffer insertion is done
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
349 (let ((moving (= (point) (process-mark proc)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
350 (output-after-point (< (point) (process-mark proc)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
351 (old-buffer (current-buffer))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
352 start)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
353 (set-buffer (process-buffer proc))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
354 (unwind-protect
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
355 (save-excursion
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
356 ;; Insert the text, moving the process-marker.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
357 (goto-char (process-mark proc))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
358 (setq start (point))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
359 (insert-before-markers string)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
360 (set-marker (process-mark proc) (point))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
361 ;; Check for a filename-and-line number.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
362 ;; Don't display the specified file
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
363 ;; unless (1) point is at or after the position where output appears
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
364 ;; and (2) this buffer is on the screen.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
365 (if (and gud-last-frame (not output-after-point)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
366 (get-buffer-window (current-buffer)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
367 (gud-display-frame))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
368 )
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
369 (set-buffer old-buffer))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
370 (if moving (goto-char (process-mark proc)))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
371
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
372 (defun gud-sentinel (proc msg)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
373 (cond ((null (buffer-name (process-buffer proc)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
374 ;; buffer killed
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
375 ;; Stop displaying an arrow in a source file.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
376 (setq overlay-arrow-position nil)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
377 (set-process-buffer proc nil))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
378 ((memq (process-status proc) '(signal exit))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
379 ;; Stop displaying an arrow in a source file.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
380 (setq overlay-arrow-position nil)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
381 ;; Fix the mode line.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
382 (setq mode-line-process
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
383 (concat ": "
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
384 (symbol-name (process-status proc))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
385 (let* ((obuf (current-buffer)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
386 ;; save-excursion isn't the right thing if
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
387 ;; process-buffer is current-buffer
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
388 (unwind-protect
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
389 (progn
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
390 ;; Write something in *compilation* and hack its mode line,
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
391 (set-buffer (process-buffer proc))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
392 ;; Force mode line redisplay soon
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
393 (set-buffer-modified-p (buffer-modified-p))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
394 (if (eobp)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
395 (insert ?\n mode-name " " msg)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
396 (save-excursion
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
397 (goto-char (point-max))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
398 (insert ?\n mode-name " " msg)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
399 ;; If buffer and mode line will show that the process
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
400 ;; is dead, we can delete it now. Otherwise it
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
401 ;; will stay around until M-x list-processes.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
402 (delete-process proc))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
403 ;; Restore old buffer, but don't restore old point
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
404 ;; if obuf is the gud buffer.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
405 (set-buffer obuf))))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
406
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
407
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
408 (defun gud-refresh (&optional arg)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
409 "Fix up a possibly garbled display, and redraw the arrow."
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
410 (interactive "P")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
411 (recenter arg)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
412 (gud-display-frame))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
413
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
414 (defun gud-display-frame ()
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
415 "Find and obey the last filename-and-line marker from the debugger.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
416 Obeying it means displaying in another window the specified file and line."
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
417 (interactive)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
418 (if gud-last-frame
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
419 (progn
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
420 (gud-set-buffer)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
421 (gud-display-line (car gud-last-frame) (cdr gud-last-frame))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
422 (setq gud-last-frame nil))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
423
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
424 ;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
425 ;; and that its line LINE is visible.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
426 ;; Put the overlay-arrow on the line LINE in that buffer.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
427
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
428 (defun gud-display-line (true-file line)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
429 (let* ((buffer (gud-visit-file true-file))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
430 (window (display-buffer buffer t))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
431 (pos))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
432 (save-excursion
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
433 (set-buffer buffer)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
434 (save-restriction
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
435 (widen)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
436 (goto-line line)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
437 (setq pos (point))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
438 (setq overlay-arrow-string "=>")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
439 (or overlay-arrow-position
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
440 (setq overlay-arrow-position (make-marker)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
441 (set-marker overlay-arrow-position (point) (current-buffer)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
442 (cond ((or (< pos (point-min)) (> pos (point-max)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
443 (widen)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
444 (goto-char pos))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
445 (set-window-point window overlay-arrow-position)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
446
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
447 (defun gud-call (command &rest args)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
448 "Invoke the debugger COMMAND displaying source in other window."
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
449 (interactive)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
450 (gud-set-buffer)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
451 (goto-char (point-max))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
452 (let ((command (concat (apply 'format command args) "\n"))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
453 (proc (get-buffer-process current-gud-buffer)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
454 (gud-filter-insert proc command)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
455 (send-string proc command)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
456 ))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
457
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
458 (defun gud-queue-send (&rest cmdlist)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
459 ;; Send the first command, queue the rest for send after successive
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
460 ;; send on subsequent prompts
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
461 (interactive)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
462 (gud-call (car cmdlist))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
463 (setq gud-command-queue (append gud-command-queue (cdr cmdlist))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
464
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
465 (defun gud-apply-from-source (func)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
466 ;; Apply a method from the gud buffer environment, passing it file and line.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
467 ;; This is intended to be used for gud commands called from a source file.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
468 (if (not buffer-file-name)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
469 (error "There is no file associated with this buffer"))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
470 (let ((file (file-name-nondirectory buffer-file-name))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
471 (line (save-restriction (widen) (1+ (count-lines 1 (point))))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
472 (save-excursion
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
473 (gud-set-buffer)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
474 (funcall func
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
475 (get-buffer-process current-gud-buffer)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
476 file
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
477 line)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
478 )))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
479
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
480 (defun gud-break ()
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
481 "Set breakpoint at this source line."
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
482 (interactive)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
483 (gud-apply-from-source 'gud-set-break))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
484
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
485 (defun gud-read-address()
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
486 "Return a string containing the core-address found in the buffer at point."
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
487 (save-excursion
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
488 (let ((pt (dot)) found begin)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
489 (setq found (if (search-backward "0x" (- pt 7) t)(dot)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
490 (cond (found (forward-char 2)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
491 (setq result
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
492 (buffer-substring found
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
493 (progn (re-search-forward "[^0-9a-f]")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
494 (forward-char -1)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
495 (dot)))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
496 (t (setq begin (progn (re-search-backward "[^0-9]") (forward-char 1)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
497 (dot)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
498 (forward-char 1)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
499 (re-search-forward "[^0-9]")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
500 (forward-char -1)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
501 (buffer-substring begin (dot)))))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
502
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
503
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
504 (defvar gud-commands nil
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
505 "List of strings or functions used by send-gud-command.
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
506 It is for customization by you.")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
507
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
508 (defun send-gud-command (arg)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
509
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
510 "This command reads the number where the cursor is positioned. It
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
511 then inserts this ADDR at the end of the debugger buffer. A numeric arg
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
512 selects the ARG'th member COMMAND of the list gud-print-command. If
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
513 COMMAND is a string, (format COMMAND ADDR) is inserted, otherwise
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
514 (funcall COMMAND ADDR) is inserted. eg. \"p (rtx)%s->fld[0].rtint\"
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
515 is a possible string to be a member of gud-commands. "
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
516
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
517
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
518 (interactive "P")
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
519 (let (comm addr)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
520 (if arg (setq comm (nth arg gud-commands)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
521 (setq addr (gud-read-address))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
522 (if (eq (current-buffer) current-gud-buffer)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
523 (set-mark (point)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
524 (cond (comm
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
525 (setq comm
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
526 (if (stringp comm) (format comm addr) (funcall comm addr))))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
527 (t (setq comm addr)))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
528 (switch-to-buffer current-gud-buffer)
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
529 (goto-char (dot-max))
c103b99fd872 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
530 (insert-string comm)))
477
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
531
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
532 ;; gud.e ends here
ab9a55b26bd4 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 460
diff changeset
533