1# Copyright 2012-2020 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16load_lib "trace-support.exp"
17
18standard_testfile
19set executable ""
20
21set ws "\[\r\n\t \]+"
22set cr "\[\r\n\]+"
23
24# Only x86 and x86_64 targets are supported for now.
25
26if { ![istarget "x86_64-*"] && ![istarget "i?86-*"] } {
27    continue
28}
29
30proc compile_stap_bin {exec_name {arg ""}} {
31    global srcfile
32    global srcdir
33    global subdir
34    global executable
35
36    if { $arg != "" } {
37	set arg "additional_flags=$arg"
38    }
39
40    set executable ${exec_name}
41
42    if { [gdb_compile "$srcdir/$subdir/$srcfile" \
43	      [standard_output_file $exec_name] \
44	      executable [concat $arg debug nowarnings]] != "" } {
45	untested "failed to compile"
46	return 0
47    }
48
49    return 1
50}
51
52proc prepare_for_trace_test {} {
53    global executable
54
55    clean_restart $executable
56
57    if { ![runto_main] } {
58	perror "Could not run to `main'."
59	continue
60    }
61
62    gdb_breakpoint [gdb_get_line_number "end-here"]
63}
64
65proc run_trace_experiment { test_probe msg } {
66    global gdb_prompt
67
68    set test "collect $msg: start trace experiment"
69    gdb_test_multiple "tstart" "$test" {
70	-re "^tstart\r\n$gdb_prompt $" {
71	    pass "$test"
72	}
73    }
74
75    gdb_test "continue" \
76	    "Continuing.*Breakpoint \[0-9\]+.*" \
77	    "collect $msg: run trace experiment"
78    gdb_test "tstop" \
79	    "\[\r\n\]+" \
80	    "collect $msg: stop trace experiment"
81    gdb_test "tfind start" \
82	    "#0 .*" \
83	    "collect $msg: tfind test frame"
84}
85
86proc gdb_collect_probe_arg { msg probe val_arg0 } {
87    global gdb_prompt
88    global cr
89
90    prepare_for_trace_test
91
92    gdb_test "trace $probe" \
93	    "Tracepoint \[0-9\]+ at .*" \
94	    "collect $msg: set tracepoint"
95    gdb_trace_setactions "collect $msg: define actions" \
96	    "" \
97	    "collect \$_probe_arg0" "^$"
98
99    # Begin the test.
100    run_trace_experiment $msg $probe
101
102    gdb_test "print \$_probe_arg0" \
103	    "\\$\[0-9\]+ = $val_arg0$cr" \
104	    "collect $msg: collected probe arg0"
105}
106
107if {![compile_stap_bin "stap-probe-nosem"]} {
108    # An appropriate failure message has already been output
109    return -1
110}
111
112clean_restart $executable
113if { ![runto_main] } {
114    perror "Could not run to `main'."
115    continue
116}
117
118if { ![gdb_target_supports_trace] } {
119    # Test cannot run on this target.
120    return 1
121}
122
123gdb_collect_probe_arg "probe args without semaphore" "-probe-stap user" "23"
124gdb_exit
125
126if {![compile_stap_bin "stap-probe-sem" "-DUSE_PROBES"]} {
127    # An appropriate failure message has already been output
128    return -1
129}
130
131gdb_collect_probe_arg "probe args with semaphore" "-probe-stap two" "46"
132
133# Finished!
134gdb_test "tfind none" ".*" ""
135