aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-05-21 03:34:21 +0000
committerRichard M. Stallman1998-05-21 03:34:21 +0000
commitd2d23393cdbddf56f6a5211caf509a3c462eaea1 (patch)
tree88960c4b11074df345a0140dfecf6e9fa4755377
parentba14e174a6afb436c0ea57faaa9cf169be764076 (diff)
downloademacs-d2d23393cdbddf56f6a5211caf509a3c462eaea1.tar.gz
emacs-d2d23393cdbddf56f6a5211caf509a3c462eaea1.zip
Support pdb.
(pdb): New function. (gud-pdb-command-name): New variable. (pdb-minibuffer-local-map): Likewise. (gud-pdb-find-file): New function. (gud-pdb-marker-filter): New function. (gud-pdb-marker-regexp*): New variables. (gud-pdb-massage-args): New function. (gud-pdb-history): New variable.
-rw-r--r--lisp/gud.el136
1 files changed, 135 insertions, 1 deletions
diff --git a/lisp/gud.el b/lisp/gud.el
index a88fb98b65c..66cd552c7a8 100644
--- a/lisp/gud.el
+++ b/lisp/gud.el
@@ -47,7 +47,7 @@
47 47
48(defgroup gud nil 48(defgroup gud nil
49 "Grand Unified Debugger mode for gdb and other debuggers under Emacs. 49 "Grand Unified Debugger mode for gdb and other debuggers under Emacs.
50Supported debuggers include gdb, sdb, dbx, xdb, perldb, and jdb." 50Supported debuggers include gdb, sdb, dbx, xdb, perldb, pdb (Python), and jdb."
51 :group 'unix 51 :group 'unix
52 :group 'tools) 52 :group 'tools)
53 53
@@ -1269,6 +1269,140 @@ and source-file directory for your debugger."
1269 ) 1269 )
1270 1270
1271;; ====================================================================== 1271;; ======================================================================
1272;; pdb (Python debugger) functions
1273
1274;;; History of argument lists passed to pdb.
1275(defvar gud-pdb-history nil)
1276
1277(defun gud-pdb-massage-args (file args)
1278 args)
1279
1280;; Last group is for return value, e.g. "> test.py(2)foo()->None"
1281;; Either file or function name may be omitted: "> <string>(0)?()"
1282(defvar gud-pdb-marker-regexp
1283 "^> \\([-a-zA-Z0-9_/.]*\\|<string>\\)(\\([0-9]+\\))\\([a-zA-Z0-9_]*\\|\\?\\)()\\(->[^\n]*\\)?\n")
1284(defvar gud-pdb-marker-regexp-file-group 1)
1285(defvar gud-pdb-marker-regexp-line-group 2)
1286(defvar gud-pdb-marker-regexp-fnname-group 3)
1287
1288(defvar gud-pdb-marker-regexp-start "^> ")
1289
1290;; There's no guarantee that Emacs will hand the filter the entire
1291;; marker at once; it could be broken up across several strings. We
1292;; might even receive a big chunk with several markers in it. If we
1293;; receive a chunk of text which looks like it might contain the
1294;; beginning of a marker, we save it here between calls to the
1295;; filter.
1296(defun gud-pdb-marker-filter (string)
1297 (setq gud-marker-acc (concat gud-marker-acc string))
1298 (let ((output ""))
1299
1300 ;; Process all the complete markers in this chunk.
1301 (while (string-match gud-pdb-marker-regexp gud-marker-acc)
1302 (setq
1303
1304 ;; Extract the frame position from the marker.
1305 gud-last-frame
1306 (let ((file (match-string gud-pdb-marker-regexp-file-group
1307 gud-marker-acc))
1308 (line (string-to-int
1309 (match-string gud-pdb-marker-regexp-line-group
1310 gud-marker-acc))))
1311 (if (string-equal file "<string>")
1312 gud-last-frame
1313 (cons file line)))
1314
1315 ;; Output everything instead of the below
1316 output (concat output (substring gud-marker-acc 0 (match-end 0)))
1317;; ;; Append any text before the marker to the output we're going
1318;; ;; to return - we don't include the marker in this text.
1319;; output (concat output
1320;; (substring gud-marker-acc 0 (match-beginning 0)))
1321
1322 ;; Set the accumulator to the remaining text.
1323 gud-marker-acc (substring gud-marker-acc (match-end 0))))
1324
1325 ;; Does the remaining text look like it might end with the
1326 ;; beginning of another marker? If it does, then keep it in
1327 ;; gud-marker-acc until we receive the rest of it. Since we
1328 ;; know the full marker regexp above failed, it's pretty simple to
1329 ;; test for marker starts.
1330 (if (string-match gud-pdb-marker-regexp-start gud-marker-acc)
1331 (progn
1332 ;; Everything before the potential marker start can be output.
1333 (setq output (concat output (substring gud-marker-acc
1334 0 (match-beginning 0))))
1335
1336 ;; Everything after, we save, to combine with later input.
1337 (setq gud-marker-acc
1338 (substring gud-marker-acc (match-beginning 0))))
1339
1340 (setq output (concat output gud-marker-acc)
1341 gud-marker-acc ""))
1342
1343 output))
1344
1345(defun gud-pdb-find-file (f)
1346 (save-excursion
1347 (let ((buf (find-file-noselect f)))
1348 (set-buffer buf)
1349 (gud-make-debug-menu)
1350 ;; (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish))
1351 ;; (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
1352 ;; (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
1353 buf)))
1354
1355(defvar pdb-minibuffer-local-map nil
1356 "Keymap for minibuffer prompting of pdb startup command.")
1357(if pdb-minibuffer-local-map
1358 ()
1359 (setq pdb-minibuffer-local-map (copy-keymap minibuffer-local-map))
1360 (define-key
1361 pdb-minibuffer-local-map "\C-i" 'comint-dynamic-complete-filename))
1362
1363(defcustom gud-pdb-command-name "pdb"
1364 "File name for executing the Python debugger.
1365This should be an executable on your path, or an absolute file name."
1366 :type 'string
1367 :group 'gud)
1368
1369;;;###autoload
1370(defun pdb (command-line)
1371 "Run pdb on program FILE in buffer `*gud-FILE*'.
1372The directory containing FILE becomes the initial working directory
1373and source-file directory for your debugger."
1374 (interactive
1375 (list (read-from-minibuffer "Run pdb (like this): "
1376 (if (consp gud-pdb-history)
1377 (car gud-pdb-history)
1378 (concat gud-pdb-command-name " "))
1379 pdb-minibuffer-local-map nil
1380 '(gud-pdb-history . 1))))
1381
1382 (gud-common-init command-line 'gud-pdb-massage-args
1383 'gud-pdb-marker-filter 'gud-pdb-find-file)
1384
1385 (gud-def gud-break "break %l" "\C-b" "Set breakpoint at current line.")
1386 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
1387 (gud-def gud-step "step" "\C-s" "Step one source line with display.")
1388 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
1389 (gud-def gud-cont "continue" "\C-r" "Continue with display.")
1390 (gud-def gud-finish "return" "\C-f" "Finish executing current function.")
1391 (gud-def gud-up "up" "<" "Up one stack frame.")
1392 (gud-def gud-down "down" ">" "Down one stack frame.")
1393 (gud-def gud-print "p %e" "\C-p" "Evaluate Python expression at point.")
1394 ;; Is this right?
1395 (gud-def gud-statement "! %e" "\C-e" "Execute Python statement at point.")
1396
1397 (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish))
1398 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
1399 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
1400 ;; (setq comint-prompt-regexp "^(.*pdb[+]?) *")
1401 (setq comint-prompt-regexp "^(Pdb) *")
1402 (setq paragraph-start comint-prompt-regexp)
1403 (run-hooks 'pdb-mode-hook))
1404
1405;; ======================================================================
1272;; 1406;;
1273;; JDB support. 1407;; JDB support.
1274;; 1408;;