From patchwork Sat Jan 11 18:10:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 37305 Received: (qmail 15243 invoked by alias); 11 Jan 2020 18:11:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 15154 invoked by uid 89); 11 Jan 2020 18:11:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=7, 6, 51891 X-HELO: mailsec113.isp.belgacom.be Received: from mailsec113.isp.belgacom.be (HELO mailsec113.isp.belgacom.be) (195.238.20.109) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 11 Jan 2020 18:11:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1578766274; x=1610302274; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c3VA3PBp/S4LuDw2QbHZbeHKEXg20zFJr7dsEDyJS78=; b=ZJC4cETtCbwkPSoQDak7Ry/Rs5q62vfxrz7zrBMiPzzg8JBXTreNBiGM VbGefjzMZ/9jxQpBoQ1f0nk/uWDMJA==; IronPort-SDR: w/IcRWGYbc1J12miMQN9Kz6/FMdZRK83opNQ3kEJ/zZUW4aCuNhYOMt2NNSbvT95Tk6gOSkF4q NtKygTb6baRHz4KYOUqy13e58YVcqHhkfVrNOq8zXXtX5kJgs/5zuagyMjP69QIA9TEQQDpxwP dfDGtv/t9cKcWLRBi0ZGxYDKPeUSJLrUUtorzWp5VzSJnQ0WtDHo4FTUprpNHI6kF0AKQ9RJ4y ugMu8oTvp7kVT2K0jXRa21MLGI/0LraJqXGPaPityIA4bqzX8dPSohLRJEPqPvR4uIgc0SfLpx WHQ= Received: from 156.47-242-81.adsl-dyn.isp.belgacom.be (HELO md.home) ([81.242.47.156]) by relay.skynet.be with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Jan 2020 19:10:47 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFAv2 2/3] Test 'set exec-file-mismatch ask|warn|off'. Date: Sat, 11 Jan 2020 19:10:40 +0100 Message-Id: <20200111181041.7163-3-philippe.waroquiers@skynet.be> In-Reply-To: <20200111181041.7163-1-philippe.waroquiers@skynet.be> References: <20200111181041.7163-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes Modify gdb.base/attach.exp to test the behaviour of the option exec-file-mismatch. Note that this test can also be run using/ make check RUNTESTFLAGS="--target_board=native-extended-gdbserver" TESTS=gdb.base/attach.exp to test the behaviour of attaching to running program using a gdb server. Note: when running the test with a gdbserver, the tests in test_command_line_attach_run fail because the command "run" is not supported. I tried to extend the condition if ![isnative] then { unsupported "commandline attach run test" return 0 } but unclear to me how to best do that. The below trials all failed to work properly: if { ![isnative] || [target_is_gdbserver] } then { if { ![isnative] || [use_gdb_stub] } then { if { ![isnative] || [is_remote target] } then { => could never obtain a condition that was true with gdbserver. Some more test changes Some more test changes --- gdb/testsuite/gdb.base/attach.c | 1 + gdb/testsuite/gdb.base/attach.exp | 84 ++++++++++++++++++++++++++++++- gdb/testsuite/gdb.base/attach2.c | 1 + 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/gdb.base/attach.c b/gdb/testsuite/gdb.base/attach.c index 91b180c73c..2e87f9b710 100644 --- a/gdb/testsuite/gdb.base/attach.c +++ b/gdb/testsuite/gdb.base/attach.c @@ -7,6 +7,7 @@ #include #include +int bidule = 0; int should_exit = 0; int main () diff --git a/gdb/testsuite/gdb.base/attach.exp b/gdb/testsuite/gdb.base/attach.exp index 52a8995a30..5a1d7a8473 100644 --- a/gdb/testsuite/gdb.base/attach.exp +++ b/gdb/testsuite/gdb.base/attach.exp @@ -474,7 +474,12 @@ proc test_command_line_attach_run {} { global gdb_prompt global binfile - if ![isnative] then { + # Skip test if we cannot attach on the command line and use the run command. + # ??? Unclear what condition to use to return here when using gdbserver. + # ??? None of the below works. + # ![isnative] || [target_is_gdbserver] + # ![isnative] || [use_gdb_stub] + if { ![isnative] || [is_remote target] } then { unsupported "commandline attach run test" return 0 } @@ -513,14 +518,91 @@ proc test_command_line_attach_run {} { } } + +# This is a test of 'set exec-file-mismatch' handling. + +proc_with_prefix do_attach_exec_mismatch_handling_tests {} { + global gdb_prompt + global binfile + global binfile2 + + clean_restart $binfile + + # Start two programs that can be attached to. + # The first program contains a 'int bidule' variable, the second a 'float bidule'. + + set test_spawn_id [spawn_wait_for_attach $binfile] + set testpid [spawn_id_get_pid $test_spawn_id] + set test_spawn_id2 [spawn_wait_for_attach $binfile2] + set testpid2 [spawn_id_get_pid $test_spawn_id2] + + + # Test with the default value of 'set exec-file-mismatch load". + set test "mismatch load" + gdb_test "attach $testpid" "Attaching to program.*" "$test attach1" + # Verify that we can "see" the variable "bidule" in the + # program, and that it is an integer. + gdb_test "ptype bidule" " = int" "$test after attach1, bidule is int" + # Detach the process. + gdb_test "detach" "Detaching from program: .* detached\\\]" "$test detach1" + gdb_test_multiple "attach $testpid2" "$test attach2" { + -re "Attaching to program.*exec-file-mismatch handling is currently \"ask\".*Load new symbol table from .*attach2\".*\(y or n\)" { + pass "$test attach2" + } + } + gdb_test "y" "Reading symbols from .*attach2.*" "$test load attach2" + # Verify that we can "see" the variable "bidule" in the + # program, and that it is a float. + gdb_test "ptype bidule" " = float" "$test after attach2 and load, bidule is float" + # Detach the process. + gdb_test "detach" "Detaching from program: .* detached\\\]" "$test detach attach2" + + + # Test with 'set exec-file-mismatch warn". + set test "mismatch warn" + gdb_test_no_output "set exec-file-mismatch warn" + gdb_test_multiple "attach $testpid" "$test attach" { + -re "Attaching to program.*exec-file-mismatch handling is currently \"warn\".*$gdb_prompt" { + pass "$test attach" + } + } + # Verify that we still (wrongly) "see" the variable "bidule" as a float, + # as we have not loaded the correct exec-file. + gdb_test "ptype bidule" " = float" "$test after attach and warn, bidule is float" + # Detach the process. + gdb_test "detach" "Detaching from program: .* detached\\\]" "$test detach attach" + + + # Same test but with 'set exec-file-mismatch off". + set test "mismatch off" + gdb_test_no_output "set exec-file-mismatch off" + gdb_test_multiple "attach $testpid" "$test attach" { + -re "Attaching to program.*$gdb_prompt" { + pass "$test attach" + } + } + # Verify that we still (wrongly) "see" the variable "bidule" as a float, + # as we have not warned the user and not loaded the correct exec-file + gdb_test "ptype bidule" " = float" "$test after attach and warn, bidule is float" + # Detach the process. + gdb_test "detach" "Detaching from program: .* detached\\\]" "$test detach attach" + + + # Don't leave a process around + kill_wait_spawned_process $test_spawn_id + kill_wait_spawned_process $test_spawn_id2 +} + do_attach_tests do_attach_failure_tests do_call_attach_tests +do_attach_exec_mismatch_handling_tests # Test "gdb --pid" do_command_attach_tests + test_command_line_attach_run return 0 diff --git a/gdb/testsuite/gdb.base/attach2.c b/gdb/testsuite/gdb.base/attach2.c index a78037ed38..44d37258fb 100644 --- a/gdb/testsuite/gdb.base/attach2.c +++ b/gdb/testsuite/gdb.base/attach2.c @@ -8,6 +8,7 @@ #include #include +float bidule = 0.0; int should_exit = 0; int main ()