This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v3 3/4] tracepoint multithread and multiprocess support (test)


This patch is for the test.
The first parts of trace-multi.exp and trace-multi.c check if GDB and
gdbserver is OK to support multithread with trace in thread2's function
but set thread of tracepoint to thread1.
And really collect some traceframe for thread2 and select thread1 in
GDB side, test if tfind the GDB will select thread2.

The second parts and trace-multi2.c check if GDB and gdbserver is OK to
support multiprocess.
And "set remote multi-process-tracepoint-together-packet on" to open
multiprocess tracepoint together support in GDB side, then when GDB send
tracepoints of 2 inferiors, GDB will return error.

Please help me review it.

Thanks,
Hui

2013-12-31  Hui Zhu  <hui@codesourcery.com>

	* gdb.trace/trace-multi.exp: New file.
	* gdb.trace/trace-multi.c: New file.
	* gdb.trace/trace-multi2.c: New file.
--- a/gdb/testsuite/gdb.trace/Makefile.in
+++ b/gdb/testsuite/gdb.trace/Makefile.in
@@ -4,7 +4,8 @@ srcdir = @srcdir@
 .PHONY: all clean mostlyclean distclean realclean
PROGS = actions-changed ax backtrace deltrace disconnected-tracing \
-	infotrace packetlen passc-dyn passcount report save-trace tfile \
+	infotrace packetlen passc-dyn passcount trace-multi \
+	trace-multi2 report save-trace tfile \
 	tfind tracecmd tsv unavailable while-dyn while-stepping
all info install-info dvi install uninstall installcheck check:
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/trace-multi.c
@@ -0,0 +1,55 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2013 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/>.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pthread.h>
+
+void stop ()
+{
+}
+
+int thread_count;
+
+static void *
+thread (void *arg)
+{
+  int i = 0;
+
+  while (i < 5)
+    ++i;	/* set tracepoint1 here */
+  stop ();
+  while (i < 10)
+    ++i;	/* set tracepoint2 here */
+  stop ();
+}
+
+int main ()
+{
+  int i = 0;
+  pthread_t tid;
+
+  i = pthread_create (&tid, NULL, thread, NULL);
+  assert (i == 0);
+  pthread_join (tid, NULL);
+
+  while (i < 10)
+    ++i;	/* set tracepoint3 here */
+  stop ();
+  return 0;
+}
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/trace-multi.exp
@@ -0,0 +1,135 @@
+# Copyright 2013 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/>.
+
+load_lib "trace-support.exp"
+
+standard_testfile
+set exec1 ${testfile}
+set srcfile1 ${exec1}.c
+
+set tp_location1 ${srcfile1}:[gdb_get_line_number "set tracepoint1 here" ${srcfile1}]
+set tp_location2 ${srcfile1}:[gdb_get_line_number "set tracepoint2 here" ${srcfile1}]
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+    return -1
+}
+
+clean_restart ${exec1}
+
+if ![runto_main] {
+    return -1
+}
+
+if ![gdb_target_supports_trace] {
+    unsupported "target does not support trace"
+    return -1
+}
+
+gdb_breakpoint "stop"
+
+# Set tracepoint to tp_location1 and thread 1
+gdb_test "trace ${tp_location1} thread 1" \
+	"Tracepoint $decimal .*" \
+	"set tracepoint1 to thread 1"
+gdb_trace_setactions "set tracepoint1 actions to thread 1" "" \
+	"collect i" "^$"
+
+gdb_test_no_output "tstart"
+gdb_test "continue" "Continuing.*Breakpoint $decimal.*" "continue 1"
+gdb_test_no_output "tstop"
+
+# Test if tracepoint is not triggered by thread 2
+gdb_test "tfind" "Target failed to find requested trace frame." "thread tfind 1"
+
+# Check threads
+gdb_test "info threads" \
+	 "\r\n\[ \t\]*Id\[ \t\]+Target\[ \t\]+Id\[ \t\]+Frame\[ \t\]*\r\n.*2 *Thread.*\r\n.*1 *Thread.*"
+
+# Set tracepoint to tp_location2 and thread 2
+gdb_test "trace ${tp_location2} thread 2" \
+	"Tracepoint $decimal .*" \
+	"set tracepoint1 to thread 2"
+gdb_trace_setactions "set tracepoint2 actions to thread 2" "" \
+	"collect i" "^$"
+
+gdb_test_no_output "tstart"
+gdb_test "continue" "Continuing.*Breakpoint $decimal.*" "continue 2"
+gdb_test_no_output "tstop"
+
+# Test current thread switch from 1 to 2 when tfind the traceframe of thread 2
+gdb_test "thread 1" "Switching to thread 1.*"
+gdb_test "tfind" "Switching to thread 2.*" "thread tfind 2"
+
+gdb_test "tfind -1" "No longer looking at any trace frame.*"
+
+
+# Following part is multiprocess test
+# Multiple inferiors are needed, therefore both native and extended gdbserver
+# modes are supported.  Only non-extended gdbserver is not supported.
+if [target_info exists use_gdb_stub] {
+    untested ${testfile}.exp
+    return
+}
+
+standard_testfile
+set exec2 ${testfile}2
+set srcfile2 ${exec2}.c
+set binfile2 [standard_output_file ${exec2}]
+
+set tp_location3 ${srcfile1}:[gdb_get_line_number "set tracepoint3 here" ${srcfile1}]
+set tp_location4 ${srcfile2}:[gdb_get_line_number "set tracepoint4 here" ${srcfile2}]
+
+if { [build_executable ${testfile}.exp ${exec2} "${srcfile2}"] == -1 } {
+    return -1
+}
+
+gdb_test "add-inferior -exec ${binfile2}" \
+    "Added inferior 2.*" \
+    "add inferior 2 with -exec ${exec2}"
+
+gdb_test "trace ${tp_location3}" \
+	"Tracepoint $decimal .*" \
+	"set tracepoint to inferior 1"
+gdb_trace_setactions "set tracepoint actions to inferior 1" "" \
+	"collect i" "^$"
+gdb_test "trace ${tp_location4}" \
+	"Tracepoint $decimal .*" \
+	"set tracepoint to inferior 2"
+gdb_trace_setactions "set tracepoint actions to inferior 2" "" \
+	"collect \$reg" "^$"
+
+gdb_test_no_output "tstart"
+gdb_test "continue" "Continuing.*Breakpoint $decimal.*" "run trace"
+gdb_test_no_output "tstop"
+
+gdb_test "tfind"
+gdb_test "print i" " = 0" "Print i 0"
+gdb_test "tfind"
+gdb_test "print i" " = 1" "Print i 1"
+gdb_test "tfind"
+gdb_test "print i" " = 2" "Print i 2"
+gdb_test "tfind"
+gdb_test "print i" " = 3" "Print i 3"
+gdb_test "tfind"
+gdb_test "print i" " = 4" "Print i 4"
+gdb_test "tfind"
+gdb_test "print i" " = 5" "Print i 5"
+gdb_test "tfind"
+gdb_test "print i" " = 6" "Print i 6"
+
+
+# Following part is multiprocess tracepoint together test
+gdb_test_no_output "set remote multi-process-tracepoint-together-packet on"
+gdb_test "tstart" "Target returns error code.*" "tstart with multiprocess tracepoint together test"
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/trace-multi2.c
@@ -0,0 +1,30 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2013 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/>.  */
+
+void stop ()
+{
+}
+
+int main ()
+{
+  int i = 10;
+
+  while (i > 0)
+    --i;	/* set tracepoint4 here */
+  stop ();
+  return 0;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]