如何在 emacs 中从 gdb 获取输入(使用 python 脚本)

发布于 2024-11-01 16:39:30 字数 968 浏览 1 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请别遗忘我 2024-11-08 16:39:30

使用 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...

心凉怎暖 2024-11-08 16:39:30

当在 emacs 缓冲区中使用交互式外部进程时,该模式需要能够从缓冲区中识别外部进程何时提示用户输入,以便它知道需要允许用户输入某些内容。否则,emacs 将永远等待进程输出它识别的内容,并且进程将永远等待输入。由于您的 python 脚本使用不同的提示符,因此 emacs gdb 模式永远不会识别正在请求输入。

尝试修改gdb-prompt-name-regexp的值。以下是 gdb-mi.el 的默认值:

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

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=\"\\(.*?\\)\"")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文