Simple testsuite for DTrace USDT probes.

This patch adds some simple tests testing the support for DTrace USDT
probes.  The testsuite will be skipped as unsupported in case the user
does not have DTrace installed on her system.  The tests included in the
test suite test breakpointing on DTrace probes, enabling and disabling
probes, printing of probe arguments of several types and also
breakpointing on several probes with the same name.

gdb/ChangeLog:

2015-02-17  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* lib/dtrace.exp: New file.
	* gdb.base/dtrace-probe.exp: Likewise.
	* gdb.base/dtrace-probe.d: Likewise.
	* gdb.base/dtrace-probe.c: Likewise.
	* lib/pdtrace.in: Likewise.
	* configure.ac: Output variables with the transformed names of
	the strip, readelf, as and nm tools.  AC_SUBST lib/pdtrace.in.
	* configure: Regenerated.
This commit is contained in:
Jose E. Marchesi
2015-02-17 16:41:16 +01:00
parent c3e3045e5c
commit 497c491bea
8 changed files with 1357 additions and 0 deletions

View File

@ -1,3 +1,14 @@
2015-02-17 Jose E. Marchesi <jose.marchesi@oracle.com>
* lib/dtrace.exp: New file.
* gdb.base/dtrace-probe.exp: Likewise.
* gdb.base/dtrace-probe.d: Likewise.
* gdb.base/dtrace-probe.c: Likewise.
* lib/pdtrace.in: Likewise.
* configure.ac: Output variables with the transformed names of
the strip, readelf, as and nm tools. AC_SUBST lib/pdtrace.in.
* configure: Regenerated.
2015-02-17 Jose E. Marchesi <jose.marchesi@oracle.com> 2015-02-17 Jose E. Marchesi <jose.marchesi@oracle.com>
* gdb.base/stap-probe.exp (stap_test): Remove "SystemTap" from * gdb.base/stap-probe.exp (stap_test): Remove "SystemTap" from

View File

@ -591,6 +591,10 @@ ac_includes_default="\
ac_subst_vars='LTLIBOBJS ac_subst_vars='LTLIBOBJS
LIBOBJS LIBOBJS
NM_TRANSFORM_NAME
GAS_TRANSFORM_NAME
READELF_TRANSFORM_NAME
STRIP_TRANSFORM_NAME
EXTRA_RULES EXTRA_RULES
EGREP EGREP
GREP GREP
@ -1272,6 +1276,11 @@ _ACEOF
cat <<\_ACEOF cat <<\_ACEOF
Program names:
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names
System types: System types:
--build=BUILD configure for building on BUILD [guessed] --build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD] --host=HOST cross-compile to build programs to run on HOST [BUILD]
@ -3458,6 +3467,42 @@ if test "${build}" = "${host}" -a "${host}" = "${target}"; then
fi fi
# Transform the name of some programs and generate the lib/pdtrace
# test tool.
test "$program_prefix" != NONE &&
program_transform_name="s&^&$program_prefix&;$program_transform_name"
# Use a double $ so make ignores it.
test "$program_suffix" != NONE &&
program_transform_name="s&\$&$program_suffix&;$program_transform_name"
# Double any \ or $.
# By default was `s,x,x', remove it if useless.
ac_script='s/[\\$]/&&/g;s/;s,x,x,$//'
program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`
transform=`echo "$program_transform_name" | sed -e 's/\\$\\$/\\$/g'`
STRIP_TRANSFORM_NAME=`echo strip | sed -e "$transform"`
if test "x$STRIP_TRANSFORM_NAME" = x; then
STRIP_TRANSFORM_NAME=strip
fi
READELF_TRANSFORM_NAME=`echo readelf | sed -e "$transform"`
if test "x$READELF_TRANSFORM_NAME" = x; then
READELF_TRANSFORM_NAME=readelf
fi
GAS_TRANSFORM_NAME=`echo as | sed -e "$transform"`
if test "x$GAS_TRANSFORM_NAME" = x; then
GAS_TRANSFORM_NAME=as
fi
NM_TRANSFORM_NAME=`echo nm | sed -e "$transform"`
if test "x$NM_TRANSFORM_NAME" = x; then
NM_TRANSFORM_NAME=nm
fi
ac_config_files="$ac_config_files lib/pdtrace"
ac_config_files="$ac_config_files Makefile gdb.ada/Makefile gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.btrace/Makefile gdb.cell/Makefile gdb.compile/Makefile gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile gdb.dlang/Makefile gdb.fortran/Makefile gdb.gdb/Makefile gdb.go/Makefile gdb.server/Makefile gdb.java/Makefile gdb.hp/Makefile gdb.hp/gdb.objdbg/Makefile gdb.hp/gdb.base-hp/Makefile gdb.hp/gdb.aCC/Makefile gdb.hp/gdb.compat/Makefile gdb.hp/gdb.defects/Makefile gdb.guile/Makefile gdb.linespec/Makefile gdb.mi/Makefile gdb.modula2/Makefile gdb.multi/Makefile gdb.objc/Makefile gdb.opencl/Makefile gdb.opt/Makefile gdb.pascal/Makefile gdb.perf/Makefile gdb.python/Makefile gdb.reverse/Makefile gdb.stabs/Makefile gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile" ac_config_files="$ac_config_files Makefile gdb.ada/Makefile gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.btrace/Makefile gdb.cell/Makefile gdb.compile/Makefile gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile gdb.dlang/Makefile gdb.fortran/Makefile gdb.gdb/Makefile gdb.go/Makefile gdb.server/Makefile gdb.java/Makefile gdb.hp/Makefile gdb.hp/gdb.objdbg/Makefile gdb.hp/gdb.base-hp/Makefile gdb.hp/gdb.aCC/Makefile gdb.hp/gdb.compat/Makefile gdb.hp/gdb.defects/Makefile gdb.guile/Makefile gdb.linespec/Makefile gdb.mi/Makefile gdb.modula2/Makefile gdb.multi/Makefile gdb.objc/Makefile gdb.opencl/Makefile gdb.opt/Makefile gdb.pascal/Makefile gdb.perf/Makefile gdb.python/Makefile gdb.reverse/Makefile gdb.stabs/Makefile gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile"
cat >confcache <<\_ACEOF cat >confcache <<\_ACEOF
@ -4158,6 +4203,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
for ac_config_target in $ac_config_targets for ac_config_target in $ac_config_targets
do do
case $ac_config_target in case $ac_config_target in
"lib/pdtrace") CONFIG_FILES="$CONFIG_FILES lib/pdtrace" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
"gdb.ada/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.ada/Makefile" ;; "gdb.ada/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.ada/Makefile" ;;
"gdb.arch/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.arch/Makefile" ;; "gdb.arch/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.arch/Makefile" ;;
@ -4599,6 +4645,11 @@ which seems to be undefined. Please make sure it is defined." >&2;}
esac esac
case $ac_file$ac_mode in
"lib/pdtrace":F) chmod +x lib/pdtrace ;;
esac
done # for ac_tag done # for ac_tag

View File

@ -96,6 +96,32 @@ if test "${build}" = "${host}" -a "${host}" = "${target}"; then
fi fi
AC_SUBST(EXTRA_RULES) AC_SUBST(EXTRA_RULES)
# Transform the name of some programs and generate the lib/pdtrace
# test tool.
AC_ARG_PROGRAM
transform=`echo "$program_transform_name" | sed -e 's/[\\$][\\$]/\\$/g'`
STRIP_TRANSFORM_NAME=`echo strip | sed -e "$transform"`
if test "x$STRIP_TRANSFORM_NAME" = x; then
STRIP_TRANSFORM_NAME=strip
fi
AC_SUBST(STRIP_TRANSFORM_NAME)
READELF_TRANSFORM_NAME=`echo readelf | sed -e "$transform"`
if test "x$READELF_TRANSFORM_NAME" = x; then
READELF_TRANSFORM_NAME=readelf
fi
AC_SUBST(READELF_TRANSFORM_NAME)
GAS_TRANSFORM_NAME=`echo as | sed -e "$transform"`
if test "x$GAS_TRANSFORM_NAME" = x; then
GAS_TRANSFORM_NAME=as
fi
AC_SUBST(GAS_TRANSFORM_NAME)
NM_TRANSFORM_NAME=`echo nm | sed -e "$transform"`
if test "x$NM_TRANSFORM_NAME" = x; then
NM_TRANSFORM_NAME=nm
fi
AC_SUBST(NM_TRANSFORM_NAME)
AC_CONFIG_FILES([lib/pdtrace], [chmod +x lib/pdtrace])
AC_OUTPUT([Makefile \ AC_OUTPUT([Makefile \
gdb.ada/Makefile \ gdb.ada/Makefile \
gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.btrace/Makefile \ gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.btrace/Makefile \

View File

@ -0,0 +1,38 @@
/* This testcase is part of GDB, the GNU debugger.
Copyright 2014, 2015 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/>. */
#include "dtrace-probe.h"
int
main ()
{
char *name = "application";
TEST_TWO_LOCATIONS ();
int i = 0;
while (i < 10)
{
i++;
if (TEST_PROGRESS_COUNTER_ENABLED ())
TEST_PROGRESS_COUNTER (name, i);
else
TEST_TWO_LOCATIONS ();
}
return 0; /* last break here */
}

View File

@ -0,0 +1,21 @@
/* This testcase is part of GDB, the GNU debugger.
Copyright 2014, 2015 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/>. */
provider test {
probe progress__counter (char *, int);
probe two__locations ();
};

View File

@ -0,0 +1,106 @@
# Copyright (C) 2014, 2015 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/>.
load_lib "dtrace.exp"
# Run the tests.
# This returns -1 on failure to compile or start, 0 otherwise.
proc dtrace_test {} {
global testfile hex srcfile binfile
standard_testfile
if {[dtrace_build_usdt_test_program] == -1} {
untested "could not compile test program"
return -1
}
clean_restart ${binfile}
if ![runto_main] {
return -1
}
gdb_test "print \$_probe_argc" "No probe at PC $hex" \
"check argument not at probe point"
# Test the 'info probes' command.
gdb_test "info probes dtrace" \
"test *progress-counter *$hex +no.*test *two-locations *$hex +always.*test *two-locations *$hex +always.*" \
"info probes dtrace"
# Disabling the probe test:two-locations shall have no effect,
# since no is-enabled probes are defined for it in the object
# file.
gdb_test "disable probe test two-locations" \
"Probe test:two-locations cannot be disabled.*" \
"disable probe test two-locations"
# On the other hand, the probe test:progress-counter can be
# enabled and then disabled again.
gdb_test "enable probe test progress-counter" \
"Probe test:progress-counter enabled.*" \
"enable probe test progress-counter"
gdb_test "disable probe test progress-counter" \
"Probe test:progress-counter disabled.*" \
"disable probe test progress-counter"
# Since test:progress-counter is disabled we can run to the second
# instance of the test:two-locations probe.
if {![runto "-probe-dtrace test:two-locations"]} {
fail "run to the first test:two-locations probe point"
}
if {![runto "-probe-dtrace test:two-locations"]} {
fail "run to the second test:two-locations probe point"
}
# Go back to the breakpoint on main() and enable the
# test:progress-counter probe. Set a breakpoint on it and see
# that it gets reached.
if ![runto_main] {
return -1
}
gdb_test "enable probe test progress-counter" \
"Probe test:progress-counter enabled.*" \
"enable probe test progress-counter"
gdb_test "break -probe-dtrace test:progress-counter" \
".*Breakpoint \[0-9\]+ .*" "set breakpoint in test:progress-counter"
gdb_continue_to_breakpoint "test:progress-counter"
# Test probe arguments.
gdb_test "print \$_probe_argc" " = 2" \
"print \$_probe_argc for probe progress-counter"
gdb_test "print \$_probe_arg0" \
" = $hex \"application\"" \
"print \$_probe_arg0 for probe progress-counter"
gdb_test "print \$_probe_arg1" " = 1" \
"print \$_probe_arg1 for probe progress-counter"
# Set a breakpoint with multiple probe locations.
gdb_test "break -pdtrace test:two-locations" \
"Breakpoint \[0-9\]+ at $hex.*2 locations.*" \
"set multi-location probe breakpoint (probe two-locations)"
return 0
}
dtrace_test

View File

@ -0,0 +1,71 @@
# Copyright 2014, 2015 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/>.
# Generate a test program containing DTrace USDT probes, whose sources
# are ${srcfile} and ${testfile}.d. The sequence of commands used to
# generate the test program is:
#
# 1. Generate a header file from ${testfile}.d using dtrace -h.
# 2. Compile ${srcfile}.c.
# 3. Generate an object file containing a DOF program using dtrace -G.
# 4. Link everything together to get the test program.
#
# Note that if DTrace is not found in the host system then this
# function uses the pdtrace implementation, which is located at
# testsuite/lib/pdtrace.
#
# This function requires 'testfile', 'srcfile' and 'binfile' to be
# properly set.
#
# This function returns -1 on failure, 0 otherwise
proc dtrace_build_usdt_test_program {} {
global testfile hex objdir srcdir srcfile subdir binfile
# Make sure that dtrace is installed, it is the real one (not the
# script installed by SystemTap, for example) and of the right
# version (>= 0.4.0). If it is not then use pdtrace instead.
set dtrace "dtrace"
set result [remote_exec host "$dtrace -V"]
if {[lindex $result 0] != 0 || ![regexp {^dtrace: Sun D [0-9]\.[0-9]\.[0-9]} [lindex $result 1]]} {
set dtrace "${objdir}/lib/pdtrace"
}
set dscript_file "${srcdir}/${subdir}/${testfile}.d"
# 1. Generate a header file from testprogram.d using dtrace -h.
set out_header_file [standard_output_file "${testfile}.h"]
set result [remote_exec host "$dtrace -h -s $dscript_file -o $out_header_file"]
verbose -log [lindex $result 1]
if {[lindex $result 0] != 0} {
return -1
}
# 2. Compile testprogram.c.
set options [list debug additional_flags=-I[file dirname $out_header_file]]
if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}.o" object ${options}] != ""} {
return -1
}
# 3. Generate an object file containing a DOF program using dtrace -G.
set result [remote_exec host "$dtrace -G -s $dscript_file -o ${binfile}-p.o ${binfile}.o"]
verbose -log [lindex $result 1]
if {[lindex $result 0] != 0} {
return -1
}
# 4. Link everything together to get the test program.
if {[gdb_compile "${binfile}.o ${binfile}-p.o" ${binfile} executable {debug}] != ""} {
return -1
}
}

1033
gdb/testsuite/lib/pdtrace.in Executable file

File diff suppressed because it is too large Load Diff