如何通过GUD获取发送到PDB的命令?

9
我已经开始在emacs 23.3中通过gud使用pdb,如何挂钩从缓冲区发送给调试器的命令消息?我为gdb编写了下面的建议,以保持comint的环,但找不到一个等效的函数来挂钩pdb。我正在使用python-mode.el作为我的major mode。
谢谢。
(defadvice gdb-send-item (before gdb-save-history first nil activate)
  "write input ring on quit"
  (if (equal (type-of item) 'string) ; avoid problems with 'unprintable' structures sent to this function..
    (if (string-match "^q\\(u\\|ui\\|uit\\)?$" item)
      (progn (comint-write-input-ring)
             (message "history file '%s' written" comint-input-ring-file-name)))))

注意:'gdb-send-item'在Emacs 23.3和现在(24.3)之间的某个版本中已被删除,但将上述'string-match'与下面答案中的建议合并即可使我的Emacs GUD/GDB和外部GDB历史记录再次同步。 - elbeardmorez
1个回答

2
我想我当时可能只需要再深入一点就能回答自己的问题了,但是第一个gdb解决方案在学习方面让我感到有些吃力。我恢复过来了,所以...
C-h b C-s Major 经过一番滚动,我们可以确定“comint-send-input”是与“enter”键绑定的函数。查看这个函数的源代码,comint.el:1765是对'run-hook-with-args'的调用..这时我们意识到没有特定的地方可以使用“pdb”来实现我们想要的功能。
Gud是一个通用的包装器,用于调用外部调试进程并返回结果...因此控制不在elisp中。虽然gdb也是如此,但是有一个很好的(已经存在的)包装器围绕外部调用,使得对该函数进行建议感觉很“干净”。
所以这个hack...就在“comint-send-input”上面,有一个“comint-add-to-input-history”..非常简单。
;;save command history
(defadvice comint-add-to-input-history (before pdb-save-history activate compile)
  "write input ring on exit"
  (message "%s" cmd)
  (if (string-match "^e\\(x\\|xi\\|xit\\)?$" cmd)
  (progn (comint-write-input-ring)
     (message "history file '%s' written" comint-input-ring-file-name)))
)

提醒一下,我有这些东西来启动调试会话的输入环

;#debugger history
(defun debug-history-ring (file)
  (comint-read-input-ring t)
  (setq comint-input-ring-file-name file)
  (setq comint-input-ring-size 1000)
  (setq comint-input-ignoredups t))
(let ((hooks '((gdb-mode-hook . (lambda () (debug-history-ring "~/.gdbhist")))
       (pdb-mode-hook . (lambda () (debug-history-ring  "~/.pythonhist"))))))
  (dolist (hook hooks) (print (cdr hook)) (add-hook (car hook) (cdr hook))))

..并在调试缓冲区被清除时写入历史文件
  (add-hook 'kill-buffer-hook 'comint-write-input-ring)

干杯。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接