如何在 emacs 中从 gdb 获取输入(使用 python 脚本)
我想使用 python 为 gdb 创建一些交互式脚本。它在 gdb 中运行良好,但如果我从 emacs 调用 gdb,则它不起作用。
例如,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 中一样工作?
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:
% 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
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
Mx gud-gdb
调用 gdb 解决了我的问题。有关更多详细信息,请参阅 Emacs 手册的第 27 章。希望两年后这仍然有帮助......
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...
当在 emacs 缓冲区中使用交互式外部进程时,该模式需要能够从缓冲区中识别外部进程何时提示用户输入,以便它知道需要允许用户输入某些内容。否则,emacs 将永远等待进程输出它识别的内容,并且进程将永远等待输入。由于您的 python 脚本使用不同的提示符,因此 emacs gdb 模式永远不会识别正在请求输入。
尝试修改
gdb-prompt-name-regexp
的值。以下是gdb-mi.el
的默认值: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 fromgdb-mi.el
: