* Discrepancy between Python and Guile wrt exiting the interpreter
@ 2020-01-18 14:46 Eli Zaretskii
2020-01-19 16:11 ` Simon Marchi
2020-01-23 17:21 ` Pedro Alves
0 siblings, 2 replies; 15+ messages in thread
From: Eli Zaretskii @ 2020-01-18 14:46 UTC (permalink / raw)
To: gdb-patches
If you invoke the Guile interpreter from GDB:
(gdb) gr
then typing ,q followed by Enter exits the Guile interpreter back to
GDB. However, if the Python interpreter is started:
(gdb) pi
then typing quit() and Enter exits GDB, not just the Python
interpreter. Why do these two interpreters behave differently in this
context? Is there some other Python command to exit the interpreter?
(I know about Ctrl-D, but I'm asking about commands.)
Thanks.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-18 14:46 Discrepancy between Python and Guile wrt exiting the interpreter Eli Zaretskii
@ 2020-01-19 16:11 ` Simon Marchi
2020-01-19 16:42 ` Eli Zaretskii
2020-01-23 17:21 ` Pedro Alves
1 sibling, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2020-01-19 16:11 UTC (permalink / raw)
To: Eli Zaretskii, gdb-patches
On 2020-01-18 6:07 a.m., Eli Zaretskii wrote:
> If you invoke the Guile interpreter from GDB:
>
> (gdb) gr
>
> then typing ,q followed by Enter exits the Guile interpreter back to
> GDB. However, if the Python interpreter is started:
>
> (gdb) pi
>
> then typing quit() and Enter exits GDB, not just the Python
> interpreter. Why do these two interpreters behave differently in this
> context? Is there some other Python command to exit the interpreter?
> (I know about Ctrl-D, but I'm asking about commands.)
>
> Thanks.
>
I looked into it, but didn't find a way to exit the Python interpreter and
come back in GDB by typing a Python command. That command would somehow
have to fool the Python interpreter in thinking that its input stream, which
we pass here:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/python/python.c;h=d6f7f99c457300cba8e6dbe590ac15b4b2e2b110;hb=HEAD#l302
has reached EOF.
I'm not saying it can't be done, just that I haven't found a way.
Simon
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-19 16:11 ` Simon Marchi
@ 2020-01-19 16:42 ` Eli Zaretskii
2020-01-19 17:20 ` Simon Marchi
0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2020-01-19 16:42 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches
> From: Simon Marchi <simark@simark.ca>
> Date: Sun, 19 Jan 2020 11:07:14 -0500
>
> I looked into it, but didn't find a way to exit the Python interpreter and
> come back in GDB by typing a Python command. That command would somehow
> have to fool the Python interpreter in thinking that its input stream, which
> we pass here:
>
> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/python/python.c;h=d6f7f99c457300cba8e6dbe590ac15b4b2e2b110;hb=HEAD#l302
>
> has reached EOF.
Ctrl-d does that, but it is not a command.
Is there any reason why quit() exits from GDB as well? Doesn't the
Python interpreter support invocation from some other 'main' program?
It's strange.
Thanks.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-19 16:42 ` Eli Zaretskii
@ 2020-01-19 17:20 ` Simon Marchi
2020-01-19 19:13 ` Eli Zaretskii
0 siblings, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2020-01-19 17:20 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
On 2020-01-19 11:40 a.m., Eli Zaretskii wrote:
>> From: Simon Marchi <simark@simark.ca>
>> Date: Sun, 19 Jan 2020 11:07:14 -0500
>>
>> I looked into it, but didn't find a way to exit the Python interpreter and
>> come back in GDB by typing a Python command. That command would somehow
>> have to fool the Python interpreter in thinking that its input stream, which
>> we pass here:
>>
>> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/python/python.c;h=d6f7f99c457300cba8e6dbe590ac15b4b2e2b110;hb=HEAD#l302
>>
>> has reached EOF.
>
> Ctrl-d does that, but it is not a command.
>
> Is there any reason why quit() exits from GDB as well? Doesn't the
> Python interpreter support invocation from some other 'main' program?
> It's strange.
Yes, it does (we use it). It's just the way it works. From [1]:
Read and execute statements from a file associated with an interactive device
until EOF is reached.
The quit() and exit() functions are aliases of the same thing. They raise a
"SystemExit" exception. According to the SystemExit exception [2]:
When it is not handled, the Python interpreter exits; no stack traceback is printed.
When using the various PyRun_Interactive* functions, it seems like the interpreter is
catching the SystemExit exception and calling the C exit() function before returning
to our code, so we don't have a chance to do handle it from the caller of
PyRun_Interactive* function.
[1] https://docs.python.org/3/c-api/veryhigh.html#c.PyRun_InteractiveLoopFlags
[2] https://docs.python.org/3/library/exceptions.html#SystemExit
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-19 17:20 ` Simon Marchi
@ 2020-01-19 19:13 ` Eli Zaretskii
2020-01-21 19:53 ` Tom Tromey
0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2020-01-19 19:13 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches
> Cc: gdb-patches@sourceware.org
> From: Simon Marchi <simark@simark.ca>
> Date: Sun, 19 Jan 2020 12:01:33 -0500
>
> When using the various PyRun_Interactive* functions, it seems like the interpreter is
> catching the SystemExit exception and calling the C exit() function before returning
> to our code, so we don't have a chance to do handle it from the caller of
> PyRun_Interactive* function.
Too bad.
The context of these questions is the Emacs's front-end for GDB, which
uses MI, and that adds even more complexities to this already quite
complex situation, in particular because Emacs until now didn't know
(nor care) whether the user invoked Python or Guile interpreter.
Thanks.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-19 19:13 ` Eli Zaretskii
@ 2020-01-21 19:53 ` Tom Tromey
2020-01-21 19:57 ` Eli Zaretskii
0 siblings, 1 reply; 15+ messages in thread
From: Tom Tromey @ 2020-01-21 19:53 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Simon Marchi, gdb-patches
>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:
Eli> The context of these questions is the Emacs's front-end for GDB, which
Eli> uses MI, and that adds even more complexities to this already quite
Eli> complex situation, in particular because Emacs until now didn't know
Eli> (nor care) whether the user invoked Python or Guile interpreter.
I wonder if Emacs could use the "new-ui" command to create a separate MI
channel just for its use.
Tom
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-21 19:53 ` Tom Tromey
@ 2020-01-21 19:57 ` Eli Zaretskii
0 siblings, 0 replies; 15+ messages in thread
From: Eli Zaretskii @ 2020-01-21 19:57 UTC (permalink / raw)
To: Tom Tromey; +Cc: simark, gdb-patches
> From: Tom Tromey <tom@tromey.com>
> Cc: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
> Date: Tue, 21 Jan 2020 12:51:03 -0700
>
> >>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:
>
> Eli> The context of these questions is the Emacs's front-end for GDB, which
> Eli> uses MI, and that adds even more complexities to this already quite
> Eli> complex situation, in particular because Emacs until now didn't know
> Eli> (nor care) whether the user invoked Python or Guile interpreter.
>
> I wonder if Emacs could use the "new-ui" command to create a separate MI
> channel just for its use.
It would only work on some platforms, but in any case I don't think I
understand how that would help with the issue of exiting the Python
interpreter. What did I miss?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-18 14:46 Discrepancy between Python and Guile wrt exiting the interpreter Eli Zaretskii
2020-01-19 16:11 ` Simon Marchi
@ 2020-01-23 17:21 ` Pedro Alves
2020-01-23 17:37 ` Simon Marchi
2020-01-23 18:20 ` Eli Zaretskii
1 sibling, 2 replies; 15+ messages in thread
From: Pedro Alves @ 2020-01-23 17:21 UTC (permalink / raw)
To: Eli Zaretskii, gdb-patches
On 1/18/20 11:07 AM, Eli Zaretskii wrote:
> If you invoke the Guile interpreter from GDB:
>
> (gdb) gr
>
> then typing ,q followed by Enter exits the Guile interpreter back to
> GDB. However, if the Python interpreter is started:
>
> (gdb) pi
>
> then typing quit() and Enter exits GDB, not just the Python
> interpreter. Why do these two interpreters behave differently in this
> context? Is there some other Python command to exit the interpreter?
> (I know about Ctrl-D, but I'm asking about commands.)
>
Note that these commands are not direct equivalents. The guile equivalent
to "pi" which is short for "python" would be "guile", or "gu", and with
that command you get the same behavior as "pi", in the sense that ",q"
doesn't bail you out, you have to type some command and finish with
either Ctrl-D or Ctrl-C to abort.
"gr" is an alias for "guile-repl", and with that command, it's the Guile
repl that implements the ",q", not GDB. With the "python" and "guile"
commands, it's GDB that implements the secondary prompt handling and
command line reading (the ">", etc.). Compare guile_repl_command and
guile_command.
I think that calling quit() in the Python interpreter ends up being the
the equivalent of doing:
(gdb) guile
> (primitive-exit)
Ctrl-D
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-23 17:21 ` Pedro Alves
@ 2020-01-23 17:37 ` Simon Marchi
2020-01-23 17:50 ` Pedro Alves
2020-01-23 18:20 ` Eli Zaretskii
1 sibling, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2020-01-23 17:37 UTC (permalink / raw)
To: Pedro Alves, Eli Zaretskii, gdb-patches
On 2020-01-23 12:10 p.m., Pedro Alves wrote:
> Note that these commands are not direct equivalents. The guile equivalent
> to "pi" which is short for "python" would be "guile", or "gu", and with
> that command you get the same behavior as "pi", in the sense that ",q"
> doesn't bail you out, you have to type some command and finish with
> either Ctrl-D or Ctrl-C to abort.
"pi" is not a shorthand for "python", it's a shorthand for "python-interactive",
which spawns a Python interpreter prompt/repl. So I think that and "guile-repl"
are quite similar. It's just that the Python repl doesn't provide a convenient
way (other than ctrl-D) so say "exit the repl".
Simon
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-23 17:50 ` Pedro Alves
@ 2020-01-23 17:39 ` Pedro Alves
2020-01-24 10:26 ` Eli Zaretskii
0 siblings, 1 reply; 15+ messages in thread
From: Pedro Alves @ 2020-01-23 17:39 UTC (permalink / raw)
To: Simon Marchi, Eli Zaretskii, gdb-patches
On 1/23/20 5:32 PM, Pedro Alves wrote:
> On 1/23/20 5:21 PM, Simon Marchi wrote:
>> On 2020-01-23 12:10 p.m., Pedro Alves wrote:
>>> Note that these commands are not direct equivalents. The guile equivalent
>>> to "pi" which is short for "python" would be "guile", or "gu", and with
>>> that command you get the same behavior as "pi", in the sense that ",q"
>>> doesn't bail you out, you have to type some command and finish with
>>> either Ctrl-D or Ctrl-C to abort.
>>
>> "pi" is not a shorthand for "python", it's a shorthand for "python-interactive",
>> which spawns a Python interpreter prompt/repl. So I think that and "guile-repl"
>> are quite similar. It's just that the Python repl doesn't provide a convenient
>> way (other than ctrl-D) so say "exit the repl".
>
> Indeed, I got confused with that.
And I have to add -- wow, "quit()" exiting gdb is really nasty
in that case. It's even suggested if you try "quit" without
parens:
>>> quit
Use quit() or Ctrl-D (i.e. EOF) to exit
Clearly the embedded use case wasn't considered here. I think
this should be reported to Python upstream.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-23 17:37 ` Simon Marchi
@ 2020-01-23 17:50 ` Pedro Alves
2020-01-23 17:39 ` Pedro Alves
0 siblings, 1 reply; 15+ messages in thread
From: Pedro Alves @ 2020-01-23 17:50 UTC (permalink / raw)
To: Simon Marchi, Eli Zaretskii, gdb-patches
On 1/23/20 5:21 PM, Simon Marchi wrote:
> On 2020-01-23 12:10 p.m., Pedro Alves wrote:
>> Note that these commands are not direct equivalents. The guile equivalent
>> to "pi" which is short for "python" would be "guile", or "gu", and with
>> that command you get the same behavior as "pi", in the sense that ",q"
>> doesn't bail you out, you have to type some command and finish with
>> either Ctrl-D or Ctrl-C to abort.
>
> "pi" is not a shorthand for "python", it's a shorthand for "python-interactive",
> which spawns a Python interpreter prompt/repl. So I think that and "guile-repl"
> are quite similar. It's just that the Python repl doesn't provide a convenient
> way (other than ctrl-D) so say "exit the repl".
Indeed, I got confused with that.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-23 17:21 ` Pedro Alves
2020-01-23 17:37 ` Simon Marchi
@ 2020-01-23 18:20 ` Eli Zaretskii
2020-01-23 18:30 ` Pedro Alves
1 sibling, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2020-01-23 18:20 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
> From: Pedro Alves <palves@redhat.com>
> Date: Thu, 23 Jan 2020 17:10:10 +0000
>
> Note that these commands are not direct equivalents. The guile equivalent
> to "pi" which is short for "python" would be "guile", or "gu", and with
> that command you get the same behavior as "pi", in the sense that ",q"
> doesn't bail you out, you have to type some command and finish with
> either Ctrl-D or Ctrl-C to abort.
>
> "gr" is an alias for "guile-repl", and with that command, it's the Guile
> repl that implements the ",q", not GDB. With the "python" and "guile"
> commands, it's GDB that implements the secondary prompt handling and
> command line reading (the ">", etc.). Compare guile_repl_command and
> guile_command.
Thanks.
Is there a Python equivalent of "gr"?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-23 18:20 ` Eli Zaretskii
@ 2020-01-23 18:30 ` Pedro Alves
2020-01-23 18:46 ` Eli Zaretskii
0 siblings, 1 reply; 15+ messages in thread
From: Pedro Alves @ 2020-01-23 18:30 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
On 1/23/20 6:17 PM, Eli Zaretskii wrote:
> Is there a Python equivalent of "gr"?
I was wrong -- see follow up messages.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-23 18:30 ` Pedro Alves
@ 2020-01-23 18:46 ` Eli Zaretskii
0 siblings, 0 replies; 15+ messages in thread
From: Eli Zaretskii @ 2020-01-23 18:46 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
> Cc: gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Thu, 23 Jan 2020 18:21:24 +0000
>
> I was wrong -- see follow up messages.
Yes, sorry. I'm used to believing you blindly in these matters ;-)
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Discrepancy between Python and Guile wrt exiting the interpreter
2020-01-23 17:39 ` Pedro Alves
@ 2020-01-24 10:26 ` Eli Zaretskii
0 siblings, 0 replies; 15+ messages in thread
From: Eli Zaretskii @ 2020-01-24 10:26 UTC (permalink / raw)
To: Pedro Alves; +Cc: simark, gdb-patches
> From: Pedro Alves <palves@redhat.com>
> Date: Thu, 23 Jan 2020 17:36:28 +0000
>
> And I have to add -- wow, "quit()" exiting gdb is really nasty
> in that case. It's even suggested if you try "quit" without
> parens:
>
> >>> quit
> Use quit() or Ctrl-D (i.e. EOF) to exit
>
> Clearly the embedded use case wasn't considered here. I think
> this should be reported to Python upstream.
How does one do that?
And btw, while I have your attention: an Emacs user reported a problem
whereby he couldn't find a way of exiting the "pi" invoked from the
GDB session started by "M-x gdb" (which uses GDB/MI) in Emacs. See
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=39140. I proposed a
solution to that in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=39140#8,
which seems to work for me, but that user said it didn't help on his
system. Does that patch work for others here, or is it the GNU/Linux
system I used to test (fencepost.gnu.org, btw) which is the odd one
out?
P.S. As you might guess, that bug report was the trigger for my
question here.
Thanks.
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2020-01-24 7:00 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-18 14:46 Discrepancy between Python and Guile wrt exiting the interpreter Eli Zaretskii
2020-01-19 16:11 ` Simon Marchi
2020-01-19 16:42 ` Eli Zaretskii
2020-01-19 17:20 ` Simon Marchi
2020-01-19 19:13 ` Eli Zaretskii
2020-01-21 19:53 ` Tom Tromey
2020-01-21 19:57 ` Eli Zaretskii
2020-01-23 17:21 ` Pedro Alves
2020-01-23 17:37 ` Simon Marchi
2020-01-23 17:50 ` Pedro Alves
2020-01-23 17:39 ` Pedro Alves
2020-01-24 10:26 ` Eli Zaretskii
2020-01-23 18:20 ` Eli Zaretskii
2020-01-23 18:30 ` Pedro Alves
2020-01-23 18:46 ` Eli Zaretskii
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox