gdb/testsuite: Introduce and use gdb_spawn_attach_cmdline

Following a7e6a19e87 "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.

This helper starts GDB and adds the "--pid=$PID" argument.

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.

To maintain a behavior similat to what gdb.base/attach.exp used to do,
gdb_spawn_attach_cmdline keeps the -quiet flag.

Tested on x86_64-gnu-linux

Change-Id: I1fdcdb71c86d9c5d34bb28fc86fac68bcec37358
This commit is contained in:
Lancelot SIX 2022-04-14 10:41:48 +01:00
parent 4206d69e96
commit b750766ac9
2 changed files with 49 additions and 8 deletions

View File

@ -467,14 +467,9 @@ proc_with_prefix do_command_attach_tests {} {
gdb_exit
set res [gdb_spawn_with_cmdline_opts \
"-quiet -iex \"set height 0\" -iex \"set width 0\" --pid=$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
# Get rid of the process
kill_wait_spawned_process $test_spawn_id

View File

@ -5186,6 +5186,52 @@ proc gdb_attach { testpid args } {
return 0
}
# Start gdb with "--pid $TESTPID" on the command line and wait for the prompt.
# 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=$testpid"]
if { $res != 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.