首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何挂接通过gud发送到pdb的命令?

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

Stack Overflow用户
提问于 2011-06-07 04:37:11
回答 1查看 566关注 0票数 9

我已经开始在emacs 23.3中通过gud使用pdb了,我怎样才能钩住从缓冲区发送到调试器的命令消息呢?我写了下面的建议用于gdb,以便持久化comint的环,但找不到一个等效的函数来挂钩pdb。我使用python-mode.el作为我的主要模式。

谢谢。

代码语言:javascript
复制
(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)))))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-18 01:59:09

我想我当时可能只需要再深入一点就可以回答我自己的问题,但是第一个gdb解决方案让我在旧的学习战线上失去了它。我恢复了,所以..。

C-h b C-s大调

经过一些滚动,我们可以确定'comint-send-input‘是绑定到'enter’键的函数。看一下这个函数的源代码,comint.el:1765是对'run-hook-with-args‘的调用,而..this是我们意识到没有地方特别'pdb’来做我们想要做的事情。

gud是一个通用的包装器,用于调用外部调试进程并返回结果。..hence控件在elisp中是不存在的。gdb也是一样,但是外部调用有一个很好的(预先存在的)包装器,这使得通知函数感觉很“干净”。

所以黑客..。就在'comint-send-input‘的上方是'comint-add-to-input-history'..非常简单。

代码语言:javascript
复制
;;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)))
)

仅供参考,我用它们来启动调试会话的输入环

代码语言:javascript
复制
;#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))))

在取消调试缓冲区时写入历史文件的..and

代码语言:javascript
复制
  (add-hook 'kill-buffer-hook 'comint-write-input-ring)

干杯。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6257758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档