From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kJkrKCEouWBoIwAAWB0awg (envelope-from ) for ; Thu, 03 Jun 2021 15:06:09 -0400 Received: by simark.ca (Postfix, from userid 112) id A29E11F163; Thu, 3 Jun 2021 15:06:09 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 786A81E01F for ; Thu, 3 Jun 2021 15:06:08 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 41316382E830 for ; Thu, 3 Jun 2021 19:06:08 +0000 (GMT) Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by sourceware.org (Postfix) with ESMTPS id 73EC4398FC3E for ; Thu, 3 Jun 2021 19:03:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 73EC4398FC3E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f41.google.com with SMTP id n4so6914305wrw.3 for ; Thu, 03 Jun 2021 12:03:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JO9wSoUwBYMVoXwE/8o7RgBG4rgXx3yyWWc6TKM1bgs=; b=Y23KJ+OIsWnWmmRY9XcAxPLXo/qEJer0RzWqilHaMiGxQt6NxjgTFkWUG1CuSuqRoN lermGwSJUU9aiBMgY40oKHjMFDCrIg8eQskLKu5e6Yu+oflUfpTYo92iXRX93aGUGBo0 6qCUYpFe33CVRmz4B8NviGhnPDanQxh7yY/t24/ZLWQxoLI1yPK9vJugxS/RCoeKahnW o+q+b++ilLzOEbtRs1fzLR6Q+5KVhWwajv+aHb0Unqcq85AInwUX8CmyqB/xsBEVo+aR WO70ttNUipofpK/vdPyr4t8q1Gp880WWOY/EE8R5/JaBksDx83ttjj/9tNru5cv82n7b Wh0A== X-Gm-Message-State: AOAM533zFQ3Fjb3r0sehmuTA9mrL1mUxkEF9TsqJHe5sgLaXj0/FALvT GYnLN7fUyVikU4LMkqX6JsZV2irRHMO6OA== X-Google-Smtp-Source: ABdhPJw1toCpdqBanY+QkUV+MzBAiPj4Vkw+OyMKS5Jy+APo67d9yGprKLXklEWaTkFpZj4UK1I9iw== X-Received: by 2002:a5d:6dae:: with SMTP id u14mr541wrs.148.1622746983815; Thu, 03 Jun 2021 12:03:03 -0700 (PDT) Received: from localhost ([2001:8a0:f932:6a00:6b6e:c7b6:c5a7:aac3]) by smtp.gmail.com with ESMTPSA id a11sm4195869wrr.48.2021.06.03.12.03.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Jun 2021 12:03:03 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 08/17] Make inferior/GDB share terminal in run+detach testcases Date: Thu, 3 Jun 2021 20:02:34 +0100 Message-Id: <20210603190243.2609886-9-pedro@palves.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210603190243.2609886-1-pedro@palves.net> References: <20210603190243.2609886-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" A following patch will make GDB put spawned inferiors in their own terminal/session. A consequence of that is that if you do "run", and then "detach", GDB closes the terminal, and the inferior gets a SIGHUP, after being detached, which likely means it'll die. (The referenced patch will make GDB detect the scenario and ask for confirmation before detaching.) To avoid that, testcases that explicitly want to do run/start + detach need to tell GDB to not create a terminal for the inferior. That's what this patch does. gdb/testsuite/ChangeLog: yyyy-mm-dd Pedro Alves * gdb.base/attach-wait-input.exp: Issue "tty /dev/tty" before starting program. * gdb.base/auto-connect-native-target.exp: Likewise. * gdb/testsuite/gdb.base/detach.exp: Issue "tty /dev/tty" before starting program. Use with_test_prefix. * gdb/testsuite/gdb.base/dprintf-detach.exp: Issue "tty /dev/tty" before starting program. * gdb/testsuite/gdb.base/jit-elf.exp: Likewise. * gdb/testsuite/gdb.base/multi-forks.exp: Likewise. * gdb/testsuite/gdb.base/watchpoint-hw-attach.exp: Likewise. * gdb/testsuite/gdb.mi/mi-detach.exp: Likewise. * gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp: Likewise. * gdb.threads/process-dies-while-detaching.exp: Likewise. * gdb.threads/threadapply.exp: Likewise. Change-Id: Ic62bca178295763fb9c47657ee459fe715f7865e --- gdb/testsuite/gdb.base/attach-wait-input.exp | 4 ++++ .../gdb.base/auto-connect-native-target.exp | 3 +++ gdb/testsuite/gdb.base/detach.exp | 19 +++++++++++-------- gdb/testsuite/gdb.base/dprintf-detach.exp | 9 ++++++++- gdb/testsuite/gdb.base/jit-elf.exp | 10 +++++++++- gdb/testsuite/gdb.base/multi-forks.exp | 3 +++ .../gdb.base/watchpoint-hw-attach.exp | 3 +++ gdb/testsuite/gdb.mi/mi-detach.exp | 6 ++++++ .../gdb.multi/watchpoint-multi-exit.exp | 3 +++ .../process-dies-while-detaching.exp | 3 +++ gdb/testsuite/gdb.threads/threadapply.exp | 3 +++ 11 files changed, 56 insertions(+), 10 deletions(-) diff --git a/gdb/testsuite/gdb.base/attach-wait-input.exp b/gdb/testsuite/gdb.base/attach-wait-input.exp index f190af1811a..c16a1e87562 100644 --- a/gdb/testsuite/gdb.base/attach-wait-input.exp +++ b/gdb/testsuite/gdb.base/attach-wait-input.exp @@ -47,6 +47,10 @@ proc start_program {binfile} { clean_restart $binfile + # Let our spawned inferior run in GDB's terminal/session, so that + # we can detach from it. + gdb_test_no_output "tty /dev/tty" + if ![runto setup_done] then { fail "can't run to setup_done" return 0 diff --git a/gdb/testsuite/gdb.base/auto-connect-native-target.exp b/gdb/testsuite/gdb.base/auto-connect-native-target.exp index 10cddc042c5..5baabaab96f 100644 --- a/gdb/testsuite/gdb.base/auto-connect-native-target.exp +++ b/gdb/testsuite/gdb.base/auto-connect-native-target.exp @@ -147,6 +147,9 @@ with_test_prefix "kill" { } with_test_prefix "detach" { + # So we can safely detach after "start". + gdb_test_no_output "tty /dev/tty" + gdb_test "start" "main.*" set test "detach" diff --git a/gdb/testsuite/gdb.base/detach.exp b/gdb/testsuite/gdb.base/detach.exp index e9b198705f5..06938be3be7 100644 --- a/gdb/testsuite/gdb.base/detach.exp +++ b/gdb/testsuite/gdb.base/detach.exp @@ -35,11 +35,13 @@ proc do_detach_tests {} { global binfile global escapedbinfile global subdir - global pass + + # So we can safely detach after "run". + gdb_test_no_output "tty /dev/tty" runto_main - gdb_test_no_output "set should_exit = 1" "set should_exit, $pass" - gdb_test "detach" "Detaching from program: .*$escapedbinfile, .*" "detach, $pass" + gdb_test_no_output "set should_exit = 1" "set should_exit" + gdb_test "detach" "Detaching from program: .*$escapedbinfile, .*" } # Start with a fresh gdb @@ -48,14 +50,15 @@ gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_load ${binfile} -global pass -set pass "one" -do_detach_tests +with_test_prefix "one" { + do_detach_tests +} # Wait a moment and do it again. exec sleep 1 -set pass "two" -do_detach_tests +with_test_prefix "two" { + do_detach_tests +} return 0 diff --git a/gdb/testsuite/gdb.base/dprintf-detach.exp b/gdb/testsuite/gdb.base/dprintf-detach.exp index 1a94d26f84c..261eeed05b6 100644 --- a/gdb/testsuite/gdb.base/dprintf-detach.exp +++ b/gdb/testsuite/gdb.base/dprintf-detach.exp @@ -39,7 +39,14 @@ proc dprintf_detach_test { breakpoint_always_inserted dprintf_style disconnected with_test_prefix "$test_prefix" { # Start with a clean gdb - clean_restart ${binfile} + + global GDBFLAGS + save_vars { GDBFLAGS } { + # Make the inferior run in the same session as GDB, so + # that we can detach from it. + append GDBFLAGS " -ex \"tty /dev/tty\"" + clean_restart $binfile + } gdb_test_no_output "set breakpoint always-inserted ${breakpoint_always_inserted}" gdb_test_no_output "set dprintf-style ${dprintf_style}" diff --git a/gdb/testsuite/gdb.base/jit-elf.exp b/gdb/testsuite/gdb.base/jit-elf.exp index 2018814df7e..f4b4601d357 100644 --- a/gdb/testsuite/gdb.base/jit-elf.exp +++ b/gdb/testsuite/gdb.base/jit-elf.exp @@ -88,7 +88,15 @@ proc one_jit_test {jit_solibs_target match_str reattach} { global test_verbose global main_binfile main_srcfile - clean_restart ${main_binfile} + global GDBFLAGS + save_vars { GDBFLAGS } { + if {$reattach} { + # Let our spawned inferior run in GDB's + # terminal/session, so that we can detach from it. + append GDBFLAGS { -ex "tty /dev/tty"} + } + clean_restart ${main_binfile} + } # This is just to help debugging when things fail if {$test_verbose > 0} { diff --git a/gdb/testsuite/gdb.base/multi-forks.exp b/gdb/testsuite/gdb.base/multi-forks.exp index 154b24c9c42..09fe48322e3 100644 --- a/gdb/testsuite/gdb.base/multi-forks.exp +++ b/gdb/testsuite/gdb.base/multi-forks.exp @@ -139,6 +139,9 @@ foreach mode { "child" "parent" } { clean_restart ${binfile} +# So we can safely detach after "run". +gdb_test_no_output "tty /dev/tty" + runto_main gdb_breakpoint $exit_bp_loc diff --git a/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp b/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp index 270bc6c29af..ddbf1edbdc8 100644 --- a/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp +++ b/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp @@ -32,6 +32,9 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { clean_restart $binfile +# So we can safely detach after "run". +gdb_test_no_output "tty /dev/tty" + if ![runto_main] { untested "can't run to main" return -1 diff --git a/gdb/testsuite/gdb.mi/mi-detach.exp b/gdb/testsuite/gdb.mi/mi-detach.exp index c25a63699cc..a23942f3d9b 100644 --- a/gdb/testsuite/gdb.mi/mi-detach.exp +++ b/gdb/testsuite/gdb.mi/mi-detach.exp @@ -26,6 +26,12 @@ if {[build_executable $testfile.exp $testfile $srcfile {debug}] == -1} { } mi_clean_restart $binfile + +# So we can safely detach after "-exec-run". +mi_gdb_test "302-inferior-tty-set /dev/tty" \ + "302\\\^done" \ + "set tty to /dev/pts/1" + mi_runto_main mi_gdb_test "-target-detach" "=thread-exited,id=\"1\".*=thread-group-exited,id=\"i1\".*" "detach" diff --git a/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp b/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp index 1dff0832255..6d7a55da4f2 100644 --- a/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp +++ b/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp @@ -31,6 +31,9 @@ proc do_test {dispose} { clean_restart $binfile + # So we can safely detach after "run". + gdb_test_no_output "tty /dev/tty" + gdb_test_no_output "set follow-fork child" gdb_test_no_output "set detach-on-fork off" diff --git a/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp b/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp index ac1aad26ec5..f01d4cf0666 100644 --- a/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp +++ b/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp @@ -215,6 +215,7 @@ proc test_detach {multi_process cmd} { global binfile clean_restart ${binfile} + gdb_test_no_output "tty /dev/tty" if ![runto_main] { fail "can't run to main" @@ -240,6 +241,7 @@ proc test_detach_watch {multi_process cmd} { global binfile decimal clean_restart ${binfile} + gdb_test_no_output "tty /dev/tty" if ![runto_main] { fail "can't run to main" @@ -276,6 +278,7 @@ proc test_detach_killed_outside {multi_process cmd} { global binfile clean_restart ${binfile} + gdb_test_no_output "tty /dev/tty" if ![runto_main] { fail "can't run to main" diff --git a/gdb/testsuite/gdb.threads/threadapply.exp b/gdb/testsuite/gdb.threads/threadapply.exp index ebc1cf15ad6..17a02084b09 100644 --- a/gdb/testsuite/gdb.threads/threadapply.exp +++ b/gdb/testsuite/gdb.threads/threadapply.exp @@ -76,6 +76,9 @@ proc thr_apply_detach {thread_set} { clean_restart ${binfile} + # So we can safely detach after "run". + gdb_test_no_output "tty /dev/tty" + if ![runto_main] { fail "can't run to main" return -1 -- 2.26.2