]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb] Fix tsan warning: signal handler spoils errno
authorTom de Vries <tdevries@suse.de>
Fri, 13 Dec 2024 17:36:34 +0000 (18:36 +0100)
committerTom de Vries <tdevries@suse.de>
Fri, 13 Dec 2024 17:36:34 +0000 (18:36 +0100)
commit2e792a78e495be6df4b8c0a3e41332c2f6dcd911
tree96610bcb63f974158805a0a887d7802cdd58725e
parent7336a8977d81b7b8c00f2e8ccb8a084afb33b19a
[gdb] Fix tsan warning: signal handler spoils errno

When building gdb with -fsanitize=thread and running test-case
gdb.base/bg-exec-sigint-bp-cond.exp, I run into:
...
==================^M
WARNING: ThreadSanitizer: signal handler spoils errno (pid=25422)^M
    #0 handler_wrapper gdb/posix-hdep.c:66^M
    #1 decltype ({parm#2}({parm#3}...)) gdb::handle_eintr<>() \
         gdbsupport/eintr.h:67^M
    #2 gdb::waitpid(int, int*, int) gdbsupport/eintr.h:78^M
    #3 run_under_shell gdb/cli/cli-cmds.c:926^M
...

Likewise in:
- tui_sigwinch_handler with test-case gdb.python/tui-window.exp, and
- handle_sighup with test-case gdb.base/quit-live.exp.

Fix this by saving the original errno, and restoring it before returning [1].

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
[1] https://www.gnu.org/software/libc/manual/html_node/POSIX-Safety-Concepts.html
gdb/event-top.c
gdb/posix-hdep.c
gdb/tui/tui-win.c