aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/py-thrhandle.exp
diff options
context:
space:
mode:
authorKevin Buettner <kevinb@redhat.com>2016-05-05 12:39:36 -0700
committerKevin Buettner <kevinb@redhat.com>2017-09-21 11:49:48 -0700
commit757bf54bb48a8417154cfdd7128c1775d43478d8 (patch)
treef6513023423e4d9c6df9c4bfa08dc2b959f25e6e /gdb/testsuite/gdb.python/py-thrhandle.exp
parentf2ff95c5837bd41848e7156aa2677498518d0d18 (diff)
downloadgdb-757bf54bb48a8417154cfdd7128c1775d43478d8.zip
gdb-757bf54bb48a8417154cfdd7128c1775d43478d8.tar.gz
gdb-757bf54bb48a8417154cfdd7128c1775d43478d8.tar.bz2
Test case for Inferior.thread_from_thread_handle
As the title says, this is a test case for Inferior.thread_from_thread_handle, a python method which will, given a thread library dependent thread handle, find the GDB thread which corresponds to that thread handle (in the inferior under consideration). The C file for this test case causes the thread handles for the main thread and two child threads to be placed into an array. The test case runs to one of the functions (do_something()) at which point, it retrieves the thread handles from the array and attempts to find the corresponding thread in GDB's internal thread list. I use barriers to make sure that both threads have actually started; execution will stop when one of the threads breaks at do_something. Thanks to Simon Marchi for suggestions for forcing the thread numbering to be stable. gdb/testsuite/ChangeLog: * gdb.python/py-thrhandle.c, gdb.python/py-thrhandle.exp: New files.
Diffstat (limited to 'gdb/testsuite/gdb.python/py-thrhandle.exp')
-rw-r--r--gdb/testsuite/gdb.python/py-thrhandle.exp102
1 files changed, 102 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-thrhandle.exp b/gdb/testsuite/gdb.python/py-thrhandle.exp
new file mode 100644
index 0000000..66b0472
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-thrhandle.exp
@@ -0,0 +1,102 @@
+# Copyright (C) 2017 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@gnu.org
+
+# This file verifies that gdb.Inferior.thread_from_thread_handle works
+# as expected.
+
+standard_testfile
+
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } {
+ return -1
+}
+
+clean_restart ${binfile}
+runto_main
+
+gdb_test "break after_mc_barrier" \
+ "Breakpoint 2 at .*: file .*${srcfile}, line .*" \
+ "breakpoint on after_mc_barrier"
+
+gdb_test "break do_something" \
+ "Breakpoint 3 at .*: file .*${srcfile}, line .*" \
+ "breakpoint on do_something"
+
+gdb_test "continue" \
+ "Breakpoint 2, after_mc_barrier .*" \
+ "run to after_mc_barrier"
+
+gdb_test_no_output "del 2" "delete after_mc_barrier breakpoint"
+
+gdb_test "continue" \
+ "Breakpoint 3, do_something .*" \
+ "run to do_something"
+
+# The test case has been constructed so that the current thread,
+# indicated by '*' in the "info threads" output, should be stopped in
+# do_something() with a value of n which is the same as the number
+# reported in the "Id" column. If it's not, then something went wrong
+# with the start up sequence which should cause the main thread to be
+# thread 1, the first child thread to be thread 2, and the second
+# child thread to be thread 3.
+#
+# Note that \1 in the RE below is a backreference to the thread id
+# reported in the "Id" column.
+
+gdb_test "info threads" \
+ {.*[\r\n]+\* +([0-9]+) +Thread[^\r\n]* do_something \(n=\1\) at.*}
+
+# Check for expected results when passing a valid thread handle to
+# thread_from_thread_handle().
+
+gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('thrs\[0\]')).num)" \
+ "1" "print thread id for thrs\[0\]"
+
+gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('thrs\[1\]')).num)" \
+ "2" "print thread id for thrs\[1\]"
+
+gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('thrs\[2\]')).num)" \
+ "3" "print thread id for thrs\[2\]"
+
+# Objects which are of the correct size, but which are bogus thread
+# handles should return None. For the first test (using thrs[3]), we
+# use 0. For the second (thrs[4]), we use an unlikely bit pattern.
+
+gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('thrs\[3\]')))" \
+ "None" "print thread for bogus handle thrs\[3\]"
+
+gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('thrs\[4\]')))" \
+ "None" "print thread for bogus handle thrs\[4\]"
+
+# We should see an exception when passing an object of the wrong type.
+
+gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.lookup_symbol('main')))" \
+ ".*TypeError: Argument 'handle_obj' must be a thread handle object.*" \
+ "TypeError when passing a symbol object to thread_from_thread_handle"
+
+# We should see an exception when passing too large of an object.
+
+gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('thrs')))" \
+ ".*Thread handle size mismatch.*" \
+ "Pass overly large object to thread_from_thread_handle"
+
+# We should see an exception when passing too small of an object.
+
+gdb_test "python print(gdb.selected_inferior().thread_from_thread_handle(gdb.parse_and_eval('\"S\"')))" \
+ ".*Thread handle size mismatch.*" \
+ "Pass too small of an object to thread_from_thread_handle"