[英]gdb within emacs: python commands (py and pi)
I want to debug a c++ program using gdb. 我想使用gdb调试c ++程序。 I use the
pi
and the py
commands to evaluate python commands from within gdb, which works fine when I invoke gdb from the command line. 我使用
pi
和py
命令从gdb中评估python命令,当我从命令行调用gdb时,效果很好。 However, when I invoke gdb from within emacs using Mx gdb
and then gdb -i=mi file_name
, the following errors occur: 但是,当我使用
Mx gdb
gdb从emacs中调用gdb,然后使用gdb -i=mi file_name
,会发生以下错误:
pi
command correctly opens an interactive python shell, but any input to this shell yields the errors like this: pi
命令正确打开了一个交互式python shell,但是对此shell的任何输入都会产生如下错误: File "stdin", line 1
文件“ stdin”,第1行
-interpreter-exec console "2"-interpreter-exec控制台“ 2”
SyntaxError: invalid syntaxSyntaxError:语法无效
py
command works correctly for a single command (like py print 2+2
), but not for multiple commands py
命令py
单个命令有效(例如py print 2+2
),但对多个命令无效 I can get around those problems by starting gdb with gud-gdb
, but then I dont have the support for gdb-many-windows
. 我可以通过使用
gud-gdb
启动gdb来解决这些问题,但是后来我没有对gdb-many-windows
的支持。 Maybe the problem is caused by the prompt after typing pi
, which is no longer (gdb)
but >>>
instead? 也许问题是由键入
pi
后的提示引起的,不再是(gdb)
而是>>>
?
I am going to go out on a limb and say this is a bug in gud mode. 我要弯腰说这是在gud模式下的错误。 The clue is the
-interpreter-exec
line in the error. 提示是错误中的
-interpreter-exec
行。
What happens here is that gud runs gdb in a special "MI" ("Machine Interface") mode. 这里发生的是,gud以特殊的“ MI”(“计算机接口”)模式运行gdb。 In this mode, commands and their responses are designed to be machine-, rather than human-, readable.
在这种模式下,命令及其响应被设计为机器可读的,而不是人类可读的。
To let GUIs provide a console interface to users, MI provides the -interpreter-exec
command, which evaluates a command using some other gdb "interpreter" (which doesn't mean what you may think and in particular has nothing to do with Python). 为了让GUI为用户提供控制台界面,MI提供了
-interpreter-exec
命令,该命令使用其他gdb“解释器”评估命令(这并不意味着您可能会想到,尤其与Python无关) 。
So, gud sends user input to gdb, I believe, with -interpreter-exec console ...
. 因此,我相信gud使用
-interpreter-exec console ...
将用户输入发送到gdb。 But, in the case of a continuation line for a python
command, this is the wrong thing to do. 但是,在使用
python
命令的续行的情况下,这样做是错误的。
I tried this out in Emacs and I was able to make it work for the python
command when I spelled it out -- but py
, pi
, and python-interactive
all failed. 我在Emacs中进行了尝试,并在拼写出来时使它适用于
python
命令-但py
, pi
和python-interactive
均失败。
I had this problem when I build and used emacs 24.5.1 using gdb 7.9.1. 使用gdb 7.9.1构建和使用emacs 24.5.1时遇到了这个问题。
I have no problem with gdb command line, but weird behavior with gdb-emacs. 我对gdb命令行没有任何问题,但是对gdb-emacs的行为却很奇怪。
I get the behavior described by Tom and user280107, depending on the order of commands and operations: 我得到了Tom和user280107描述的行为,具体取决于命令和操作的顺序:
(gdb) pi
>>> print(123)
File "<stdin>", line 1
-interpreter-exec console "print(123) "
^
SyntaxError: invalid syntax
>>>
However, if I run a 'python xxx' command first, it seems to work (some forgotten initialization?): 但是,如果我先运行“ python xxx”命令,它似乎可以工作(某些被遗忘的初始化?):
(gdb) python print(123)
123
(gdb) pi
pi
>>> print(123)
123
>>>
Anyway, I've sent a note to emacs-devel@gnu.org. 无论如何,我已经发送了一封邮件到emacs-devel@gnu.org。
BTW, I'm sure Tom T. knows way more about this than I do 顺便说一句,我确定汤姆T.比我更了解这一点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.