From: Tom de Vries Date: Sat, 4 Jan 2025 09:19:37 +0000 (+0100) Subject: [gdb/cli] Warn about forced return from signal trampoline X-Git-Tag: binutils-2_44~270 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9e2d0e2f5369bdd483973171ce436062b866d2dc;p=thirdparty%2Fbinutils-gdb.git [gdb/cli] Warn about forced return from signal trampoline The Linaro CI reported a regression on arm-linux in test-case gdb.base/sigstep.exp following commit 7b46460a619 ("[gdb/symtab] Apply workaround for PR gas/31115 a bit more") [1]: ... (gdb) return^M Make __default_sa_restorer return now? (y or n) n^M Not confirmed^M (gdb) FAIL: $exp: return from handleri: \ leave signal trampoline (got interactive prompt) ... After installing package glibc-debuginfo and adding --with-separate-debug-dir to the configure flags, I managed to reproduce the FAIL. The regression seems to be a progression in the sense that the function name for the signal trampoline is found. After reading up on the signal trampoline [2] and the return command [3], my understanding is that forced returning from the signal trampoline is potentially unsafe, given that for instance the process signal mask won't be restored. Fix this by: - rather than using the name, using "signal trampoline" in the query, and - adding a warning about returning from a signal trampoline, giving us: ... (gdb) return^M warning: Returning from signal trampoline does not fully restore pre-signal \ state, such as process signal mask.^M Make signal trampoline return now? (y or n) y^M 87 dummy = 0; dummy = 0; while (!done);^M (gdb) PASS: $exp: return from handleri: leave signal trampoline (in main) ... Tested on x86_64-linux. Reviewed-by: Thiago Jung Bauermann [1] https://linaro.atlassian.net/browse/GNU-1459 [2] https://man7.org/linux/man-pages/man2/sigreturn.2.html [3] https://sourceware.org/gdb/current/onlinedocs/gdb.html/Returning.html --- diff --git a/gdb/stack.c b/gdb/stack.c index 4a3e7e4ff00..9785a94b858 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -2776,7 +2776,14 @@ return_command (const char *retval_exp, int from_tty) { int confirmed; - if (thisfun == NULL) + if (get_frame_type (thisframe) == SIGTRAMP_FRAME) + { + warning (_("Returning from signal trampoline does not fully restore" + " pre-signal state, such as process signal mask.")); + confirmed = query (_("%sMake signal trampoline return now? "), + query_prefix.c_str ()); + } + else if (thisfun == NULL) confirmed = query (_("%sMake selected stack frame return now? "), query_prefix.c_str ()); else diff --git a/gdb/testsuite/gdb.base/sigstep.exp b/gdb/testsuite/gdb.base/sigstep.exp index 315d89d97c5..d08a34ed0b2 100644 --- a/gdb/testsuite/gdb.base/sigstep.exp +++ b/gdb/testsuite/gdb.base/sigstep.exp @@ -259,7 +259,7 @@ proc advancei { cmd } { -re "return .*${gdb_prompt} $" { fail "$test (stepped)" } - -re "Make .*frame return now.*y or n. $" { + -re "Make signal trampoline return now.*y or n. $" { send_gdb "y\n" exp_continue -continue_timer }