This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v2 2/4] Unregister the last inferior from the event loop
- From: "Maciej W. Rozycki" <macro at wdc dot com>
- To: Pedro Alves <palves at redhat dot com>, gdb-patches at sourceware dot org
- Cc: Jim Wilson <jimw at sifive dot com>
- Date: Wed, 6 Nov 2019 20:51:59 +0000 (GMT)
- Subject: [PATCH v2 2/4] Unregister the last inferior from the event loop
- Ironport-sdr: OAXO0zbsfd1QeuJq09F9VKKx7qQoW8ugDWEaQR6DE7BoxUyyVbMKAtTnuYVdGrkcVfw74rAfXR oMNSilhQnm3jEC1jBCACixrEhahi9Spo2WyXrdqOPF/0DJrCnS86K5v3Yy2FtIuCISSkccvW2p e6WckaKfb0Sdr1WH+lhDqbFDtQOq84hzm3Z65H3A1E7nUWsKRyuS9eeXx69rfirRCie7C1Fzzl 5lgdvHVlNgJQRPQWuobh2VV6/26gDHVotk5h+YA8Uye5OPPOuDQXg3MuEsx6sIQr7IYaWcBvlu 3R8=
- Ironport-sdr: npTv+cRn8AUMa78eHfl0XVaKkr5748AhrEOj9rPy24WoOqyobMUnUnLouKsPYcwBX5/BBtFdP9 w9S2OtFH7Jl6Ej0owXwOhlfHqIWndUzuyuP7oM/Qc2PlwXfTZohoWRY90kfEZSSxjlI3tM0hJH vaXBXOBoFapZzO+7VOge7DvUcP5f9r57HXPd4f3rq8cvy2G/93BkdZUtVjKDBhwpYZstDNsilV Mey68vkdaVQWF4j7HGrOHO0sbvg8giLUqVvGXnid5lKqbQG/b7HOdWMMZw4b02N6J2NOqsw4nP oD6mQLVibHqvHJ31aT5482bc
- Ironport-sdr: MQq3HiUdHTgsQLdQ8tI5nzArIxkLOE/Aws9m+ZqkG3wIdPZqJ2IxhIK4UzBIXwokXhixmc9RS1 OPtFPXc78rWYYIaKKbTJg0jKubhLAzXcwP9CSWnW4lLGQiIX9ja122zv9JtNKTCJu1Roo6t2Ba cXBqfK28eAOJxZm6RftEqGzJJuUoj/hD0m8lcMt6SfrzGf/F/opIrWgwmloDXZxlcaXeYSCsfV Dmf3vxPdrTGmHgtfbBQ88iHsfjSGdEYFqmt4Lv27cA4DV5a3o4GUue8FU17/DP7wT+ibTalwF8 X4c=
- References: <alpine.LFD.2.21.1911051509370.13542@redsun52.ssa.fujisawa.hgst.com>
- Wdcironportexception: Internal
Fix an issue with GDB starting to effectively busy-loop (though still
accepting and interpreting commands) using the full processing power
available when a remote connection is forcibly terminated while the
target is running.
This was observed with RISC-V/Linux `gdbserver' modified to hang after a
successful acceptance of a `vCont' packet, as follows:
(gdb) set debug infrun 2
(gdb) set debug remote 2
(gdb) continue
Continuing.
infrun: clear_proceed_status_thread (Thread 22854.22854)
infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT)
Sending packet: $Z0,10430,2#0c...Packet received:
Packet Z0 (software-breakpoint) is NOT supported
Sending packet: $m10430,2#c3...Packet received: 8147
Sending packet: $X10430,0:#e6...Packet received: OK
binary downloading supported by target
Sending packet: $X10430,2:\002\220#7a...Packet received: OK
Sending packet: $m15555607b8,2#07...Packet received: 8280
Sending packet: $X15555607b8,2:\002\220#be...Packet received: OK
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 22854.22854] at 0x1555556ef0
Sending packet: $QPassSignals:e;10;14;17;1a;1b;1c;21;24;25;2c;4c;97;#0a...Packet received: OK
Sending packet: $vCont?#49...Packet received: vCont;c;C;t
Packet vCont (verbose-resume) is supported
Sending packet: $vCont;c:p5946.-1#b6...infrun: infrun_async(1)
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun: -1.0.0 [process -1],
infrun: status->kind = ignore
infrun: handle_inferior_event status->kind = ignore
infrun: prepare_to_wait
^Cremote_pass_ctrlc called
remote_interrupt called
^Cremote_pass_ctrlc called
infrun: infrun_async(0)
The target is not responding to interrupt requests.
Stop debugging it? (y or n) y
infrun: infrun_async(1)
Disconnected from target.
(gdb) infrun: target_wait (-1.0.0, status) =
infrun: -1.0.0 [process -1],
infrun: status->kind = ignore
infrun: handle_inferior_event status->kind = ignore
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun: -1.0.0 [process -1],
infrun: status->kind = ignore
infrun: handle_inferior_event status->kind = ignore
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun: -1.0.0 [process -1],
infrun: status->kind = ignore
infrun: handle_inferior_event status->kind = ignore
infrun: prepare_to_wait
[...]
This is because `remote_target::resume' enables the asynchronous event
loop, as indicated by the first `infrun: infrun_async(1)' record above,
and then the confirmation dialogue temporarily disables it and then
reenables, as indicated by the second `infrun: infrun_async(1)' record
above. The problem with that approach is that the reenabling also marks
the handler for the `infrun_async_inferior_event_token' event ready,
even though it was not before the temporary disabling, by calling
`mark_async_event_handler' on it, and that triggers the infinite loop as
there's no inferior anymore and consequently no event waiting that would
stop it.
Unregister the `infrun_async_inferior_event_token' event from the loop
then when the last inferior has gone. The final part of the session now
looks like:
^Cremote_pass_ctrlc called
remote_interrupt called
^Cremote_pass_ctrlc called
infrun: infrun_async(0)
The target is not responding to interrupt requests.
Stop debugging it? (y or n) y
infrun: infrun_async(1)
infrun: infrun_async(0)
Disconnected from target.
(gdb)
and the looping does not happen anymore.
gdb/
* target.c (target_stack::unpush): Unregister the last inferior
from the event loop.
---
New change in v2.
---
gdb/target.c | 6 ++++++
1 file changed, 6 insertions(+)
gdb-unpush-target-async.diff
Index: binutils-gdb/gdb/target.c
===================================================================
--- binutils-gdb.orig/gdb/target.c
+++ binutils-gdb/gdb/target.c
@@ -634,6 +634,12 @@ target_stack::unpush (target_ops *t)
implementation don't end up in T anymore. */
target_close (t);
+ /* If this was the last inferior, then make sure it's been unregistered
+ from the event loop so that we don't get distracted by spurious
+ inferior output. */
+ if (!have_live_inferiors ())
+ infrun_async (0);
+
return true;
}