1 # Copyright 2014-2023 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Generate a test program containing DTrace USDT probes, whose sources
17 # are ${srcfile} and ${testfile}.d. The sequence of commands used to
18 # generate the test program is:
20 # 1. Generate a header file from ${testfile}.d using dtrace -h.
21 # 2. Compile ${srcfile}.c.
22 # 3. Generate an object file containing a DOF program using dtrace -G.
23 # 4. Link everything together to get the test program.
25 # Note that if DTrace is not found in the host system then this
26 # function uses the pdtrace implementation, which is located at
27 # testsuite/lib/pdtrace.
29 # This function requires 'testfile', 'srcfile' and 'binfile' to be
32 # This function returns -1 on failure, 0 otherwise
33 proc dtrace_build_usdt_test_program {} {
34 global testfile hex objdir srcdir srcfile subdir binfile
36 # Make sure that dtrace is installed, it is the real one (not the
37 # script installed by SystemTap, for example) and of the right
38 # version (>= 0.4.0). If it is not then use pdtrace instead.
40 set result [remote_exec host "$dtrace -V"]
41 if {[lindex $result 0] != 0 || ![regexp {^dtrace: Sun D [0-9]\.[0-9]\.[0-9]} [lindex $result 1]]} {
42 set dtrace "${objdir}/lib/pdtrace"
44 set dscript_file "${srcdir}/${subdir}/${testfile}.d"
46 # 1. Generate a header file from testprogram.d using dtrace -h.
47 set out_header_file [standard_output_file "${testfile}.h"]
48 set result [remote_exec host "$dtrace -h -s $dscript_file -o $out_header_file"]
49 verbose -log [lindex $result 1]
50 if {[lindex $result 0] != 0} {
54 # 2. Compile testprogram.c.
55 set options [list debug quiet \
56 additional_flags=-I[file dirname $out_header_file]]
57 if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}.o" object ${options}] != ""} {
61 # 3. Generate an object file containing a DOF program using dtrace -G.
62 set result [remote_exec host "$dtrace -G -s $dscript_file -o ${binfile}-p.o ${binfile}.o"]
63 verbose -log [lindex $result 1]
64 if {[lindex $result 0] != 0} {
68 # 4. Link everything together to get the test program.
69 if {[gdb_compile "${binfile}.o ${binfile}-p.o" ${binfile} executable \
70 {debug quiet}] != ""} {