Discussion:
[Bug python/23718] New: Exceptions in gdb.execute("cont") etc. cause a hang with stdin disabled
graham.markall at embecosm dot com
2018-09-27 09:38:33 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23718

Bug ID: 23718
Summary: Exceptions in gdb.execute("cont") etc. cause a hang
with stdin disabled
Product: gdb
Version: HEAD
Status: NEW
Severity: normal
Priority: P2
Component: python
Assignee: unassigned at sourceware dot org
Reporter: graham.markall at embecosm dot com
Target Milestone: ---

Created attachment 11279
--> https://sourceware.org/bugzilla/attachment.cgi?id=11279&action=edit
Reproducer for hang on exception in Python execute command

When Python gdb.execute() is called, an exception could occur. For example, one
might be connected to gdbserver and run:

gdb.execute('cont')

If during execution of this command the gdbserver dies / disconnects
unexpectedly for some reason, then once the Python code finishes executing, the
GDB prompt does not return, and the debugging session is effectively hung.

The cause of this appears to be that stdin is disabled when executing the
command, and it is never re-enabled. In other scenarios:

1. When running the cont command outside of Python (e.g. at the gdb prompt or
in a sourced list of commands) stdin would be re-enabled if an exception was
thrown because the exception propagates all the way up to the top-level event
loop which is prepared for this eventuality and handles re-enabling stdin.

2. When nothing goes wrong with running the cont command from Python, stdin is
re-enabled somewhere in normal_stop() so there is no issue when the target
doesn't disconnect.

However, when the exception is thrown for the target disconnecting, it is then
converted into a Python exception, which never propagates to the top-level
event loop, and we don't hit normal_stop() either.

The attached reproducer shows the problem. To reproduce (on Linux, at least):

1. In one shell, run `./run_gdbserver.sh`
2. In another, run `./run_gdb.sh`
3. In a third terminal, kill the running gdbserver. GDB should now show the
exception and be hung, with output similar to:

Traceback (most recent call last):
File "gdb_commands.py", line 7, in <module>
do_gdb_stuff()
File "gdb_commands.py", line 5, in do_gdb_stuff
gdb.execute('cont')
gdb.error: Remote connection closed
--
You are receiving this mail because:
You are on the CC list for the bug.
graham.markall at embecosm dot com
2018-09-27 21:17:57 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23718

--- Comment #1 from Graham Markall <graham.markall at embecosm dot com> ---
An attempt to fix this is posted at:
https://sourceware.org/ml/gdb-patches/2018-09/msg00884.html
--
You are receiving this mail because:
You are on the CC list for the bug.
Loading...