1# Copyright (C) 2007-2020 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# This file was written by Chris Demetriou (cgd@google.com). 17# It tests printing of thread event (start, exit) information, and 18# disabling of those messages. 19# 20# Note: the format of thread event messages (and also whether or not 21# messages are printed and can be disabled) is dependent on the target 22# thread support code. 23 24# This test has only been verified with Linux targets, and would need 25# to be generalized to support other targets 26if ![istarget *-*-linux*] then { 27 return 28} 29 30# When using the RSP, we don't get notifications about new threads. 31# This is expected, so don't test for that. 32if {[target_info gdb_protocol] == "remote" 33 || [target_info gdb_protocol] == "extended-remote"} { 34 return 35} 36 37 38standard_testfile 39 40if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } { 41 return -1 42} 43 44proc gdb_test_thread_start {messages_enabled command pattern message} { 45 global gdb_prompt 46 47 if { $messages_enabled } { 48 set events_expected 1 49 } else { 50 set events_expected 0 51 } 52 set events_seen 0 53 54 return [gdb_test_multiple $command $message { 55 -re "\\\[New Thread \[^\]\]*\\\]\r\n" { 56 incr events_seen 57 exp_continue 58 } 59 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" { 60 if { $events_seen != $events_expected } { 61 fail "$message (saw $events_seen, expected $events_expected)" 62 } else { 63 pass "$message" 64 } 65 } 66 }] 67} 68 69proc gdb_test_thread_exit {messages_enabled command pattern message} { 70 global gdb_prompt 71 72 if { $messages_enabled } { 73 set events_expected 1 74 } else { 75 set events_expected 0 76 } 77 set events_seen 0 78 79 return [gdb_test_multiple $command $message { 80 -re "\\\[Thread \[^\]\]* exited\\\]\r\n" { 81 incr events_seen 82 exp_continue 83 } 84 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" { 85 if { $events_seen != $events_expected } { 86 fail "$message (saw $events_seen, expected $events_expected)" 87 } else { 88 pass "$message" 89 } 90 } 91 }] 92} 93 94proc test_thread_messages {enabled} { 95 global srcdir subdir binfile srcfile 96 97 if { $enabled } { 98 set enabled_string "with messages enabled" 99 } else { 100 set enabled_string "with messages disabled" 101 } 102 103 gdb_start 104 gdb_reinitialize_dir $srcdir/$subdir 105 gdb_load ${binfile} 106 107 if { $enabled } { 108 gdb_test "set print thread-events on" 109 } else { 110 gdb_test "set print thread-events off" 111 } 112 113 # The initial thread may log a 'New Thread' message, but we don't 114 # check for it. 115 if ![runto_main] then { 116 fail "can't run to main $enabled_string" 117 return 1 118 } 119 120 gdb_test "break threadfunc" \ 121 "Breakpoint.*at.* file .*$srcfile, line.*" \ 122 "breakpoint at threadfunc $enabled_string" 123 gdb_test "break after_join_func" \ 124 "Breakpoint.*at.* file .*$srcfile, line.*" \ 125 "breakpoint at after_join_func $enabled_string" 126 127 # continue to threadfunc breakpoint. A thread will start. 128 # Expect to see a thread start message, if messages are enabled. 129 gdb_test_thread_start $enabled "continue" \ 130 ".*Breakpoint .*,.*threadfunc.*at.*$srcfile:.*" \ 131 "continue to threadfunc $enabled_string" 132 133 # continue to after_join_func breakpoint. A thread will exit. 134 # Expect to see a thread exit message, if messages are enabled. 135 gdb_test_thread_exit $enabled "continue" \ 136 ".*Breakpoint .*,.*after_join_func.*at.*$srcfile:.*" \ 137 "continue to after_join_func $enabled_string" 138 139 delete_breakpoints 140 141 gdb_exit 142} 143 144test_thread_messages 0 145test_thread_messages 1 146