keiths / rpms / gdb

Forked from rpms/gdb 5 months ago
Clone
28857cc
2005-02-11  Jeff Johnston  <jjohnstn@redhat.com>
28857cc
28857cc
	* testsuite/gdb.threads/step-thread-exit.c: New testcase.
28857cc
	* testsuite/gdb.threads/step-thread-exit.exp: Ditto.
28857cc
	
9231e41
Index: gdb-6.5/gdb/testsuite/gdb.threads/step-thread-exit.c
9231e41
===================================================================
9231e41
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
fef19e0
+++ gdb-6.5/gdb/testsuite/gdb.threads/step-thread-exit.c	2006-07-12 03:18:47.000000000 -0300
fef19e0
@@ -0,0 +1,50 @@
28857cc
+/* This testcase is part of GDB, the GNU debugger.
28857cc
+
28857cc
+   Copyright 2005 Free Software Foundation, Inc.
28857cc
+
28857cc
+   This program is free software; you can redistribute it and/or modify
28857cc
+   it under the terms of the GNU General Public License as published by
28857cc
+   the Free Software Foundation; either version 2 of the License, or
28857cc
+   (at your option) any later version.
28857cc
+
28857cc
+   This program is distributed in the hope that it will be useful,
28857cc
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
28857cc
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28857cc
+   GNU General Public License for more details.
28857cc
+
28857cc
+   You should have received a copy of the GNU General Public License
28857cc
+   along with this program; if not, write to the Free Software
28857cc
+   Foundation, Inc., 59 Temple Place - Suite 330,
28857cc
+   Boston, MA 02111-1307, USA.  */
28857cc
+
28857cc
+#include <pthread.h>
28857cc
+#include <stdio.h>
28857cc
+#include <stdlib.h>
28857cc
+#include <unistd.h>
28857cc
+
28857cc
+void *thread_function (void *ptr)
28857cc
+{
28857cc
+  int *x = (int *)ptr;
28857cc
+  printf("In thread_function, *x is %d\n", *x);
28857cc
+} /* thread_function_end */
28857cc
+
fef19e0
+volatile int repeat = 0;
fef19e0
+
28857cc
+main()
28857cc
+{
28857cc
+  int ret;
28857cc
+  pthread_t th;
28857cc
+  int i = 3;
28857cc
+
28857cc
+  ret = pthread_create (&th, NULL, thread_function, &i);
fef19e0
+  do
fef19e0
+    {
fef19e0
+      repeat = 0;
fef19e0
+      sleep (3);  /* sleep */
fef19e0
+    }
fef19e0
+  while (repeat);
28857cc
+  pthread_join (th, NULL);
28857cc
+  return 0;
28857cc
+}
28857cc
+
28857cc
+
9231e41
Index: gdb-6.5/gdb/testsuite/gdb.threads/step-thread-exit.exp
9231e41
===================================================================
9231e41
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
fef19e0
+++ gdb-6.5/gdb/testsuite/gdb.threads/step-thread-exit.exp	2006-07-12 03:22:30.000000000 -0300
fef19e0
@@ -0,0 +1,113 @@
28857cc
+# This testcase is part of GDB, the GNU debugger.
28857cc
+
28857cc
+# Copyright 2005 Free Software Foundation, Inc.
28857cc
+
28857cc
+# This program is free software; you can redistribute it and/or modify
28857cc
+# it under the terms of the GNU General Public License as published by
28857cc
+# the Free Software Foundation; either version 2 of the License, or
28857cc
+# (at your option) any later version.
28857cc
+#
28857cc
+# This program is distributed in the hope that it will be useful,
28857cc
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
28857cc
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28857cc
+# GNU General Public License for more details.
28857cc
+#
28857cc
+# You should have received a copy of the GNU General Public License
28857cc
+# along with this program; if not, write to the Free Software
28857cc
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
28857cc
+
28857cc
+# Check that GDB can step over a thread exit.
28857cc
+
28857cc
+if $tracelevel {
28857cc
+    strace $tracelevel
28857cc
+}
28857cc
+
28857cc
+set prms_id 0
28857cc
+set bug_id 0
28857cc
+
28857cc
+set testfile "step-thread-exit"
28857cc
+set srcfile ${testfile}.c
28857cc
+set binfile ${objdir}/${subdir}/${testfile}
28857cc
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
28857cc
+    return -1
28857cc
+}
28857cc
+
28857cc
+gdb_exit
28857cc
+gdb_start
28857cc
+gdb_reinitialize_dir $srcdir/$subdir
28857cc
+gdb_load ${binfile}
28857cc
+
28857cc
+# Reset the debug file directory so we can't debug within the C library
28857cc
+gdb_test "set debug-file-directory ." "" ""
28857cc
+
28857cc
+#
28857cc
+# Run to `main' where we begin our tests.
28857cc
+#
28857cc
+
28857cc
+if ![runto_main] then {
28857cc
+    gdb_suppress_tests
28857cc
+}
28857cc
+
28857cc
+set sleep_line [expr [gdb_get_line_number "sleep"]]
28857cc
+set end_line [expr [gdb_get_line_number "thread_function_end"]]
28857cc
+
28857cc
+gdb_breakpoint "$end_line"
28857cc
+gdb_test "continue" "Break.*thread_function.*" "continue to thread_function 1"
28857cc
+
28857cc
+# Keep nexting until we cause the thread to exit.  We expect the main
28857cc
+# thread to be stopped and a message printed to tell us we have stepped
28857cc
+# over the thread exit.
28857cc
+set test "step over thread exit 1"
28857cc
+gdb_test_multiple "next" "$test" {
28857cc
+  -re "\}.*$gdb_prompt $" {
28857cc
+     send_gdb "next\n"
28857cc
+     exp_continue
28857cc
+  }
fef19e0
+  -re "Stepped over thread exit.*Program received signal SIGSTOP.*$gdb_prompt $" {
fef19e0
+     pass "$test"
28857cc
+  }
28857cc
+  -re "start_thread.*$gdb_prompt $" {
28857cc
+     send_gdb "next\n"
28857cc
+     exp_continue
28857cc
+  }
28857cc
+}
28857cc
+
28857cc
+gdb_test "bt" ".*sleep.*main.*$sleep_line.*" "backtrace after step 1"
28857cc
+
28857cc
+runto_main
28857cc
+gdb_breakpoint "$sleep_line"
28857cc
+gdb_breakpoint "$end_line"
fef19e0
+set test "continue to thread_function 2"
fef19e0
+gdb_test_multiple "continue" "$test" {
fef19e0
+    -re "Break.*thread_function.*$gdb_prompt $" {
fef19e0
+	pass $test
fef19e0
+    }
fef19e0
+    -re "Break.*$sleep_line.*$gdb_prompt $" {
fef19e0
+	gdb_test "set repeat=1" "" ""
fef19e0
+	send_gdb "continue\n"
fef19e0
+	exp_continue
fef19e0
+    }
fef19e0
+}
28857cc
+
28857cc
+# Keep nexting until we cause the thread to exit.  In this case, we
28857cc
+# expect the breakpoint in the main thread to have already triggered
28857cc
+# and so we should stop there with a message that we stepped over
28857cc
+# the thread exit.
28857cc
+set test "step over thread exit 2"
28857cc
+gdb_test_multiple "next" "$test" {
28857cc
+  -re "\}.*$gdb_prompt $" {
28857cc
+     send_gdb "next\n"
28857cc
+     exp_continue
28857cc
+  }
fef19e0
+  -re "Stepped over thread exit.*Break.*$sleep_line.*$gdb_prompt $" {
fef19e0
+     pass "$test (breakpoint hit)"
fef19e0
+  }
fef19e0
+  -re "Stepped over thread exit.*$gdb_prompt $" {
fef19e0
+     pass "$test (breakpoint not hit)"
28857cc
+  }
28857cc
+  -re "start_thread.*$gdb_prompt $" {
28857cc
+     send_gdb "next\n"
28857cc
+     exp_continue
28857cc
+  }
28857cc
+}
28857cc
+