From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 3F3CA3858D37; Thu, 18 Apr 2024 15:00:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F3CA3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1713452451; bh=q8AiiU6OvqoI7lnFGcIvK6FDi2FodaMiSiMtBVCfWz0=; h=From:To:Subject:Date:From; b=uhejS/6oTdKve//m3MnJRUatCnqoYFmMfe4N3jXxp5aojToWuDV84S+kOHonLJFUZ rsPB+d4JjUnHlFUR0k1DMw5QcR+rSI/ia+bDPZ8LwWCTVm1FK4j1Hp7DHEbmmDJIno euQUMY6DdlX47LNn9vwOyO9MdB4wiVUIZcPHAHAg= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/testsuite] Use allocator_may_return_null=1 in two test-cases X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 523e454fab831e07c83a648c5d07370375a1c376 X-Git-Newrev: b0c431de3f04e5e97cff0ec917dd457696efd43e Message-Id: <20240418150051.3F3CA3858D37@sourceware.org> Date: Thu, 18 Apr 2024 15:00:51 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Db0c431de3f04= e5e97cff0ec917dd457696efd43e commit b0c431de3f04e5e97cff0ec917dd457696efd43e Author: Tom de Vries Date: Thu Apr 18 17:01:09 2024 +0200 [gdb/testsuite] Use allocator_may_return_null=3D1 in two test-cases =20 Simon reported [1] that recent commit 06e967dbc9b ("[gdb/python] Throw MemoryError in inferior.read_memory if malloc fails") introduced AddressSanitizer allocation-size-too-big errors in the two test-cases affected by this commit. =20 Fix this by suppressing the error in the two test-cases using allocator_may_return_null=3D1. =20 Tested on aarch64-linux. =20 Approved-By: Tom Tromey =20 [1] https://sourceware.org/pipermail/gdb-patches/2024-April/208171.html Diff: --- gdb/testsuite/gdb.dap/memory.exp | 11 +++++++++-- gdb/testsuite/gdb.python/py-inferior.exp | 10 +++++++++- gdb/testsuite/lib/gdb.exp | 18 +++++++++++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/gdb/testsuite/gdb.dap/memory.exp b/gdb/testsuite/gdb.dap/memor= y.exp index 4e2e361289a..7082706e11c 100644 --- a/gdb/testsuite/gdb.dap/memory.exp +++ b/gdb/testsuite/gdb.dap/memory.exp @@ -25,8 +25,15 @@ if {[build_executable ${testfile}.exp $testfile] =3D=3D = -1} { return } =20 -if {[dap_initialize] =3D=3D ""} { - return +save_vars { env(ASAN_OPTIONS) } { + # The request readMemory with count 18446744073709551615 triggers addr= ess + # sanitizer. Suppress the error, leaving us with just this warning: + # WARNING: AddressSanitizer failed to allocate 0xffffffffffffffff by= tes + set_sanitizer ASAN_OPTIONS allocator_may_return_null 1 + + if {[dap_initialize] =3D=3D ""} { + return + } } =20 set line [gdb_get_line_number "BREAK"] diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.p= ython/py-inferior.exp index 4c19e259159..e74fbfd050d 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -27,7 +27,15 @@ if { [gdb_compile_pthreads ${srcdir}/${subdir}/${srcfile= } ${binfile} executable } =20 # Start with a fresh gdb. -clean_restart ${testfile} +save_vars { env(ASAN_OPTIONS) } { + # The call to gdb.selected_inferior().read_memory (0, 0xffffffffffffff= ff) + # triggers address sanitizer. Suppress the error, leaving us with just + # this warning: + # WARNING: AddressSanitizer failed to allocate 0xffffffffffffffff by= tes + set_sanitizer ASAN_OPTIONS allocator_may_return_null 1 + + clean_restart ${testfile} +} =20 switch [get_endianness] { little { set python_pack_char "<" } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index d48ea37c0cc..ddee928d510 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -45,9 +45,9 @@ proc cond_wrap { cond wrap body } { } } =20 -# Add VAR_ID=3DVAL to ENV_VAR, unless ENV_VAR already contains a VAR_ID se= tting. +# Helper function for set_sanitizer/set_sanitizer_default. =20 -proc set_sanitizer_default { env_var var_id val } { +proc set_sanitizer_1 { env_var var_id val default} { global env =20 if { ![info exists env($env_var) ] @@ -57,7 +57,7 @@ proc set_sanitizer_default { env_var var_id val } { return } =20 - if { [regexp $var_id=3D $env($env_var)] } { + if { $default && [regexp $var_id=3D $env($env_var)] } { # Don't set var_id. It's already set by the user, leave as is. # Note that we could probably get the same result by unconditionally # prepending it, but this way is less likely to cause confusion. @@ -68,6 +68,18 @@ proc set_sanitizer_default { env_var var_id val } { append env($env_var) : $var_id=3D$val } =20 +# Add VAR_ID=3DVAL to ENV_VAR. + +proc set_sanitizer { env_var var_id val } { + set_sanitizer_1 $env_var $var_id $val 0 +} + +# Add VAR_ID=3DVAL to ENV_VAR, unless ENV_VAR already contains a VAR_ID se= tting. + +proc set_sanitizer_default { env_var var_id val } { + set_sanitizer_1 $env_var $var_id $val 1 +} + set_sanitizer_default TSAN_OPTIONS suppressions \ $srcdir/../tsan-suppressions.txt