]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/cli] Warn about forced return from signal trampoline
authorTom de Vries <tdevries@suse.de>
Sat, 4 Jan 2025 09:19:37 +0000 (10:19 +0100)
committerTom de Vries <tdevries@suse.de>
Sat, 4 Jan 2025 09:19:37 +0000 (10:19 +0100)
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 <thiago.bauermann@linaro.org>
[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

gdb/stack.c
gdb/testsuite/gdb.base/sigstep.exp

index 4a3e7e4ff006e7ac22d13a7fdbfa918cfe0d3b31..9785a94b858d093376a77aaca4448815bed7b4a4 100644 (file)
@@ -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
index 315d89d97c54009dc43ed036584aa8c1a33ab662..d08a34ed0b2c542f0d524dc08aec2e12716a8db9 100644 (file)
@@ -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
            }