From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id A88A43858D38 for ; Tue, 21 Jul 2020 07:45:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A88A43858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 49EBDAD4A for ; Tue, 21 Jul 2020 07:45:18 +0000 (UTC) Date: Tue, 21 Jul 2020 09:45:10 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [committed][gdb/testsuite] Don't leak env vars in gdb.debuginfod/fetch_src_and_symbols.exp Message-ID: <20200721074503.GA6936@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_BADIPHTTP, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jul 2020 07:45:14 -0000 Hi, Test-case gdb.debuginfod/fetch_src_and_symbols.exp leaks env vars DEBUGINFOD_URLS, DEBUGINFOD_TIMEOUT and DEBUGINFOD_CACHE_PATH, causing timeouts in subsequent tests. Fix this by using save_vars. Also, fix PATH and DUPLICATE errors. Finally, cleanup whitespace. Committed to trunk. Thanks, - Tom [gdb/testsuite] Don't leak env vars in gdb.debuginfod/fetch_src_and_symbols.exp gdb/testsuite/ChangeLog: 2020-07-21 Tom de Vries * gdb.debuginfod/fetch_src_and_symbols.exp: Use save_vars for env vars. Fix PATH and DUPLICATE errors. Cleanup whitespace. --- .../gdb.debuginfod/fetch_src_and_symbols.exp | 209 ++++++++++++--------- 1 file changed, 120 insertions(+), 89 deletions(-) diff --git a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp index fbab3b1f48..c26893ddf4 100644 --- a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp +++ b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp @@ -31,7 +31,7 @@ if { [which curl] == 0 } { # Skip testing if gdb was not configured with debuginfod if { [string first "with-debuginfod" \ - [eval exec $GDB $INTERNAL_GDBFLAGS --configuration]] == -1 } { + [eval exec $GDB $INTERNAL_GDBFLAGS --configuration]] == -1 } { untested "gdb not configured with debuginfod" return -1 } @@ -58,31 +58,6 @@ if { [gdb_compile "$sourcetmp" "$binfile" executable {debug}] != "" } { return -1 } -setenv DEBUGINFOD_URLS "" -setenv DEBUGINFOD_TIMEOUT 30 -setenv DEBUGINFOD_CACHE_PATH $cache - -# Test that gdb cannot find source without debuginfod -clean_restart $binfile -gdb_test_no_output "set substitute-path $outputdir /dev/null" -gdb_test "list" ".*No such file or directory.*" - -# Strip symbols into separate file and move it so gdb cannot find it without debuginfod -if { [gdb_gnu_strip_debug $binfile ""] != 0 } { - fail "strip debuginfo" - return -1 -} - -set debugdir [standard_output_file "debug"] -set debuginfo [standard_output_file "fetch_src_and_symbols.debug"] - -file mkdir $debugdir -file rename -force $debuginfo $debugdir - -# Test that gdb cannot find symbols without debuginfod -clean_restart $binfile -gdb_test "file" ".*No symbol file.*" - # Write some assembly that just has a .gnu_debugaltlink section. # Copied from testsuite/gdb.dwarf2/dwzbuildid.exp. proc write_just_debugaltlink {filename dwzname buildid} { @@ -118,7 +93,7 @@ proc write_dwarf_file {filename buildid {value 99}} { cu {} { compile_unit {{language @DW_LANG_C}} { - int_label2: base_type { + int_label2: base_type { {name int} {byte_size 4 sdata} {encoding @DW_ATE_signed} @@ -134,82 +109,138 @@ proc write_dwarf_file {filename buildid {value 99}} { } } -set buildid "01234567890abcdef0123456" +proc no_url { } { + global binfile outputdir debugdir -write_just_debugaltlink ${binfile}_has_altlink.S ${binfile}_dwz.o $buildid -write_dwarf_file ${binfile}_dwz.S $buildid + setenv DEBUGINFOD_URLS "" -if {[gdb_compile ${binfile}_has_altlink.S ${binfile}_alt.o object nodebug] != ""} { - fail "compile main with altlink" - return -1 -} + # Test that gdb cannot find source without debuginfod + clean_restart $binfile + gdb_test_no_output "set substitute-path $outputdir /dev/null" \ + "set substitute-path" + gdb_test "list" ".*No such file or directory.*" -if {[gdb_compile ${binfile}_dwz.S ${binfile}_dwz.o object nodebug] != ""} { - fail "compile altlink" - return -1 -} + # Strip symbols into separate file and move it so gdb cannot find it \ + without debuginfod + if { [gdb_gnu_strip_debug $binfile ""] != 0 } { + fail "strip debuginfo" + return -1 + } -file rename -force ${binfile}_dwz.o $debugdir + set debugdir [standard_output_file "debug"] + set debuginfo [standard_output_file "fetch_src_and_symbols.debug"] -# Test that gdb cannot find dwz without debuginfod. -clean_restart -gdb_test "file ${binfile}_alt.o" ".*could not find '.gnu_debugaltlink'.*" + file mkdir $debugdir + file rename -force $debuginfo $debugdir -# Find an unused port -set port 7999 -set found 0 -while { ! $found } { - incr port - if { $port == 65536 } { - fail "no available ports" - return -1 - } - - spawn debuginfod -vvvv -d $db -p $port -F $debugdir - expect { - "started http server on IPv4 IPv6 port=$port" { set found 1 } - "failed to bind to port" { kill_wait_spawned_process $spawn_id } - timeout { - fail "find port timeout" - return -1 + # Test that gdb cannot find symbols without debuginfod + clean_restart $binfile + gdb_test "file" ".*No symbol file.*" + + set buildid "01234567890abcdef0123456" + + write_just_debugaltlink ${binfile}_has_altlink.S ${binfile}_dwz.o \ + $buildid + write_dwarf_file ${binfile}_dwz.S $buildid + + if {[gdb_compile ${binfile}_has_altlink.S ${binfile}_alt.o object \ + nodebug] != ""} { + fail "compile main with altlink" + return -1 } - } -} -set metrics [list "ready 1" \ - "thread_work_total{role=\"traverse\"} 1" \ - "thread_work_pending{role=\"scan\"} 0" \ - "thread_busy{role=\"scan\"} 0"] + if {[gdb_compile ${binfile}_dwz.S ${binfile}_dwz.o object \ + nodebug] != ""} { + fail "compile altlink" + return -1 + } + + file rename -force ${binfile}_dwz.o $debugdir -# Check server metrics to confirm init has completed. -foreach m $metrics { - set timelim 20 - while { $timelim != 0 } { - sleep 0.5 - catch {exec curl -s http://127.0.0.1:$port/metrics} got + # Test that gdb cannot find dwz without debuginfod. + clean_restart + gdb_test "file ${binfile}_alt.o" \ + ".*could not find '.gnu_debugaltlink'.*" \ + "file [file tail ${binfile}_alt.o]" +} + +proc local_url { } { + global binfile outputdir db debugdir + + # Find an unused port + set port 7999 + set found 0 + while { ! $found } { + incr port + if { $port == 65536 } { + fail "no available ports" + return -1 + } - if { [regexp $m $got] } { - break + spawn debuginfod -vvvv -d $db -p $port -F $debugdir + expect { + "started http server on IPv4 IPv6 port=$port" { set found 1 } + "failed to bind to port" { kill_wait_spawned_process $spawn_id } + timeout { + fail "find port timeout" + return -1 + } + } } - incr timelim -1 - } + set metrics [list "ready 1" \ + "thread_work_total{role=\"traverse\"} 1" \ + "thread_work_pending{role=\"scan\"} 0" \ + "thread_busy{role=\"scan\"} 0"] - if { $timelim == 0 } { - fail "server init timeout" - return -1 - } + # Check server metrics to confirm init has completed. + foreach m $metrics { + set timelim 20 + while { $timelim != 0 } { + sleep 0.5 + catch {exec curl -s http://127.0.0.1:$port/metrics} got + + if { [regexp $m $got] } { + break + } + + incr timelim -1 + } + + if { $timelim == 0 } { + fail "server init timeout" + return -1 + } + } + + # Point the client to the server + setenv DEBUGINFOD_URLS http://127.0.0.1:$port + + # gdb should now find the symbol and source files + clean_restart $binfile + gdb_test_no_output "set substitute-path $outputdir /dev/null" \ + "set substitute-path" + gdb_test "br main" "Breakpoint 1 at.*file.*" + gdb_test "l" ".*This program is distributed in the hope.*" + + # gdb should now find the debugaltlink file + clean_restart + gdb_test "file ${binfile}_alt.o" \ + ".*Reading symbols from ${binfile}_alt.o\.\.\.*" \ + "file [file tail ${binfile}_alt.o]" } -# Point the client to the server -setenv DEBUGINFOD_URLS http://127.0.0.1:$port +set envlist \ + [list \ + env(DEBUGINFOD_URLS) \ + env(DEBUGINFOD_TIMEOUT) \ + env(DEBUGINFOD_CACHE_PATH)] -# gdb should now find the symbol and source files -clean_restart $binfile -gdb_test_no_output "set substitute-path $outputdir /dev/null" -gdb_test "br main" "Breakpoint 1 at.*file.*" -gdb_test "l" ".*This program is distributed in the hope.*" +save_vars $envlist { + setenv DEBUGINFOD_TIMEOUT 30 + setenv DEBUGINFOD_CACHE_PATH $cache -# gdb should now find the debugaltlink file -clean_restart -gdb_test "file ${binfile}_alt.o" ".*Reading symbols from ${binfile}_alt.o\.\.\.*" + with_test_prefix no_url no_url + + with_test_prefix local_url local_url +}