From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7833) id 01FC83858D1E; Wed, 20 Apr 2022 19:51:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01FC83858D1E Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Lancelot SIX To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/testsuite: Introduce and use gdb_spawn_attach_cmdline X-Act-Checkin: binutils-gdb X-Git-Author: Lancelot SIX X-Git-Refname: refs/heads/master X-Git-Oldrev: 4206d69e96ac401cf2975f37bf4e4d3a3c838313 X-Git-Newrev: b750766ac9652def5307925b8fc5c215fbcef8df Message-Id: <20220420195115.01FC83858D1E@sourceware.org> Date: Wed, 20 Apr 2022 19:51:15 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Apr 2022 19:51:15 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Db750766ac965= 2def5307925b8fc5c215fbcef8df commit b750766ac9652def5307925b8fc5c215fbcef8df Author: Lancelot SIX Date: Thu Apr 14 10:41:48 2022 +0100 gdb/testsuite: Introduce and use gdb_spawn_attach_cmdline =20 Following a7e6a19e87f3d719ea23c65b580a6d9bca4ccab3 "gdb: testsuite: add new gdb_attach to check "attach" command", this commit proposes to introduce the gdb_spawn_attach_cmdline helper and use it in gdb.base/attach.exp. =20 This helper starts GDB and adds the "--pid=3D$PID" argument. =20 Also note that both the original and new implementation use gdb_spawn_with_cmdline_opts, which in the end uses default_gdb_spawn. This makes sure that we use $INTERNAL_GDBFLAGS, which by default already contain "-iex \"set height 0\" -iex \"set width 0\"". To avoid repetition of those arguments, gdb_spawn_attach_cmdline does not repeat those arguments. =20 To maintain a behavior similat to what gdb.base/attach.exp used to do, gdb_spawn_attach_cmdline keeps the -quiet flag. =20 Tested on x86_64-gnu-linux =20 Change-Id: I1fdcdb71c86d9c5d34bb28fc86fac68bcec37358 Diff: --- gdb/testsuite/gdb.base/attach.exp | 11 +++------- gdb/testsuite/lib/gdb.exp | 46 +++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/gdb/testsuite/gdb.base/attach.exp b/gdb/testsuite/gdb.base/att= ach.exp index d01060aba53..7b661e99a1c 100644 --- a/gdb/testsuite/gdb.base/attach.exp +++ b/gdb/testsuite/gdb.base/attach.exp @@ -467,14 +467,9 @@ proc_with_prefix do_command_attach_tests {} { =20 gdb_exit =20 - set res [gdb_spawn_with_cmdline_opts \ - "-quiet -iex \"set height 0\" -iex \"set width 0\" --pid=3D$testpid"] - set test "starting with --pid" - gdb_test_multiple "" $test { - -re "Reading symbols from.*$gdb_prompt $" { - pass "$test" - } - } + # gdb_spawn_attach_cmdline records test results. No need to explicitly + # call pass/fail here. + gdb_spawn_attach_cmdline $testpid =20 # Get rid of the process kill_wait_spawned_process $test_spawn_id diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 10f78736629..0c00d599ca5 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -5186,6 +5186,52 @@ proc gdb_attach { testpid args } { return 0 } =20 +# Start gdb with "--pid $TESTPID" on the command line and wait for the pro= mpt. +# Return 1 if GDB managed to start and attach to the process, 0 otherwise. + +proc_with_prefix gdb_spawn_attach_cmdline { testpid } { + if ![can_spawn_for_attach] { + # The caller should have checked can_spawn_for_attach itself + # before getting here. + error "can't spawn for attach with this target/board" + } + + set test "start gdb with --pid" + set res [gdb_spawn_with_cmdline_opts "-quiet --pid=3D$testpid"] + if { $res !=3D 0 } { + fail $test + return 0 + } + + gdb_test_multiple "" "$test" { + -re -wrap "ptrace: Operation not permitted\\." { + untested "$gdb_test_name (operation not permitted)" + return 0 + } + -re -wrap "ptrace: No such process\\." { + fail "$gdb_test_name (no such process)" + return 0 + } + -re -wrap "Attaching to process $testpid\r\n.*" { + pass $gdb_test_name + } + } + + # Check that we actually attached to a process, in case the + # error message is not caught by the patterns above. + gdb_test_multiple "info thread" "" { + -re -wrap "No threads\\." { + fail "$gdb_test_name (no thread)" + } + -re -wrap "Id.*" { + pass $gdb_test_name + return 1 + } + } + + return 0 +} + # Kill a progress previously started with spawn_wait_for_attach, and # reap its wait status. PROC_SPAWN_ID is the spawn id associated with # the process.