From patchwork Fri Oct 17 12:02:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jose E. Marchesi" X-Patchwork-Id: 3262 Received: (qmail 9572 invoked by alias); 17 Oct 2014 12:01:42 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 9562 invoked by uid 89); 17 Oct 2014 12:01:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=AWL, BAYES_00, LIKELY_SPAM_BODY, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=no version=3.3.2 X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 17 Oct 2014 12:01:40 +0000 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s9HC1ZGk019431 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 17 Oct 2014 12:01:36 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by ucsinet22.oracle.com (8.14.5+Sun/8.14.5) with ESMTP id s9HC1Zb3019636 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 17 Oct 2014 12:01:35 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s9HC1Ygv015431; Fri, 17 Oct 2014 12:01:34 GMT Received: from termi.oracle.com (/62.156.150.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 17 Oct 2014 05:01:33 -0700 From: jose.marchesi@oracle.com (Jose E. Marchesi) To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH V2 7/9] Simple testsuite for DTrace USDT probes. References: <1412961772-16249-1-git-send-email-jose.marchesi@oracle.com> <1412961772-16249-8-git-send-email-jose.marchesi@oracle.com> <54404878.50406@redhat.com> Date: Fri, 17 Oct 2014 14:02:01 +0200 In-Reply-To: <54404878.50406@redhat.com> (Pedro Alves's message of "Thu, 16 Oct 2014 23:36:40 +0100") Message-ID: <87bnpa3nwm.fsf@oracle.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Hi Pedro. Thanks for your suggestions. Please take a look to this new version of the patch. I think it addresses all your concerns :) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index feb3ab1..f44404b 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,17 @@ 2014-10-17 Jose E. Marchesi + * lib/dtrace.exp: New file. + * gdb.base/dtrace-probe.exp: Likewise. + * gdb.base/dtrace-probe.d: Likewise. + * gdb.base/dtrace-probe.c: Likewise. + +2014-10-17 Jose E. Marchesi + * gdb.base/stap-probe.exp (stap_test): Remove "SystemTap" from expected message when trying to access $_probe_* convenience variables while not on a probe. diff --git a/gdb/testsuite/gdb.base/dtrace-probe.c b/gdb/testsuite/gdb.base/dtrace-probe.c new file mode 100644 index 0000000..45a77c5 --- /dev/null +++ b/gdb/testsuite/gdb.base/dtrace-probe.c @@ -0,0 +1,38 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2014 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 . */ + +#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); + } + + TEST_TWO_LOCATIONS (); + + return 0; /* last break here */ +} diff --git a/gdb/testsuite/gdb.base/dtrace-probe.d b/gdb/testsuite/gdb.base/dtrace-probe.d new file mode 100644 index 0000000..df8e6bb --- /dev/null +++ b/gdb/testsuite/gdb.base/dtrace-probe.d @@ -0,0 +1,21 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2014 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 . */ + +provider test { + probe progress__counter (char *name, int); + probe two__locations (); +}; diff --git a/gdb/testsuite/gdb.base/dtrace-probe.exp b/gdb/testsuite/gdb.base/dtrace-probe.exp new file mode 100644 index 0000000..ebbb5ff --- /dev/null +++ b/gdb/testsuite/gdb.base/dtrace-probe.exp @@ -0,0 +1,106 @@ +# Copyright (C) 2014 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 . + +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 ${testfile}.exp + 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" + } + gdb_test "continue" \ + "Breakpoint \[0-9\]+, main \\(\\) at.*TEST_TWO_LOCATIONS.*" \ + "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 diff --git a/gdb/testsuite/lib/dtrace.exp b/gdb/testsuite/lib/dtrace.exp new file mode 100644 index 0000000..b0310d8 --- /dev/null +++ b/gdb/testsuite/lib/dtrace.exp @@ -0,0 +1,68 @@ +# Copyright 2014 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 . + +# 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. +# +# 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 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). + + 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]]} { + return -1 + } + 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 ${binfile}.o -o ${binfile}-p.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 + } +}