2011-04-13 51 views
1

我想使用python爲gdb創建一些交互式腳本。它在gdb中運行良好,但如果我通過emacs調用gdb,則不起作用。如何從gdb中獲取輸入(使用python腳本)

例如,python腳本(test.py)如下所示。它只是打印它得到的。

def testInput(): 
    n = raw_input('(gdb) ') 
    print n 

它的工作原理在gdb:

% gdb 
GNU gdb (GDB) 7.2.50.20110217 
Copyright (C) 2011 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. Type "show copying" 
and "show warranty" for details. 
This GDB was configured as "x86_64-unknown-linux-gnu". 
For bug reporting instructions, please see: 
<http://www.gnu.org/software/gdb/bugs/>. 
(gdb) source test.py 
(gdb) python testInput() 
(gdb) 1 
1 
(gdb) q 

但在Emacs,它會掛在 「的raw_input」 和永遠無法得到的輸入:

(gdb) source test.py 
(gdb) python testInput() 
(gdb) 1 
2 
... 

反正有做它和gdb一樣工作?

回答

0

當Emacs的緩衝區使用交互式外部進程,模式需要能夠在外部過程後,提示輸入用戶從緩衝區認識,以便它知道它需要讓用戶輸入的東西。否則,emacs將會永遠等待進程輸出可識別的內容,並且該進程將永久等待輸入。由於您的python腳本使用不同的提示,因此emacs gdb模式永遠不會識別輸入被請求。

嘗試修改gdb-prompt-name-regexp的值。下面是從gdb-mi.el默認值:

(defvar gdb-prompt-name-regexp "value=\"\\(.*?\\)\"") 
+0

的問題是從你的腳本的提示,你需要的正則表達式匹配你需要的emacs認識到作爲提示所有的東西。 – 2011-09-02 05:53:32

+0

我改變了腳本,所以它使用與原始gdb相同的提示符,但它仍然不起作用。 – vicshen 2011-09-02 05:58:40

+0

啊,對不起,誤解了你以前的評論。沒有線索。 – 2011-09-02 06:10:14

1

M-x gud-gdb調用gdb的解決了這個問題對我來說。有關詳細信息,請參閱Emacs手冊的第27章。

希望這仍然是兩年後有幫助...

相關問題