[pushed,gdb/testsuite] Fix gdb.python/py-inferior.exp with -fsanitize=thread

Message ID 20241007084514.20244-1-tdevries@suse.de
State Committed
Headers
Series [pushed,gdb/testsuite] Fix gdb.python/py-inferior.exp with -fsanitize=thread |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 warning Patch is already merged
linaro-tcwg-bot/tcwg_gdb_build--master-arm warning Patch is already merged

Commit Message

Tom de Vries Oct. 7, 2024, 8:45 a.m. UTC
  With a gdb build with -fsanitize=thread, and test-case
gdb.python/py-inferior.exp I run into:
...
(gdb) python gdb.selected_inferior().read_memory (0, 0xffffffffffffffff)^M
ERROR: ThreadSanitizer: requested allocation size 0xffffffffffffffff exceeds \
  maximum supported size of 0x10000000000^M
...

There's already a workaround for this using ASAN_OPTIONS, and apparently the
same is needed for TSAN_OPTIONS.

Add the allocator_may_return_null=1 workaround also in TSAN_OPTIONS.

Likewise in gdb.dap/memory.exp.

Tested on x86_64-linux.
---
 gdb/testsuite/gdb.dap/memory.exp         | 3 ++-
 gdb/testsuite/gdb.python/py-inferior.exp | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)


base-commit: d396fcc9d17af551e8bc8543a7676694527893e4
  

Comments

Tom Tromey Oct. 7, 2024, 5:03 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> There's already a workaround for this using ASAN_OPTIONS, and apparently the
Tom> same is needed for TSAN_OPTIONS.

Tom> Add the allocator_may_return_null=1 workaround also in TSAN_OPTIONS.

Seems reasonable to me.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdb/testsuite/gdb.dap/memory.exp b/gdb/testsuite/gdb.dap/memory.exp
index 7082706e11c..c4e4fb3238b 100644
--- a/gdb/testsuite/gdb.dap/memory.exp
+++ b/gdb/testsuite/gdb.dap/memory.exp
@@ -25,11 +25,12 @@  if {[build_executable ${testfile}.exp $testfile] == -1} {
     return
 }
 
-save_vars { env(ASAN_OPTIONS) } {
+save_vars { env(ASAN_OPTIONS) env(TSAN_OPTIONS) } {
     # The request readMemory with count 18446744073709551615 triggers address
     # sanitizer.  Suppress the error, leaving us with just this warning:
     #   WARNING: AddressSanitizer failed to allocate 0xffffffffffffffff bytes
     set_sanitizer ASAN_OPTIONS allocator_may_return_null 1
+    set_sanitizer TSAN_OPTIONS allocator_may_return_null 1
 
     if {[dap_initialize] == ""} {
 	return
diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index ee30390e29f..58475bded0f 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -27,12 +27,13 @@  if { [gdb_compile_pthreads ${srcdir}/${subdir}/${srcfile} ${binfile} executable
 }
 
 # Start with a fresh gdb.
-save_vars { env(ASAN_OPTIONS) } {
+save_vars { env(ASAN_OPTIONS) env(TSAN_OPTIONS) } {
     # The call to gdb.selected_inferior().read_memory (0, 0xffffffffffffffff)
     # triggers address sanitizer.  Suppress the error, leaving us with just
     # this warning:
     #   WARNING: AddressSanitizer failed to allocate 0xffffffffffffffff bytes
     set_sanitizer ASAN_OPTIONS allocator_may_return_null 1
+    set_sanitizer TSAN_OPTIONS allocator_may_return_null 1
 
     clean_restart ${testfile}
 }