| # Copyright 2014-2026 Free Software Foundation, Inc. | |
| # This program is free software; you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation; either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU General Public License | |
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| # Check that some things work (like "info proc" and generating core files) when | |
| # the thread group leader has exited. | |
| standard_testfile | |
| set corefile [standard_output_file ${testfile}.core] | |
| if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != ""} { | |
| return | |
| } | |
| save_vars { GDBFLAGS } { | |
| append GDBFLAGS " -ex \"set non-stop on\"" | |
| clean_restart ${testfile} | |
| } | |
| if {![runto_main]} { | |
| return | |
| } | |
| gdb_test_multiple "info threads" "threads are supported" { | |
| -re ".* main .*\r\n$gdb_prompt $" { | |
| # OK, threads are supported. | |
| } | |
| -re "\r\n$gdb_prompt $" { | |
| unsupported "gdb does not support threads on this target" | |
| return | |
| } | |
| } | |
| gdb_breakpoint ${srcfile}:[gdb_get_line_number "break-here"] | |
| gdb_breakpoint ${srcfile}:[gdb_get_line_number "break-here-second"] | |
| gdb_test -no-prompt-anchor "continue &" "Continuing\\." | |
| # Wait for both workers to stop and the leader to exit. | |
| set num_events 0 | |
| gdb_test_multiple "" "wait for the workers to stop" -lbl { | |
| -re "break-here \\*/|break-here-second \\*/|\\(id 1\\) exited\\]" { | |
| incr num_events | |
| if { $num_events < 3 } { | |
| exp_continue | |
| } | |
| } | |
| } | |
| gdb_assert { $num_events == 3 } "both workers stopped, leader exited" | |
| # Check that "info proc" reads /proc through a thread that is still alive. The | |
| # format is Linux-specific. | |
| if { [istarget "*-*-linux*"] } { | |
| set binfile_re [string_to_regexp $binfile] | |
| gdb_test "info proc" \ | |
| [multi_line \ | |
| "Reading /proc for process $decimal \\(LWP $decimal\\)" \ | |
| "cmdline = '$binfile_re'" \ | |
| "cwd = '.+'" \ | |
| "exe = '$binfile_re'"] | |
| } | |
| gdb_gcore_cmd "$corefile" "save a corefile" | |
| # Do not run "info threads" before "gcore" as it could workaround the bug | |
| # by discarding non-current exited threads. | |
| gdb_test "info threads" \ | |
| {The current thread <Thread ID 1> has terminated[.] See "help thread"[.]} \ | |
| "exited thread is current due to non-stop" | |
| # Verify that "info proc stat" reads the /proc entry for the selected thread. | |
| proc check_info_proc_stat { thread_id } { | |
| # Capture the thread LWP id while switching thread. The message is | |
| # different depending on native vs remote. | |
| set lwp "" | |
| gdb_test_multiple "thread $thread_id" "switch to thread $thread_id" { | |
| -re -wrap "Switching to thread $thread_id \\(Thread \[^\r\n\]*\\(LWP ($::decimal)\\)\\).*" { | |
| set lwp $expect_out(1,string) | |
| pass $gdb_test_name | |
| } | |
| -re -wrap "Switching to thread $thread_id \\(Thread $::decimal\\.($::decimal)\\).*" { | |
| set lwp $expect_out(1,string) | |
| pass $gdb_test_name | |
| } | |
| } | |
| if { $lwp eq "" } { | |
| error "unable to capture LWP id for thread $thread_id" | |
| return | |
| } | |
| gdb_test "info proc stat" \ | |
| [multi_line \ | |
| "Reading /proc for process $::decimal \\(LWP $lwp\\)" \ | |
| "Process: $lwp" \ | |
| ".*"] \ | |
| "info proc stat for thread $thread_id" | |
| } | |
| if { [istarget "*-*-linux*"] } { | |
| check_info_proc_stat 2 | |
| check_info_proc_stat 3 | |
| } | |
| # Load the core back to verify that GDB managed to fill the NT_PRPSINFO note. | |
| # A user-visible consequence of not having this note is that GDB doesn't print | |
| # the "Core was generated by..." line. gdb_core_cmd needs to see this line in | |
| # order to emit a pass, and it emits a fail in all other cases. | |
| clean_restart ${testfile} | |
| gdb_core_cmd $corefile "reload the corefile" |