From: Tom de Vries Date: Tue, 24 Sep 2024 14:45:27 +0000 (+0200) Subject: [gdb] Handle SIGTERM in run_events X-Git-Tag: gdb-16-branchpoint~819 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6896412cde41009ad2c9e7dc49640696ee963b68;p=thirdparty%2Fbinutils-gdb.git [gdb] Handle SIGTERM in run_events While reviewing "catch (...)" uses I came across: ... for (auto &item : local) { try { item (); } catch (...) { /* Ignore exceptions in the callback. */ } } ... This means that when an item throws a gdb_exception_forced_quit, the exception is ignored and following items are executed. Fix this by handling gdb_exception_forced_quit explicity, and immediately rethrowing it. I wondered about ^C, and couldn't decide whether current behaviour is ok, so I left this alone, but I made the issue explicit in the source code. As for the "catch (...)", I think that it should let a non-gdb_exception propagate, so I've narrowed it to "catch (const gdb_exception &)". My rationale for this is as follows. There seem to be a few ways that "catch (...)" is allowed in gdb: - clean-up and rethrow (basically the SCOPE_EXIT pattern) - catch and handle an exception from a call into an external c++ library Since we're dealing with neither of those here, we remove the "catch (...)". Tested on aarch64-linux. Approved-By: Tom Tromey --- diff --git a/gdb/run-on-main-thread.c b/gdb/run-on-main-thread.c index e30dabaff03..a6213d4d85e 100644 --- a/gdb/run-on-main-thread.c +++ b/gdb/run-on-main-thread.c @@ -74,7 +74,20 @@ run_events (int error, gdb_client_data client_data) { item (); } - catch (...) + catch (const gdb_exception_forced_quit &e) + { + /* GDB is terminating, so: + - make sure this is propagated, and + - no need to keep running things, so propagate immediately. */ + throw; + } + catch (const gdb_exception_quit &e) + { + /* Should cancelation of a runnable event cancel the execution of + the following one? The answer is not clear, so keep doing what + we've done sofar: ignore this exception. */ + } + catch (const gdb_exception &) { /* Ignore exceptions in the callback. */ }