From 5c177fed07e31081fa88f2dc5ca000363fbb3ad9 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Fri, 3 Sep 2021 15:13:14 +0200 Subject: [PATCH] [gdb/testsuite] Add untested case in selftest_setup When building gdb with "-Wall -O2 -g -flto=auto", I run into: ... FAIL: gdb.gdb/python-helper.exp: breakpoint in captured_main \ (got interactive prompt) FAIL: gdb.gdb/python-helper.exp: run until breakpoint at captured_main WARNING: Couldn't test self ... and similar in gdb.gdb/selftest.exp. The first FAIL in more detail: ... (gdb) break captured_main^M Function "captured_main" not defined.^M Make breakpoint pending on future shared library load? (y or [n]) n^M (gdb) FAIL: gdb.gdb/python-helper.exp: breakpoint in captured_main \ (got interactive prompt) ... The problem is that lto has optimized away the captured_main function and consequently the selftests dependent on that cannot run. Fix this by: - using gdb_breakpoint to detect failure to set the breakpoint - handling the failure to set a breakpoint by calling untested - not emitting the warning if we've already got untested such that we have: ... (gdb) UNTESTED: gdb.gdb/python-helper.exp: Cannot set breakpoint at \ captured_main, skipping testcase. ... gdb/testsuite/ChangeLog: 2021-09-03 Tom de Vries * lib/selftest-support.exp: Emit untested when not being able to set breakpoint. --- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/lib/selftest-support.exp | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 276dd18edd..42aae6b30a 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2021-09-03 Tom de Vries + + * lib/selftest-support.exp: Emit untested when not being able to set + breakpoint. + 2021-09-01 Tom de Vries PR testsuite/28298 diff --git a/gdb/testsuite/lib/selftest-support.exp b/gdb/testsuite/lib/selftest-support.exp index 4b96bf4f5f..325ea997d5 100644 --- a/gdb/testsuite/lib/selftest-support.exp +++ b/gdb/testsuite/lib/selftest-support.exp @@ -40,6 +40,8 @@ proc find_gdb { arg } { # EXECUTABLE is the gdb to use. # FUNCTION is the function to break in, either captured_main # or captured_command_loop. +# Return 0 in case of success, -1 in case of failure, and -2 in case of +# skipping the test-case. proc selftest_setup { executable function } { global gdb_prompt @@ -73,14 +75,14 @@ proc selftest_setup { executable function } { if { $gdb_file_cmd_debug_info != "debug" } then { untested "no debug information, skipping testcase." - return -1 + return -2 } - # Set a breakpoint at main. Allow more than one location, as - # workaround for PR26096 - "gdb sets breakpoint at cold clone". - gdb_test "break $function" \ - "Breakpoint.*at.* (file.*, line|locations).*" \ - "breakpoint in $function" + # Set a breakpoint at $function. + if { [gdb_breakpoint $function "no-message"] != 1 } { + untested "Cannot set breakpoint at $function, skipping testcase." + return -2 + } # run yourself # It may take a very long time for the inferior gdb to start (lynx), @@ -165,7 +167,7 @@ proc do_self_tests {function body} { gdb_exit catch "remote_file host delete $file" - if {$result < 0} then { + if {$result == -1} then { warning "Couldn't test self" } } -- 2.34.1