aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorJason Molenda <jmolenda@apple.com>1999-10-19 02:47:02 +0000
committerJason Molenda <jmolenda@apple.com>1999-10-19 02:47:02 +0000
commit917317f4c6550f3f3e0001d0a9e5a6acd6a2d1be (patch)
tree3ecc5a5d86fef50ae8715adacf956a2011797441 /gdb/testsuite
parent446a06c9b8819b20be7704f0b540471d76959c66 (diff)
downloadgdb-917317f4c6550f3f3e0001d0a9e5a6acd6a2d1be.zip
gdb-917317f4c6550f3f3e0001d0a9e5a6acd6a2d1be.tar.gz
gdb-917317f4c6550f3f3e0001d0a9e5a6acd6a2d1be.tar.bz2
import gdb-1999-10-18 snapshot
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog13
-rw-r--r--gdb/testsuite/gdb.threads/linux-dp.c205
-rw-r--r--gdb/testsuite/gdb.threads/linux-dp.exp186
-rw-r--r--gdb/testsuite/lib/gdb.exp64
4 files changed, 444 insertions, 24 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 6fa430c..06e699f 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,16 @@
+1999-10-18 Jim Blandy <jimb@zwingli.cygnus.com>
+
+ * gdb.threads/linux-dp.c, gdb.threads/linux-dp.exp: New test suite
+ for LinuxThreads support, merged from the Code Fusion branch.
+
+Mon Oct 11 13:57:21 1999 Andrew Cagney <cagney@amy.cygnus.com>
+
+ * lib/gdb.exp (gdb_run_cmd): Break complicated gdb_expect
+ containing exp_continue into a while within an expect. Don't
+ attempt a start more than three times. Check return value from
+ gdb_load.
+
+
Wed Oct 6 12:05:58 1999 Andrew Cagney <cagney@b1.cygnus.com>
* gdb.base/watchpoint.exp: Match fail ``finish from marker1'' with
diff --git a/gdb/testsuite/gdb.threads/linux-dp.c b/gdb/testsuite/gdb.threads/linux-dp.c
new file mode 100644
index 0000000..b66649b
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/linux-dp.c
@@ -0,0 +1,205 @@
+/* linux-dp.c --- dining philosophers, on LinuxThreads
+ Jim Blandy <jimb@cygnus.com> --- March 1999 */
+
+/* It's okay to edit this file and shift line numbers around. The
+ tests use gdb_get_line_number to find source locations, so they
+ don't depend on having certain line numbers in certain places. */
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <sys/time.h>
+#include <sys/types.h>
+
+/* The number of philosophers at the table. */
+int num_philosophers;
+
+/* Mutex ordering -
+ If you want to lock a mutex M, all the mutexes you have locked
+ already must appear before M on this list.
+
+ fork_mutex[0]
+ fork_mutex[1]
+ ...
+ fork_mutex[num_philosophers - 1]
+ stdout_mutex
+ random_mutex
+*/
+
+/* You must hold this mutex while writing to stdout. */
+pthread_mutex_t stdout_mutex;
+
+/* You must hold this mutex while calling any of the random number
+ generation routines. */
+pthread_mutex_t random_mutex;
+
+/* array of mutexes, one for each fork; fork_mutex[i] is to the left
+ of philosopher i. A philosopher is holding fork i iff his/her
+ thread has locked fork_mutex[i]. */
+pthread_mutex_t *fork_mutex;
+
+/* array of threads, one representing each philosopher. */
+pthread_t *philosophers;
+
+void *
+xmalloc (size_t n)
+{
+ void *p = malloc (n);
+
+ if (! p)
+ {
+ fprintf (stderr, "out of memory\n");
+ exit (2);
+ }
+
+ return p;
+}
+
+void
+shared_printf (char *format, ...)
+{
+ va_list ap;
+
+ va_start (ap, format);
+ pthread_mutex_lock (&stdout_mutex);
+ vprintf (format, ap);
+ pthread_mutex_unlock (&stdout_mutex);
+ va_end (ap);
+}
+
+int
+shared_random ()
+{
+ static unsigned int seed;
+ int result;
+
+ pthread_mutex_lock (&random_mutex);
+ result = rand_r (&seed);
+ pthread_mutex_unlock (&random_mutex);
+ return result;
+}
+
+void
+my_usleep (long usecs)
+{
+ struct timeval timeout;
+
+ timeout.tv_sec = usecs / 1000000;
+ timeout.tv_usec = usecs % 1000000;
+
+ select (0, 0, 0, 0, &timeout);
+}
+
+void
+random_delay ()
+{
+ my_usleep ((shared_random () % 2000) * 100);
+}
+
+void
+print_philosopher (int n, char left, char right)
+{
+ int i;
+
+ shared_printf ("%*s%c %d %c\n", (n * 4) + 2, "", left, n, right);
+}
+
+void *
+philosopher (void *data)
+{
+ int n = * (int *) data;
+
+ print_philosopher (n, '_', '_');
+
+#if 1
+ if (n == num_philosophers - 1)
+ for (;;)
+ {
+ /* The last philosopher is different. He goes for his right
+ fork first, so there is no cycle in the mutex graph. */
+
+ /* Grab the right fork. */
+ pthread_mutex_lock (&fork_mutex[(n + 1) % num_philosophers]);
+ print_philosopher (n, '_', '!');
+ random_delay ();
+
+ /* Then grab the left fork. */
+ pthread_mutex_lock (&fork_mutex[n]);
+ print_philosopher (n, '!', '!');
+ random_delay ();
+
+ print_philosopher (n, '_', '_');
+ pthread_mutex_unlock (&fork_mutex[n]);
+ pthread_mutex_unlock (&fork_mutex[(n + 1) % num_philosophers]);
+ random_delay ();
+ }
+ else
+#endif
+ for (;;)
+ {
+ /* Grab the left fork. */
+ pthread_mutex_lock (&fork_mutex[n]);
+ print_philosopher (n, '!', '_');
+ random_delay ();
+
+ /* Then grab the right fork. */
+ pthread_mutex_lock (&fork_mutex[(n + 1) % num_philosophers]);
+ print_philosopher (n, '!', '!');
+ random_delay ();
+
+ print_philosopher (n, '_', '_');
+ pthread_mutex_unlock (&fork_mutex[n]);
+ pthread_mutex_unlock (&fork_mutex[(n + 1) % num_philosophers]);
+ random_delay ();
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ num_philosophers = 5;
+
+ /* Set up the mutexes. */
+ {
+ pthread_mutexattr_t ma;
+ int i;
+
+ pthread_mutexattr_init (&ma);
+ pthread_mutex_init (&stdout_mutex, &ma);
+ pthread_mutex_init (&random_mutex, &ma);
+ fork_mutex = xmalloc (num_philosophers * sizeof (fork_mutex[0]));
+ for (i = 0; i < num_philosophers; i++)
+ pthread_mutex_init (&fork_mutex[i], &ma);
+ pthread_mutexattr_destroy (&ma);
+ }
+
+ /* Set off the threads. */
+ {
+ int i;
+ int *numbers = xmalloc (num_philosophers * sizeof (*numbers));
+ pthread_attr_t ta;
+
+ philosophers = xmalloc (num_philosophers * sizeof (*philosophers));
+
+ pthread_attr_init (&ta);
+
+ for (i = 0; i < num_philosophers; i++)
+ {
+ numbers[i] = i;
+ /* linuxthreads.exp: create philosopher */
+ pthread_create (&philosophers[i], &ta, philosopher, &numbers[i]);
+ }
+
+ pthread_attr_destroy (&ta);
+ }
+
+ /* linuxthreads.exp: info threads 2 */
+ sleep (1000000);
+
+ /* Drink yourself into oblivion. */
+ for (;;)
+ sleep (1000000);
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.threads/linux-dp.exp b/gdb/testsuite/gdb.threads/linux-dp.exp
new file mode 100644
index 0000000..87dc868
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/linux-dp.exp
@@ -0,0 +1,186 @@
+# Copyright (C) 1999 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@gnu.org
+
+#### Dining Philosophers, on LinuxThreads - Jim Blandy <jimb@cygnus.com>
+####
+#### At the moment, GDB's support for LinuxThreads is pretty
+#### idiosyncratic --- GDB's output doesn't look much like the output
+#### it produces for other thread implementations, messages appear at
+#### different times, etc. So these tests are specific to LinuxThreads.
+####
+#### However, if all goes well, Linux will soon have a libthread_db
+#### interface, and GDB will manage it the same way it does other
+#### libthread_db-based systems. Then, we can adjust this file to
+#### work with any such system.
+
+### Other things we ought to test:
+### stepping a thread while others are running
+### killing and restarting
+### quitting gracefully
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+# This only works with Linux configurations.
+if ![istarget *-*-linux-gnu] then {
+ return
+}
+
+set testfile "linux-dp"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug libs=-lpthread}] != ""} {
+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
+runto_main
+
+# There should be no threads initially.
+gdb_test "info threads" "" "info threads 1"
+
+# Try stepping over the thread creation function.
+gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: create philosopher"]
+for {set i 0} {$i < 5} {incr i} {
+ gdb_continue_to_breakpoint "about to create philosopher: $i"
+ gdb_test "next" "\\\[New Thread .*\\\].*" "create philosopher: $i"
+}
+
+# Run until there are some threads.
+gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: info threads 2"]
+gdb_continue_to_breakpoint "main thread's sleep"
+gdb_test "info threads" "7 Thread .*6 Thread .*5 Thread .*4 Thread .*3 Thread .*2 Thread .* \\(initial thread\\) main \\(argc=1, argv=.*\\) at .*linux-dp.c:.*1 Thread .* \\(manager thread\\).*" "info threads 2"
+
+# Try setting a thread-specific breakpoint.
+gdb_breakpoint "print_philosopher thread 5"
+gdb_continue_to_breakpoint "thread 5's print"
+gdb_test "where" "print_philosopher.*philosopher.*pthread_start_thread.*" \
+ "first thread-specific breakpoint hit"
+
+# Make sure it's catching the right thread. Try hitting the
+# breakpoint ten times, and make sure we don't get anyone else.
+set only_five 1
+for {set i 0} {$only_five > 0 && $i < 10} {incr i} {
+ gdb_continue_to_breakpoint "thread 5's print, pass: $i"
+ send_gdb "info threads\n"
+ gdb_expect {
+ -re "\\* 5 Thread .* print_philosopher .*\r\n$gdb_prompt $" {
+ # Okay this time.
+ }
+ -re ".*$gdb_prompt $" {
+ set only_five 0
+ }
+ timeout {
+ set only_five -1
+ }
+ }
+}
+
+set name "thread-specific breakpoint is thread-specific"
+if {$only_five == 1} { pass $name }
+if {$only_five == 0} { fail $name }
+if {$only_five == -1} { fail "$name (timeout)" }
+
+
+### Select a particular thread.
+proc select_thread {thread} {
+ global gdb_prompt
+
+ send_gdb "thread $thread\n"
+ gdb_expect {
+ -re "\\\[Switching to thread .*\\\].*\r\n$gdb_prompt $" {
+ pass "selected thread: $thread"
+ }
+ -re "$gdb_prompt $" {
+ fail "selected thread: $thread"
+ }
+ timeout {
+ fail "selected thread: $thread (timeout)"
+ }
+ }
+}
+
+### Select THREAD, check for a plausible backtrace, and make sure
+### we're actually selecting a different philosopher each time.
+### Return true if the thread had a stack which was not only
+### acceptable, but interesting. SEEN should be an array in which
+### SEEN(N) exists iff we have found philosopher number N before.
+proc check_philosopher_stack {thread seen_name} {
+ global gdb_prompt
+ upvar $seen_name seen
+
+ set name "philosopher is distinct: $thread"
+ set interesting 0
+
+ select_thread $thread
+ send_gdb "where\n"
+ gdb_expect {
+ -re ".* in philosopher \\(data=(0x\[0-9a-f\]+).*\r\n$gdb_prompt $" {
+ set data $expect_out(1,string)
+ if {[info exists seen($data)]} {
+ fail $name
+ } else {
+ pass $name
+ set seen($data) yep
+ }
+ set interesting 1
+ }
+ -re "pthread_start_thread.*\r\n$gdb_prompt $" {
+ ## Maybe the thread hasn't started yet.
+ pass $name
+ }
+ -re " in \\?\\?.*\r\n$gdb_prompt $" {
+ ## Sometimes we can't get a backtrace. I'm going to call
+ ## this a pass, since we do verify that at least one
+ ## thread was interesting, so we can get more consistent
+ ## test suite totals. But in my heart, I think it should
+ ## be an xfail.
+ pass $name
+ }
+ -re "$gdb_prompt $" {
+ fail $name
+ }
+ timeout {
+ fail "$name (timeout)"
+ }
+ }
+
+ return $interesting
+}
+
+set any_interesting 0
+array set seen {}
+for {set i 3} {$i <= 7} {incr i} {
+ if [check_philosopher_stack $i seen] {
+ set any_interesting 1
+ }
+}
+
+if {$any_interesting} {
+ pass "found an interesting thread"
+} else {
+ fail "found an interesting thread"
+}
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index ab640a3..f3e3ed3 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -180,8 +180,11 @@ proc gdb_run_cmd {args} {
if [target_info exists use_gdb_stub] {
if [target_info exists gdb,do_reload_on_run] {
- # According to Stu, this will always work.
- gdb_load "";
+ # Specifying no file, defaults to the executable
+ # currently being debugged.
+ if { [gdb_load ""] < 0 } {
+ return;
+ }
send_gdb "continue\n";
gdb_expect 60 {
-re "Continu\[^\r\n\]*\[\r\n\]" {}
@@ -196,31 +199,44 @@ proc gdb_run_cmd {args} {
set start "start";
}
send_gdb "jump *$start\n"
- gdb_expect 30 {
- -re "Continuing at \[^\r\n\]*\[\r\n\]" {
- if ![target_info exists gdb_stub] {
- return;
- }
- }
- -re "No symbol \"start\" in current.*$gdb_prompt $" {
- send_gdb "jump *_start\n";
- exp_continue;
- }
- -re "No symbol \"_start\" in current.*$gdb_prompt $" {
- perror "Can't find start symbol to run in gdb_run";
+ set start_attempt 1;
+ while { $start_attempt } {
+ # Cap (re)start attempts at three to ensure that this loop
+ # always eventually fails. Don't worry about trying to be
+ # clever and not send a command when it has failed.
+ if [expr $start_attempt > 3] {
+ perror "Jump to start() failed (retry count exceeded)";
return;
}
- -re "Line.* Jump anyway.*y or n. $" {
- send_gdb "y\n"
- exp_continue;
- }
- -re "No symbol.*context.*$gdb_prompt $" {}
- -re "The program is not being run.*$gdb_prompt $" {
- gdb_load "";
- send_gdb "jump *$start\n";
- exp_continue;
+ set start_attempt [expr $start_attempt + 1];
+ gdb_expect 30 {
+ -re "Continuing at \[^\r\n\]*\[\r\n\]" {
+ set start_attempt 0;
+ }
+ -re "No symbol \"_start\" in current.*$gdb_prompt $" {
+ perror "Can't find start symbol to run in gdb_run";
+ return;
+ }
+ -re "No symbol \"start\" in current.*$gdb_prompt $" {
+ send_gdb "jump *_start\n";
+ }
+ -re "No symbol.*context.*$gdb_prompt $" {
+ set start_attempt 0;
+ }
+ -re "Line.* Jump anyway.*y or n. $" {
+ send_gdb "y\n"
+ }
+ -re "The program is not being run.*$gdb_prompt $" {
+ if { [gdb_load ""] < 0 } {
+ return;
+ }
+ send_gdb "jump *$start\n";
+ }
+ timeout {
+ perror "Jump to start() failed (timeout)";
+ return
+ }
}
- timeout { perror "Jump to start() failed (timeout)"; return }
}
if [target_info exists gdb_stub] {
gdb_expect 60 {