aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.multi/multi-target-thread-find.exp
blob: ee6df54b41154897ac5715e92611bc09097fe2e2 (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
103
104
105
106
# Copyright 2020-2024 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/>.

# Test "thread find" with multiple inferiors/targets.  Regression test
# for PR gdb/26631.

source $srcdir/$subdir/multi-target.exp.tcl

if {![multi_target_prepare]} {
    return
}

proc test_thread_find {} {
    global decimal gdb_prompt

    set NUM_INFS 6

    if {![setup "off"]} {
	untested "setup failed"
	return
    }

    # This makes sure we don't crash.  See PR gdb/26631.
    gdb_test "thread find xxxyyyzzz" \
	"No threads match 'xxxyyyzzz'"

    # Create thread names.
    for {set i 1} {$i <= $NUM_INFS} {incr i} {
	gdb_test "thread apply $i.1 thread name threadname_$i" \
	    "Thread $i.1 .*" \
	    "name thread $i"
    }

    # Collect target ids.

    for {set i 1} {$i <= $NUM_INFS} {incr i} {
	set target_id($i) ""
    }
    set any "\[^\r\n\]*"
    gdb_test_multiple "info threads" "collect thread id" {
	-re ". ($decimal).$decimal  (${tdlabel_re} ${any}) \"threadname_\[0-9\]+\" $any" {
	    set thr_num $expect_out(1,string)
	    set target_id($thr_num) $expect_out(2,string)
	    exp_continue
	}
	-re ".*$gdb_prompt $" {
	    pass "collect target id"
	}
    }

    # Find the threads by name.  Note we repeat the search with each
    # inferior selected, so that we're sure that GDB doesn't get
    # confused with which target stack to consult.

    with_test_prefix "find by name" {
	for {set sel_inf 1} {$sel_inf <= $NUM_INFS} {incr sel_inf} {
	    with_test_prefix "inf $sel_inf" {

		gdb_test "inferior $sel_inf" \
		    "Switching to inferior $sel_inf .*"

		for {set find_inf 1} {$find_inf <= $NUM_INFS} {incr find_inf} {
		    gdb_test "thread find threadname_$find_inf" \
			"Thread $find_inf.1 has name 'threadname_$find_inf'" \
			"find thread name $find_inf"
		}
	    }
	}
    }

    # Find the threads by target id.  Likewise we repeat the search
    # with each inferior selected.

    with_test_prefix "find by target id" {
	for {set sel_inf 1} {$sel_inf <= $NUM_INFS} {incr sel_inf} {
	    with_test_prefix "inf $sel_inf" {

		gdb_test "inferior $sel_inf" \
		    "Switching to inferior $sel_inf .*"

		for {set find_inf 1} {$find_inf <= $NUM_INFS} {incr find_inf} {
		    set target_id_re [string_to_regexp $target_id($find_inf)]
		    gdb_test "thread find $target_id($find_inf)" \
			"Thread $find_inf.1 has target id '$target_id_re'.*" \
			"find thread target id $find_inf"
		}
	    }
	}
    }
}

test_thread_find

multi_target_cleanup