File: rep-debugger.el

package info (click to toggle)
librep 0.92.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 4,116 kB
  • ctags: 2,915
  • sloc: ansic: 31,305; lisp: 11,265; sh: 10,704; makefile: 462; sed: 93
file content (137 lines) | stat: -rw-r--r-- 5,124 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
;;; rep-debugger.el --- Rep hacks for Emacs' gud.el

;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
;; Author: John Harper <jsh@pixelslut.com>
;; Keywords: unix, tools, rep

;; Copyright (C) 1992, 93, 94, 95, 96, 1998 Free Software Foundation, Inc.

;; This file is part of Librep.

;; Librep is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; Librep is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with Librep; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301 USA. 

;; This file is the perldb portions of gud.el with trivial substitutions
;; to make it work with rep..

(require 'gud)

;; ======================================================================
;; rep functions

;;; History of argument lists passed to rep.
(defvar gud-rep-history nil)

(defun gud-rep-massage-args (file args)
  (cons "--debug" (cons (car args) (cons "--emacs-debug" (cdr args)))))

;; There's no guarantee that Emacs will hand the filter the entire
;; marker at once; it could be broken up across several strings.  We
;; might even receive a big chunk with several markers in it.  If we
;; receive a chunk of text which looks like it might contain the
;; beginning of a marker, we save it here between calls to the
;; filter.
(defun gud-rep-marker-filter (string)
  (setq gud-marker-acc (concat gud-marker-acc string))
  (let ((output ""))

    ;; Process all the complete markers in this chunk.
    (while (string-match "\032\032\\(\\([a-zA-Z]:\\)?[^:\n]*\\):\\([0-9]*\\):.*\n"
			 gud-marker-acc)
      (setq

       ;; Extract the frame position from the marker.
       gud-last-frame
       (cons (substring gud-marker-acc (match-beginning 1) (match-end 1))
	     (string-to-int (substring gud-marker-acc
				       (match-beginning 3)
				       (match-end 3))))

       ;; Append any text before the marker to the output we're going
       ;; to return - we don't include the marker in this text.
       output (concat output
		      (substring gud-marker-acc 0 (match-beginning 0)))

       ;; Set the accumulator to the remaining text.
       gud-marker-acc (substring gud-marker-acc (match-end 0))))

    ;; Does the remaining text look like it might end with the
    ;; beginning of another marker?  If it does, then keep it in
    ;; gud-marker-acc until we receive the rest of it.  Since we
    ;; know the full marker regexp above failed, it's pretty simple to
    ;; test for marker starts.
    (if (string-match "\032.*\\'" gud-marker-acc)
	(progn
	  ;; Everything before the potential marker start can be output.
	  (setq output (concat output (substring gud-marker-acc
						 0 (match-beginning 0))))

	  ;; Everything after, we save, to combine with later input.
	  (setq gud-marker-acc
		(substring gud-marker-acc (match-beginning 0))))

      (setq output (concat output gud-marker-acc)
	    gud-marker-acc ""))

    output))

(defun gud-rep-find-file (f)
  (save-excursion
    (let ((buf (find-file-noselect f)))
      (set-buffer buf)
      (gud-make-debug-menu)
      buf)))

(defcustom gud-rep-command-name "rep"
  "File name for executing rep."
  :type 'string
  :group 'gud)

;;;###autoload
(defun rep-debugger (command-line)
  "Run the rep debugger on program FILE in buffer *gud-FILE*.
The directory containing FILE becomes the initial working directory
and source-file directory for your debugger."
  (interactive
   (list (read-from-minibuffer "Run rep debugger (like this): "
			       (if (consp gud-rep-history)
				   (car gud-rep-history)
				 (concat gud-rep-command-name
					 " "
					 (buffer-file-name)
					 " "))
			       nil nil
			       '(gud-rep-history . 1))))

  (gud-common-init command-line 'gud-rep-massage-args
		   'gud-rep-marker-filter 'gud-rep-find-file)

;  (gud-def gud-break  "b %l"         "\C-b" "Set breakpoint at current line.")
;  (gud-def gud-remove "d %l"         "\C-d" "Remove breakpoint at current line")
  (gud-def gud-step   "s"            "\C-s" "Step one source line with display.")
  (gud-def gud-next   "n"            "\C-n" "Step one line (skip functions).")
  (gud-def gud-cont   "c"            "\C-r" "Continue with display.")
;  (gud-def gud-finish "finish"       "\C-f" "Finish executing current function.")
  (gud-def gud-up     "u %p"        "<" "Up N stack frames (numeric arg).")
  (gud-def gud-down   "down %p"      ">" "Down N stack frames (numeric arg).")
  (gud-def gud-print  "p %e"           "\C-p" "Evaluate perl expression at point.")

  (setq comint-prompt-regexp "^rep-db> ")
  (setq paragraph-start comint-prompt-regexp)
  (run-hooks 'rep-debugger-mode-hook))

(provide 'rep-debugger)

;; rep-debugger.el ends here