From 30dd3fd4d7e7f9f28992b8bb70b551babcfdfdd0 Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Thu, 5 Sep 2002 14:53:43 +0000 Subject: [PATCH] * mi-pthreads.exp (check_mi_thread_command_set): New tests. (check_mi_and_console_threads): Moved contents dealing with getting MI thread list... (get_mi_threads): ...to here. (check_mi_and_console_threads): New tests. (check_console_thread_commands): New tests. * pthreads.c (done_making_threads): New marker function. (create_thread): New function to create threads. (main): Make several threads using create_thread. Call marker function done_making_threads when done making threads. --- gdb/testsuite/gdb.mi/ChangeLog | 14 +++++ gdb/testsuite/gdb.mi/mi-pthreads.exp | 93 ++++++++++++++++++++++------ gdb/testsuite/gdb.mi/pthreads.c | 25 ++++++-- 3 files changed, 108 insertions(+), 24 deletions(-) diff --git a/gdb/testsuite/gdb.mi/ChangeLog b/gdb/testsuite/gdb.mi/ChangeLog index 77298c8ada3..41ce9d898ba 100644 --- a/gdb/testsuite/gdb.mi/ChangeLog +++ b/gdb/testsuite/gdb.mi/ChangeLog @@ -1,3 +1,17 @@ +2002-09-05 Keith Seitz + + * mi-pthreads.exp (check_mi_thread_command_set): New tests. + (check_mi_and_console_threads): Moved contents dealing with + getting MI thread list... + (get_mi_threads): ...to here. + (check_mi_and_console_threads): New tests. + (check_console_thread_commands): New tests. + * pthreads.c (done_making_threads): New marker function. + (create_thread): New function to create threads. + (main): Make several threads using create_thread. + Call marker function done_making_threads when done making + threads. + 2002-09-04 Keith Seitz * configure.in: Add config header. diff --git a/gdb/testsuite/gdb.mi/mi-pthreads.exp b/gdb/testsuite/gdb.mi/mi-pthreads.exp index 56ca182df50..33b84ca3b0f 100644 --- a/gdb/testsuite/gdb.mi/mi-pthreads.exp +++ b/gdb/testsuite/gdb.mi/mi-pthreads.exp @@ -36,9 +36,7 @@ if {[mi_gdb_start]} { continue } -# Check that MI and the console know of the same threads. -# Appends NAME to all test names. -proc check_mi_and_console_threads {name} { +proc get_mi_thread_list {name} { global expect_out # MI will return a list of thread ids: @@ -46,6 +44,35 @@ proc check_mi_and_console_threads {name} { # -thread-list-ids # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N" # (gdb) + mi_gdb_test "-thread-list-ids" \ + {\^done,thread-ids=\[(thread-id="[0-9]+"(,)*)+\],number-of-threads="[0-9]+"} \ + "-thread_list_ids ($name)" + + set thread_list {} + if {![regexp {thread-ids=\[(thread-id="[0-9]+"(,)?)*\]} $expect_out(buffer) threads]} { + fail "finding threads in MI output ($name)" + } else { + pass "finding threads in MI output ($name)" + + # Make list of console threads + set start [expr {[string first \[ $threads] + 1}] + set end [expr {[string first \] $threads] - 1}] + set threads [string range $threads $start $end] + foreach thread [split $threads ,] { + if {[scan $thread {thread-id="%d"} num]} { + lappend thread_list $num + } + } + } + + return $thread_list +} + +# Check that MI and the console know of the same threads. +# Appends NAME to all test names. +proc check_mi_and_console_threads {name} { + global expect_out + mi_gdb_test "-thread-list-ids" \ {\^done,thread-ids=\[(thread-id="[0-9]+"(,)*)+\],number-of-threads="[0-9]+"} \ "-thread-list-ids ($name)" @@ -109,22 +136,7 @@ proc check_mi_and_console_threads {name} { pass "console and MI have same number of threads ($name)" # Get MI thread list - set mi_thread_list "" - if {![regexp {thread-ids=\[(thread-id="[0-9]+"(,)?)*\]} $mi_result threads]} { - fail "finding threads in MI output ($name)" - } else { - pass "finding threads in MI output ($name)" - - # Make list of console threads - set start [expr {[string first \[ $threads] + 1}] - set end [expr {[string first \] $threads] - 1}] - set threads [string range $threads $start $end] - foreach thread [split $threads ,] { - if {[scan $thread {thread-id="%d"} num]} { - lappend mi_thread_list $num - } - } - } + set mi_thread_list [get_mi_thread_list $name] # Check if MI and console have the same threads set fails 0 @@ -147,6 +159,9 @@ proc check_mi_and_console_threads {name} { } } +# This procedure checks for the bug gdb/669, where the console +# command "info threads" and the MI command "-thread-list-ids" +# return different threads in the system. proc check_for_gdb669_bug {} { mi_run_to_main check_mi_and_console_threads "at main" @@ -157,6 +172,41 @@ proc check_for_gdb669_bug {} { } } +# This procedure tests the various thread commands in MI. +proc check_mi_thread_command_set {} { + + mi_runto done_making_threads + + set thread_list [get_mi_thread_list "in check_mi_thread_command_set"] + + mi_gdb_test "-thread-select" \ + {\^error,msg="mi_cmd_thread_select: USAGE: threadnum."} \ + "check_mi_thread_command_set: -thread-select" + + mi_gdb_test "-thread-select 123456789" \ + {\^error,msg="Thread ID 123456789 not known\."} \ + "check_mi_thread_command_set: -thread-select 123456789" + + foreach thread $thread_list { + mi_gdb_test "-thread-select $thread" \ + "=context-changed,thread=\"$thread\"\r\n\\^done,new-thread-id=\"$thread\",frame={.*},line=\"(-)?\[0-9\]+\",file=\".*\"" \ + "check_mi_thread_command_set: -thread-select $thread" + } +} + +# This procedure checks that the console and MI don't get out +# of sync with each other. +proc check_console_thread_commands {} { + + # Assumed that we're at done_making_threads + set thread_list [get_mi_thread_list "in check_console_thread_commands"] + foreach thread $thread_list { + mi_gdb_test "-interpreter-exec console \"thread $thread\"" \ + "(\\~\".*\"\r\n)*=context-changed,thread=\"$thread\"\r\n\\^done" \ + "-interpreter-exec console \"thread $thread\"" + } +} + # # Start here # @@ -172,8 +222,11 @@ if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $optio } mi_gdb_reinitialize_dir $srcdir/$subdir +mi_gdb_load $binfile +check_mi_thread_command_set +check_console_thread_commands check_for_gdb669_bug mi_gdb_exit -return 0 + diff --git a/gdb/testsuite/gdb.mi/pthreads.c b/gdb/testsuite/gdb.mi/pthreads.c index df64e21e3e5..c3e17bc6ace 100644 --- a/gdb/testsuite/gdb.mi/pthreads.c +++ b/gdb/testsuite/gdb.mi/pthreads.c @@ -43,8 +43,15 @@ routine (void *arg) printf ("hello thread\n"); } -int -main (int argc, char *argv[]) +/* Marker function for the testsuite */ +void +done_making_threads (void) +{ + /* Nothing */ +}; + +void +create_thread (void) { pthread_t tid; @@ -53,10 +60,20 @@ main (int argc, char *argv[]) perror ("pthread_create 1"); exit (1); } - +} + +int +main (int argc, char *argv[]) +{ + int i; + + /* Create a few threads */ + for (i = 0; i < 5; i++) + create_thread (); + done_making_threads (); + printf ("hello\n"); printf ("hello\n"); - pthread_join (tid, NULL); return 0; } -- 2.47.2