[gdb/testsuite] Set TSAN_OPTIONS by default to history_size=7

Message ID 20230731071547.1140-1-tdevries@suse.de
State Committed
Headers
Series [gdb/testsuite] Set TSAN_OPTIONS by default to history_size=7 |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed

Commit Message

Tom de Vries July 31, 2023, 7:15 a.m. UTC
  I build gdb with -fsanitize=thread and ran the testsuite, and into the case
that a race is detected, but we see the full stack trace only for one of the
two accesses, and the other one is showing "failed to restore the stack".

Try to prevent this by setting ThreadSanitizer flag history_size [1] to the
maximum (7) by default, as suggested here [2].

Tested on x86_64-linux.

[1] https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags
[2] https://groups.google.com/g/thread-sanitizer/c/VzSWE7UxhIE
---
 gdb/testsuite/lib/gdb.exp | 8 ++++++++
 1 file changed, 8 insertions(+)


base-commit: 8e72ee1de8df0789c0ac593467d34387af388c83
  

Comments

Tom Tromey July 31, 2023, 4:37 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> I build gdb with -fsanitize=thread and ran the testsuite, and into the case
Tom> that a race is detected, but we see the full stack trace only for one of the
Tom> two accesses, and the other one is showing "failed to restore the stack".

Tom> Try to prevent this by setting ThreadSanitizer flag history_size [1] to the
Tom> maximum (7) by default, as suggested here [2].

Tom> Tested on x86_64-linux.

Seems totally fine for me.  Thank you for this & for trying out
ThreadSanitizer.

Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 66c04a2efe2..c42f5308752 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -71,6 +71,14 @@  proc set_sanitizer_default { env_var var_id val } {
 set_sanitizer_default TSAN_OPTIONS suppressions \
     $srcdir/../tsan-suppressions.txt
 
+# When using ThreadSanitizer we may run into the case that a race is detected,
+# but we see the full stack trace only for one of the two accesses, and the
+# other one is showing "failed to restore the stack".
+# Try to prevent this by setting history_size to the maximum (7) by default.
+# See also the ThreadSanitizer docs (
+# https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags ).
+set_sanitizer_default TSAN_OPTIONS history_size 7
+
 # If GDB is built with ASAN (and because there are leaks), it will output a
 # leak report when exiting as well as exit with a non-zero (failure) status.
 # This can affect tests that are sensitive to what GDB prints on stderr or its