开发者

How to get input from gdb in emacs (with python script)

I want to use python to create some interactive script for gdb. It works well in gdb, but it doesn't work if I invoke gdb from emacs.

For example, the python script (test.py) is like below. It simply print what it gets.

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

It works in gdb:

% gd开发者_如何学Gob
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

But in emacs, it will just hang in "raw_input" and could never get the input:

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

Is there anyway to make it work just as in gdb?


Invoking gdb with M-x gud-gdb solved the problem for me. For further details confer chapter 27 of the Emacs manual.

Hope this is still helpful after two years...


When using an interactive external process in an emacs buffer, the mode needs to be able to recognize from the buffer when the external process is prompting the user for input so that it knows it need to allow the user to input something. Otherwise, emacs will just wait forever for the process to output something it recognizes and the process will be waiting forever for input. Since your python script uses a different prompt, the emacs gdb mode never recognizes that input is being solicited.

Try modifying the value of gdb-prompt-name-regexp. Here's the default value from gdb-mi.el:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜