如何通过gud挂钩发送到pdb的命令?

时间:2011-06-06 20:37:11

标签: python emacs elisp pdb gud

我已经开始在emacs 23.3中通过gud使用pdb了,我如何挂钩从缓冲区发送到调试器的命令消息?我写了下面的建议与gdb一起使用,以便持久化comint的响铃,但找不到与pdb挂钩的等效函数。我正在使用python-mode.el作为我的主要模式。

感谢。

(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)))))

1 个答案:

答案 0 :(得分:1)

我想我当时可能已经回答了我自己的问题而只是进行了一些挖掘,但是第一个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)))
)

fyi,我有这些来启动调试会话的输入环

;#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)

欢呼声。