From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id 9AE61384AB4D; Fri, 26 Apr 2024 20:24:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9AE61384AB4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1714163061; bh=W2vpoxCZjnbou7OMgyesy/BvW76iaPNc3coF4Likx48=; h=From:To:Subject:Date:From; b=SLZ50BsGdYYPmX5lRx5VkqHo0FoBUZJVtEB6oNFFcuFnKaNg4j3Vwb+wlM7cpAMLK S0+PfRmrHjJrnrp3DR6V/P5Ke9oS8/VEWZR8d6o0NnndJ8CspfsmxP4uuY0+2BPS+7 pyL4eWJ1+1KVAllePZTbmgtqwcBszMN3o8cBYu2I= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb_is_target_native -> gdb_protocol_is_native X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: ef27d39dd2c2e7b6af70884895e6d751872ae305 X-Git-Newrev: c7a2ee649115c78a7722fddccb5e27dbd1478a5c Message-Id: <20240426202421.9AE61384AB4D@sourceware.org> Date: Fri, 26 Apr 2024 20:24:21 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc7a2ee649115= c78a7722fddccb5e27dbd1478a5c commit c7a2ee649115c78a7722fddccb5e27dbd1478a5c Author: Pedro Alves Date: Wed Apr 17 19:59:01 2024 +0100 gdb_is_target_native -> gdb_protocol_is_native =20 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. =20 This adds a new gdb_protocol_is_native procedure, and uses it in place of gdb_is_target_native. =20 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. =20 In some spots, we no longer need to defer the check until after starting GDB, so the patch adjusts accordingly. =20 Change-Id: Ia706232dbffac70f9d9740bcb89c609dbee5cee3 Approved-By: Tom Tromey Diff: --- 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/att= ach.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 =20 - # The --pid option is used to attach to a process using the native tar= get. - # 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 } =20 - 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.*pr= ocess.*$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.ba= se/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 @@ =20 standard_testfile =20 +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. =20 @@ -30,12 +35,6 @@ if ![runto_main] { return -1 } =20 -# 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" " =3D 0x1234" "check initial value of the_= variable" gdb_test_no_output "set the_variable =3D 0x5555" "manually change the_vari= able" diff --git a/gdb/testsuite/gdb.multi/stop-all-on-exit.exp b/gdb/testsuite/g= db.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. =20 +# 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 =20 if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} { @@ -28,14 +36,6 @@ if {![runto_main]} { return -1 } =20 -# 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.p= ython/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] =20 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/testsui= te/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] =20 - 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 1e26937c0dc..069fec5f3a8 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4754,6 +4754,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! =20 proc gdb_is_target_remote { } { @@ -4764,6 +4768,10 @@ proc gdb_is_target_remote { } { =20 # 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! =20 proc gdb_is_target_native { } { @@ -4772,6 +4780,13 @@ proc gdb_is_target_native { } { return [gdb_is_target_1 "native" ".*native \\(Native process\\).*" "$g= db_prompt $"] } =20 +# Returns true if gdb_protocol is empty, indicating use of the native +# target. + +proc gdb_protocol_is_native { } { + return [expr {[target_info gdb_protocol] =3D=3D ""}] +} + # Like istarget, but checks a list of targets. proc is_any_target {args} { foreach targ $args {