aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/py-thrhandle.exp
blob: 66b04728e0300a74c46a8ce08425057b326f25c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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"