aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.threads
diff options
context:
space:
mode:
authorVladimir Prus <vladimir@codesourcery.com>2008-01-23 11:26:29 +0000
committerVladimir Prus <vladimir@codesourcery.com>2008-01-23 11:26:29 +0000
commit93815fbfa5134025806e16f0897efc8424bf4586 (patch)
tree8c633b007b8b7fbc6d0363b951aec6670e65c7d8 /gdb/testsuite/gdb.threads
parent73f4030dfa279eb7afc5a6c93a752aefbdb0de35 (diff)
downloadgdb-93815fbfa5134025806e16f0897efc8424bf4586.zip
gdb-93815fbfa5134025806e16f0897efc8424bf4586.tar.gz
gdb-93815fbfa5134025806e16f0897efc8424bf4586.tar.bz2
Inform about new thread in a single place.
* thread.c (add_thread_silent): Renamed from add_thread. (print_thread_events): New variable definition. (show_print_thread_events): New function. (_initialize_thread): Add "set print thread-events" and "show print thread-events" commands. (add_thread): Announce new thread. * gdbthread.h (add_thread_silent): Declare. (print_thread_events): New variable declaration. * inf-ttrace.c (inf_ttrace_wait): Don't inform about new thread, as add_thread is always called too, and will take care of that. * infrun.c (handle_inferior_event): Likewise. * procfs.c (procfs_wait): Likewise. * remote.c (remote_currthread): Likewise. * sol-thread.c (sol_thread_wait): Likewise. * win32-nat.c (get_win32_debug_event): Likewise. * linux-thread-db.c (attach_thread): Likewise. Remove the verbose parameter. (check_event): Make detach_thread be verbose only if print_thread_events is set. * linux-nat.c (lin_lwp_attach_lwp): Don't inform about new thread. This is called only from linux-thread-db.c:attach_thread, which will take care. Remove the verbose parameter. * linux-nat.h (lin_lwp_attach_lwp): Adjust prototype.
Diffstat (limited to 'gdb/testsuite/gdb.threads')
-rw-r--r--gdb/testsuite/gdb.threads/thread_events.c55
-rw-r--r--gdb/testsuite/gdb.threads/thread_events.exp155
2 files changed, 210 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.threads/thread_events.c b/gdb/testsuite/gdb.threads/thread_events.c
new file mode 100644
index 0000000..9b7edcd
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/thread_events.c
@@ -0,0 +1,55 @@
+/* Copyright (C) 2007 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/>.
+
+ This file was written by Chris Demetriou (cgd@google.com). */
+
+/* Simple test to trigger thread events (thread start, thread exit). */
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static void *
+threadfunc (void *arg)
+{
+ printf ("in threadfunc\n");
+ return NULL;
+}
+
+static void
+after_join_func (void)
+{
+ printf ("finished\n");
+}
+
+int main (int argc, char *argv[])
+{
+ pthread_t thread;
+
+ if (pthread_create (&thread, NULL, threadfunc, NULL) != 0)
+ {
+ printf ("pthread_create failed\n");
+ exit (1);
+ }
+
+ if (pthread_join (thread, NULL) != 0)
+ {
+ printf ("pthread_join failed\n");
+ exit (1);
+ }
+
+ after_join_func ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.threads/thread_events.exp b/gdb/testsuite/gdb.threads/thread_events.exp
new file mode 100644
index 0000000..bd39b78
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/thread_events.exp
@@ -0,0 +1,155 @@
+# Copyright (C) 2007 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/>.
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+# This file was written by Chris Demetriou (cgd@google.com).
+# It tests printing of thread event (start, exit) information, and
+# disabling of those messages.
+#
+# Note: the format of thread event messages (and also whether or not
+# messages are printed and can be disabled) is dependent on the target
+# thread support code.
+
+# This test has only been verified with Linux targets, and would need
+# to be generalized to support other targets
+if ![istarget *-*-linux*] then {
+ return
+}
+
+# When using gdbserver, even on Linux, we don't get notifications
+# about new threads. This is expected, so don't test for that.
+if [is_remote target] then {
+ return
+}
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+set testfile "thread_events"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
+ return -1
+}
+
+proc gdb_test_thread_start {messages_enabled command pattern message} {
+ global gdb_prompt
+
+ if { $messages_enabled } {
+ set events_expected 1
+ } else {
+ set events_expected 0
+ }
+ set events_seen 0
+
+ return [gdb_test_multiple $command $message {
+ -re "\\\[New Thread \[^\]\]*\\\]\r\n" {
+ incr events_seen;
+ exp_continue;
+ }
+ -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
+ if { $events_seen != $events_expected } {
+ fail "$message (saw $events_seen, expected $events_expected)"
+ } else {
+ pass "$message"
+ }
+ }
+ }]
+}
+
+proc gdb_test_thread_exit {messages_enabled command pattern message} {
+ global gdb_prompt
+
+ if { $messages_enabled } {
+ set events_expected 1
+ } else {
+ set events_expected 0
+ }
+ set events_seen 0
+
+ return [gdb_test_multiple $command $message {
+ -re "\\\[Thread \[^\]\]* exited\\\]\r\n" {
+ incr events_seen
+ exp_continue;
+ }
+ -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
+ if { $events_seen != $events_expected } {
+ fail "$message (saw $events_seen, expected $events_expected)"
+ } else {
+ pass "$message"
+ }
+ }
+ }]
+}
+
+proc test_thread_messages {enabled} {
+ global srcdir subdir binfile srcfile
+
+ if { $enabled } {
+ set enabled_string "with messages enabled"
+ } else {
+ set enabled_string "with messages disabled"
+ }
+
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load ${binfile}
+
+ if { $enabled } {
+ gdb_test "set print thread-events on"
+ } else {
+ gdb_test "set print thread-events off"
+ }
+
+ # The initial thread may log a 'New Thread' message, but we don't
+ # check for it.
+ if ![runto_main] then {
+ fail "Can't run to main $enabled_string"
+ return 1
+ }
+
+ gdb_test "break threadfunc" \
+ "Breakpoint.*at.* file .*$srcfile, line.*" \
+ "breakpoint at threadfunc $enabled_string"
+ gdb_test "break after_join_func" \
+ "Breakpoint.*at.* file .*$srcfile, line.*" \
+ "breakpoint at after_join_func $enabled_string"
+
+ # continue to threadfunc breakpoint. A thread will start.
+ # Expect to see a thread start message, if messages are enabled.
+ gdb_test_thread_start $enabled "continue" \
+ ".*Breakpoint .*,.*threadfunc.*at.*$srcfile:.*" \
+ "continue to threadfunc $enabled_string"
+
+ # continue to after_join_func breakpoint. A thread will exit.
+ # Expect to see a thread exit message, if messages are enabled.
+ gdb_test_thread_exit $enabled "continue" \
+ ".*Breakpoint .*,.*after_join_func.*at.*$srcfile:.*" \
+ "continue to after_join_func $enabled_string"
+
+ delete_breakpoints
+
+ gdb_exit
+}
+
+test_thread_messages 0
+test_thread_messages 1