From patchwork Fri Apr 19 15:13:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 88746 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77720384772F for ; Fri, 19 Apr 2024 15:15:42 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by sourceware.org (Postfix) with ESMTPS id 0FEBB3846426 for ; Fri, 19 Apr 2024 15:14:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0FEBB3846426 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0FEBB3846426 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713539655; cv=none; b=I2I33F1taTw9RkMrC/JB3/6LUT0feUIwGLt7Lv66LD8vOVI/q9KgA8xYINsev05CtuiOBmQDgoyGMjSEmWufXb65G1J13oYqPSklnxPXtvMg1WdS+f3uVZ3n0G3xC0Z8tyqAhJTjehctkt8BgXZMfQg5a+1Tjpg2s1rWjwx4Ork= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713539655; c=relaxed/simple; bh=+78xNMR8xEVw7PVaFg7eMjkX9nvVguIMAoqxEStALbY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=UdInYX9WjIZ2Q65YRkY6vy5OC+0Y+MEwG+eZK5ljT+fVXxL3j6WmUvpn2XpYNE/1bbf0KsU2zZ8zaApz3DRclXGRAvWxtkhLiFRLLd2J47rhz3dFQ1c0tiD48hUecz6ODWUbHjmY0tv9SMVSAnz6a5/1S1k1DToVEuq7F8xady0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-418dde387a3so16673245e9.0 for ; Fri, 19 Apr 2024 08:14:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713539652; x=1714144452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rUJ3tWZez6jS4Uc+wh5CnEeduAqeLLJHb+zOVrD5bow=; b=KzEyycuL5mEK77UJRtZ6Qp6xLfUylAP3pOPbOCMmRX6rOoXkNGWul4eehQ7OgjgpWS NhGrPdafvGo7XJE16W7XW4qANVuTmTq1SLaywKLb02PBqso9bztzW9QpR6qK/b3NdBYl Xqt9QCH8VZKBNVVHciRz8qFGuqNHEutBFAhmlskyBU0IaQVKOGV4AMpC9wHDT5vBBGFA DgjfqG4qzmV0/fYH+iCr7YeW60IMrTgfAJ9EbybYzi37I/cS10EggQ93tXuF92C+ux4w VjpHhYDwm6aZ4FoXw4Az8MzcnU2PNLcgyovAMZLOvo+gKsZlMjFOiIwC6Obiobnv1sdA D7mQ== X-Gm-Message-State: AOJu0YyNC3/foJuuBn0bCRCTZdI0VRft7TPZawIjH834czxL2+g9MT4J 5QscEjhsfCaOBr34I/+Aen2ExiHwY7+9zTny7LTwcVSCj5G5icPmRFrl9kek X-Google-Smtp-Source: AGHT+IEAIkyjEALM8WR5rUOXbw+Tc5H1BxrYuKHVND8tZp0YG1fm3Ke0KztoZFLCIhoHaT8P7wfpwg== X-Received: by 2002:a05:600c:3c9f:b0:418:41b8:4d5c with SMTP id bg31-20020a05600c3c9f00b0041841b84d5cmr1984246wmb.30.1713539651450; Fri, 19 Apr 2024 08:14:11 -0700 (PDT) Received: from localhost ([2001:8a0:f93d:b900:2438:d637:5572:c30a]) by smtp.gmail.com with UTF8SMTPSA id c22-20020a05600c0a5600b00419cff40a01sm417766wmq.8.2024.04.19.08.14.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Apr 2024 08:14:10 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 09/12] gdb_target_is_native -> gdb_protocol_is_native Date: Fri, 19 Apr 2024 16:13:39 +0100 Message-ID: <20240419151342.1592474-10-pedro@palves.net> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240419151342.1592474-1-pedro@palves.net> References: <20240419151342.1592474-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org gdb_is_target_native uses "maint print target-stack", which is unnecessary when checking whether gdb_protocol is empty would do. Checking gdb_protocol is more efficient, and can be done before starting GDB and running to main, unlike gdb_is_target_native. This adds a new gdb_protocol_is_native procedure, and uses it in place of gdb_is_target_native. At first, I thought that we'd end up with a few testcases needing to use gdb_is_target_native still, especially multi-target tests that connect to targets different from the default board target, but no, actually all uses of gdb_is_target_native could be converted. gdb_is_target_native will be eliminated in a following patch. In some spots, we no longer need to defer the check until after starting GDB, so the patch adjusts accordingly. Change-Id: Ia706232dbffac70f9d9740bcb89c609dbee5cee3 --- gdb/testsuite/gdb.base/attach.exp | 13 +++---------- gdb/testsuite/gdb.base/foll-exec-mode.exp | 4 +--- gdb/testsuite/gdb.base/load-command.exp | 11 +++++------ gdb/testsuite/gdb.multi/stop-all-on-exit.exp | 16 ++++++++-------- gdb/testsuite/gdb.python/py-inferior.exp | 2 +- gdb/testsuite/gdb.threads/threads-after-exec.exp | 2 +- gdb/testsuite/lib/gdb.exp | 15 +++++++++++++++ 7 files changed, 34 insertions(+), 29 deletions(-) diff --git a/gdb/testsuite/gdb.base/attach.exp b/gdb/testsuite/gdb.base/attach.exp index 84b2d27f3eb..637f287f59e 100644 --- a/gdb/testsuite/gdb.base/attach.exp +++ b/gdb/testsuite/gdb.base/attach.exp @@ -470,16 +470,9 @@ proc_with_prefix test_command_line_attach_run {} { global gdb_prompt global binfile - # The --pid option is used to attach to a process using the native target. - # Start GDB and run to main just to see what the execution target is, skip - # if it's not the native target. - clean_restart $binfile - - if { ![runto_main] } { - return - } - - if { ![gdb_is_target_native] } { + # The --pid option is used to attach to a process using the native + # target. + if { ![gdb_protocol_is_native] } { unsupported "commandline attach run test" return } diff --git a/gdb/testsuite/gdb.base/foll-exec-mode.exp b/gdb/testsuite/gdb.base/foll-exec-mode.exp index ff92c551bba..65054b530b3 100644 --- a/gdb/testsuite/gdb.base/foll-exec-mode.exp +++ b/gdb/testsuite/gdb.base/foll-exec-mode.exp @@ -109,8 +109,6 @@ proc do_follow_exec_mode_tests { mode cmd infswitch } { return } - set target_is_native [gdb_is_target_native] - # Set the follow-exec mode. # gdb_test_no_output "set follow-exec-mode $mode" @@ -150,7 +148,7 @@ proc do_follow_exec_mode_tests { mode cmd infswitch } { # process target, which was automatically pushed when running, was # automatically unpushed from inferior 1 on exec. Use a # different regexp that verifies the Connection field is empty. - if { $target_is_native } { + if { [gdb_protocol_is_native] } { set expected_re " 1.* +[string_to_regexp $binfile].*\r\n\\* 2.*process.*$testfile2 .*" } else { set expected_re " 1.*null.*$testfile.*\r\n\\* 2.*process.*$testfile2 .*" diff --git a/gdb/testsuite/gdb.base/load-command.exp b/gdb/testsuite/gdb.base/load-command.exp index ce6f9bcb730..2d3656e711a 100644 --- a/gdb/testsuite/gdb.base/load-command.exp +++ b/gdb/testsuite/gdb.base/load-command.exp @@ -17,6 +17,11 @@ standard_testfile +if [gdb_protocol_is_native] { + unsupported "the native target does not support the load command" + return +} + # Disable generation of position independent executable (PIE). Otherwise, we # would have to manually specify an offset to load. @@ -30,12 +35,6 @@ if ![runto_main] { return -1 } -# The native target does not support the load command. -if [gdb_is_target_native] { - unsupported "the native target does not support the load command" - return -} - # Manually change the value of the_variable. gdb_test "print/x the_variable" " = 0x1234" "check initial value of the_variable" gdb_test_no_output "set the_variable = 0x5555" "manually change the_variable" diff --git a/gdb/testsuite/gdb.multi/stop-all-on-exit.exp b/gdb/testsuite/gdb.multi/stop-all-on-exit.exp index f014037106d..1ac5388c0a4 100644 --- a/gdb/testsuite/gdb.multi/stop-all-on-exit.exp +++ b/gdb/testsuite/gdb.multi/stop-all-on-exit.exp @@ -18,6 +18,14 @@ # Test that in all-stop mode with multiple inferiors, GDB stops all # threads upon receiving an exit event from one of the inferiors. +# This is a test specific for a native target, where we use the +# "-exec" argument to "add-inferior" and we explicitly don't do +# "maint set target-non-stop on". +if {![gdb_protocol_is_native]} { + untested "the test is aimed at a native target" + return 0 +} + standard_testfile if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} { @@ -28,14 +36,6 @@ if {![runto_main]} { return -1 } -# This is a test specific for a native target, where we use the -# "-exec" argument to "add-inferior" and we explicitly don't do -# "maint set target-non-stop on". -if {![gdb_is_target_native]} { - untested "the test is aimed at a native target" - return 0 -} - # Add a second inferior that will sleep longer. gdb_test "add-inferior -exec $binfile" "Added inferior 2.*" \ "add the second inferior" diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index e74fbfd050d..ee30390e29f 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -406,7 +406,7 @@ with_test_prefix "selected_inferior" { gdb_test "py print (gdb.selected_inferior().connection.num)" "1" \ "first inferior's connection number, though connection object" # Figure out if inf 1 has a native target. - set inf_1_is_native [gdb_is_target_native] + set inf_1_is_native [gdb_protocol_is_native] set num [add_inferior "-no-connection"] gdb_test "inferior $num" ".*" "switch to inferior $num" diff --git a/gdb/testsuite/gdb.threads/threads-after-exec.exp b/gdb/testsuite/gdb.threads/threads-after-exec.exp index 4dc71dd76fd..32aec6b39db 100644 --- a/gdb/testsuite/gdb.threads/threads-after-exec.exp +++ b/gdb/testsuite/gdb.threads/threads-after-exec.exp @@ -38,7 +38,7 @@ proc do_test { } { # leader detection racy") this isn't always thread 1.1. set cur_thr [get_integer_valueof "\$_thread" 0] - if {[istarget *-*-linux*] && [gdb_is_target_native]} { + if {[istarget *-*-linux*] && [gdb_protocol_is_native]} { # Confirm there's only one LWP in the list as well, and that # it is bound to the existing GDB thread. set inf_pid [get_inferior_pid] diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index ddee928d510..c072a4502b4 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4698,6 +4698,10 @@ proc gdb_is_target_remote_prompt { prompt_regexp } { # Check whether we're testing with the remote or extended-remote # targets. # +# This is meant to be used on testcases that connect to targets +# different from the default board protocol. For most tests, you can +# check whether gdb_protocol is "remote" or "extended-remote" instead. +# # NOTE: GDB must be running BEFORE this procedure is called! proc gdb_is_target_remote { } { @@ -4708,6 +4712,10 @@ proc gdb_is_target_remote { } { # Check whether we're testing with the native target. # +# This is meant to be used on testcases that connect to targets +# different from the default board protocol. For most tests, you can +# check whether gdb_protocol is the empty string instead. +# # NOTE: GDB must be running BEFORE this procedure is called! proc gdb_is_target_native { } { @@ -4716,6 +4724,13 @@ proc gdb_is_target_native { } { return [gdb_is_target_1 "native" ".*native \\(Native process\\).*" "$gdb_prompt $"] } +# Returns true if gdb_protocol is empty, indicating use of the native +# target. + +proc gdb_protocol_is_native { } { + return [expr {[target_info gdb_protocol] == ""}] +} + # Like istarget, but checks a list of targets. proc is_any_target {args} { foreach targ $args {