1 # Copyright (C) 2024-2025 Free Software Foundation, Inc. 2 3 # This program is free software; you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation; either version 3 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 require !gdb_protocol_is_remote 17 standard_testfile 18 19 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] == -1} { 20 return -1 21 } 22 23 set command "$binfile" 24 set res [remote_spawn host $command] 25 if { ![gdb_assert { ![expr {$res < 0 || $res == ""}] } "spawn inferior"] } { 26 return 27 } 28 29 # The spawn id of the test inferior. 30 set test_spawn_id $res 31 32 # Wait for the spawned program to loop. 33 set test "wait for inferior to loop" 34 gdb_expect { 35 -re "looping\r\n" { 36 pass $test 37 } 38 eof { 39 fail "$test (eof)" 40 return 41 } 42 timeout { 43 fail "$test (timeout)" 44 return 45 } 46 } 47 48 # The test case uses a very simple notification not to get caught by attach on 49 # exiting the function. 50 51 set test "spawn gstack" 52 set pid [spawn_id_get_pid $test_spawn_id] 53 set gstack_cmd [findfile $base_dir/../../gdb/gstack] 54 set command "sh -c GDB=$GDB\\ GDBARGS=-data-directory\\\\\\ $GDB_DATA_DIRECTORY\\ $gstack_cmd\\ $pid\\;echo\\ GSTACK-END" 55 set res [remote_spawn host $command] 56 if { ![gdb_assert { ![expr {$res < 0 || $res == ""}] } $test] } { 57 return 58 } 59 60 set test "got backtrace" 61 set saw_backtrace false 62 set no_awk false 63 set location_re ${srcfile}:${decimal} 64 65 gdb_test_multiple "" $test { 66 -i "$res" -re "#0 +(0x\[0-9a-f\]+ in )?main \(\).*$location_re.*\r\nGSTACK-END\r\n\$" { 67 set saw_backtrace true 68 pass $test 69 exp_continue 70 } 71 72 -i "$res" "could not find usable awk interpreter" { 73 set no_awk true 74 exp_continue 75 } 76 77 eof { 78 set result [wait -i $res] 79 verbose $result 80 81 gdb_assert { [lindex $result 2] == 0 } "gstack exits with no error" 82 gdb_assert { [lindex $result 3] == 0 } "gstack's exit status is 0" 83 84 remote_close host 85 } 86 } 87 if {$no_awk} { 88 unsupported "no awk interpreter found" 89 } elseif {!$saw_backtrace} { 90 fail $test 91 } 92 93 # Kill the test inferior. 94 kill_wait_spawned_process $test_spawn_id 95