annotate lisp/gud.el @ 1025:1ccd97bc1d2b

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