]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/lib/dtrace.exp
Update copyright year range in all GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / lib / dtrace.exp
CommitLineData
42a4f53d 1# Copyright 2014-2019 Free Software Foundation, Inc.
497c491b
JM
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
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:
19#
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.
24#
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.
28#
29# This function requires 'testfile', 'srcfile' and 'binfile' to be
30# properly set.
31#
32# This function returns -1 on failure, 0 otherwise
33proc dtrace_build_usdt_test_program {} {
34 global testfile hex objdir srcdir srcfile subdir binfile
35
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.
39 set dtrace "dtrace"
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"
43 }
44 set dscript_file "${srcdir}/${subdir}/${testfile}.d"
45
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} {
51 return -1
52 }
53
54 # 2. Compile testprogram.c.
55 set options [list debug additional_flags=-I[file dirname $out_header_file]]
56 if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}.o" object ${options}] != ""} {
57 return -1
58 }
59
60 # 3. Generate an object file containing a DOF program using dtrace -G.
61 set result [remote_exec host "$dtrace -G -s $dscript_file -o ${binfile}-p.o ${binfile}.o"]
62 verbose -log [lindex $result 1]
63 if {[lindex $result 0] != 0} {
64 return -1
65 }
66
67 # 4. Link everything together to get the test program.
68 if {[gdb_compile "${binfile}.o ${binfile}-p.o" ${binfile} executable {debug}] != ""} {
69 return -1
70 }
71}