From patchwork Thu Sep 17 08:51:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 8740 Received: (qmail 54049 invoked by alias); 17 Sep 2015 08:51:25 -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 54033 invoked by uid 89); 17 Sep 2015 08:51:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-wi0-f173.google.com Received: from mail-wi0-f173.google.com (HELO mail-wi0-f173.google.com) (209.85.212.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 17 Sep 2015 08:51:17 +0000 Received: by wicfx3 with SMTP id fx3so17777026wic.0 for ; Thu, 17 Sep 2015 01:51:14 -0700 (PDT) X-Received: by 10.180.12.195 with SMTP id a3mr27266448wic.71.1442479874106; Thu, 17 Sep 2015 01:51:14 -0700 (PDT) Received: from E107787-LIN ([195.154.84.196]) by smtp.gmail.com with ESMTPSA id qq4sm2184525wjc.14.2015.09.17.01.51.13 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 17 Sep 2015 01:51:13 -0700 (PDT) From: Yao Qi To: Pierre Langlois Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 2/2] [testsuite] Add test case for tracepoints with conditions References: <1441992301-26779-1-git-send-email-pierre.langlois@arm.com> <1441992301-26779-3-git-send-email-pierre.langlois@arm.com> Date: Thu, 17 Sep 2015 09:51:11 +0100 In-Reply-To: <1441992301-26779-3-git-send-email-pierre.langlois@arm.com> (Pierre Langlois's message of "Fri, 11 Sep 2015 18:25:01 +0100") Message-ID: <86eghx1la8.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Pierre Langlois writes: [Pierre finished his 3-month rotation program on GDB and is assigned to some other project. I take over his patches today.] > +proc test_tracepoints { trace_command condition num_frames { kfail_proc 0 } } { > + global executable > + > + clean_restart ${executable} > + > + if ![runto_main] { > + fail "Can't run to main for ftrace tests" > + return 0 > + } > + > + gdb_test "break begin" ".*" "" > + > + gdb_test "break end" ".*" "" > + > + gdb_test "${trace_command} set_point if ${condition}" "\(Fast t|T\)racepoint .*" \ > + "${trace_command} with condition $condition" > + > + gdb_test "continue" \ > + ".*Breakpoint \[0-9\]+, begin .*" \ > + "advance to trace begin" This will generate duplicated test results entries in gdb.sum. We need to use with_test_prefix to avoid that. > + > + gdb_test_no_output "tstart" "start trace experiment" > + > + gdb_test_multiple "continue" "advance through tracing" { > + -re ".*Breakpoint \[0-9\]+, end .*" { > + pass "advance through tracing" > + } > + -re "Program received signal SIGSEGV, Segmentation fault\\..*" { > + if { $kfail_proc != 0 } { > + $kfail_proc $trace_command > + } > + fail "advance through tracing" > + } > + } This is racy, "$gdb_prompt $" is needed at the end of each pattern. Patch below fixes all of them, and I'll push it in. diff --git a/gdb/testsuite/gdb.trace/trace-condition.c b/gdb/testsuite/gdb.trace/trace-condition.c new file mode 100644 index 0000000..2e965c9 --- /dev/null +++ b/gdb/testsuite/gdb.trace/trace-condition.c @@ -0,0 +1,66 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2011-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 . */ + +#ifdef SYMBOL_PREFIX +#define SYMBOL(str) SYMBOL_PREFIX #str +#else +#define SYMBOL(str) #str +#endif + +int globvar; + +static void +begin (void) +{ +} + +/* Called from asm. */ +static void __attribute__((used)) +func (void) +{ +} + +static void +marker (int anarg) +{ + /* `set_point' is the label at which to set a fast tracepoint. The + insn at the label must be large enough to fit a fast tracepoint + jump. */ + asm (" .global " SYMBOL (set_point) "\n" + SYMBOL (set_point) ":\n" +#if (defined __x86_64__ || defined __i386__) + " call " SYMBOL (func) "\n" +#endif + ); +} + +static void +end (void) +{ +} + +int +main () +{ + begin (); + + for (globvar = 1; globvar < 11; ++globvar) + marker (globvar * 100); + + end (); + return 0; +} diff --git a/gdb/testsuite/gdb.trace/trace-condition.exp b/gdb/testsuite/gdb.trace/trace-condition.exp new file mode 100644 index 0000000..d10fa9a --- /dev/null +++ b/gdb/testsuite/gdb.trace/trace-condition.exp @@ -0,0 +1,168 @@ +# Copyright 2011-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 . + +load_lib "trace-support.exp" + +standard_testfile +set executable $testfile +set expfile $testfile.exp + +# Some targets have leading underscores on assembly symbols. +set additional_flags [gdb_target_symbol_prefix_flags] + +if [is_amd64_regs_target] { + set pcreg "\$rip" +} elseif [is_x86_like_target] { + set pcreg "\$eip" +} else { + set pcreg "\$pc" +} + +if [prepare_for_testing $expfile $executable $srcfile \ + [list debug $additional_flags]] { + untested "failed to prepare for trace tests" + return -1 +} + +if ![runto_main] { + fail "Can't run to main to check for trace support" + return -1 +} + +if ![gdb_target_supports_trace] { + unsupported "target does not support trace" + return -1 +} + +set libipa [get_in_proc_agent] +gdb_load_shlibs $libipa + +# Can't use prepare_for_testing, because that splits compiling into +# building objects and then linking, and we'd fail with "linker input +# file unused because linking not done" when building the object. + +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \ + executable [list debug $additional_flags shlib=$libipa] ] != "" } { + untested "failed to compile ftrace tests" + return -1 +} + +clean_restart ${executable} + +if ![runto_main] { + fail "Can't run to main for ftrace tests" + return 0 +} + +if { [gdb_test "info sharedlibrary" ".*${libipa}.*" "IPA loaded"] != 0 } { + untested "Could not find IPA lib loaded" + return 1 +} + +proc test_tracepoints { trace_command condition num_frames { kfail_proc 0 } } { + global executable gdb_prompt + + clean_restart ${executable} + + if ![runto_main] { + fail "Can't run to main for ftrace tests" + return 0 + } + + gdb_test "break begin" ".*" "" + + gdb_test "break end" ".*" "" + + with_test_prefix "${trace_command}: ${condition}" { + + gdb_test "${trace_command} set_point if ${condition}" \ + "\(Fast t|T\)racepoint .*" \ + "set tracepoint" + + gdb_test "continue" ".*Breakpoint \[0-9\]+, begin .*" \ + "advance to trace begin" + + gdb_test_no_output "tstart" "start trace experiment" + + gdb_test_multiple "continue" "advance through tracing" { + -re ".*Breakpoint \[0-9\]+, end .*$gdb_prompt $" { + pass "advance through tracing" + } + -re "Program received signal SIGSEGV, Segmentation fault\\..*$gdb_prompt $" { + if { $kfail_proc != 0 } { + $kfail_proc $trace_command + } + fail "advance through tracing" + } + } + + if { $kfail_proc != 0 } { + $kfail_proc $trace_command + } + gdb_test "tstatus" \ + ".*Trace .*Collected $num_frames .*" \ + "check $num_frames frames were collected." + + gdb_test "tstop" "" "" + } +} + +# These callbacks identify known failures for certain architectures. They +# are called either if GDBserver crashes or has not traced the correct +# number of frames. + +proc 18955_x86_64_failure { trace_command } { + if { $trace_command == "ftrace" } { + setup_kfail "gdb/18955" "x86_64-*-linux*" + } +} + +proc 18955_i386_failure { trace_command } { + if { $trace_command == "ftrace" } { + setup_kfail "gdb/18955" "i\[34567\]86-*-*" + } +} + +foreach trace_command { "trace" "ftrace" } { + # This condition is always true as the PC should be set to the tracepoint + # address when hit. + test_tracepoints $trace_command "$pcreg == *set_point" 10 + + # Can we read local variables? + test_tracepoints $trace_command "anarg == 100 || anarg == 200" 2 18955_x86_64_failure + # Can we read global variables? + test_tracepoints $trace_command "anarg == 100 && globvar == 1" 1 18955_x86_64_failure + + # Test various operations to cover as many opcodes as possible. + test_tracepoints $trace_command "21 + 21 == 42" 10 + test_tracepoints $trace_command "21 - 21 == 0" 10 + test_tracepoints $trace_command "21 * 2 == 42" 10 + test_tracepoints $trace_command "21 << 1 == 42" 10 + test_tracepoints $trace_command "42 >> 1 == 21" 10 + test_tracepoints $trace_command "-21 << 1 == -42" 10 + test_tracepoints $trace_command "-42 >> 1 == -21" 10 + test_tracepoints $trace_command "(0xabababab & 0x0000ffff) == 0xabab" 10 + test_tracepoints $trace_command "(0xabababab | 0x0000ffff) == 0xababffff" 10 + test_tracepoints $trace_command "(0xaaaaaaaa ^ 0x55555555) == 0xffffffff" 10 + test_tracepoints $trace_command "~0xaaaaaaaa == 0x55555555" 10 + test_tracepoints $trace_command "21 < 42" 10 + test_tracepoints $trace_command "42 <= 42" 10 + test_tracepoints $trace_command "42 >= 42" 10 + test_tracepoints $trace_command "42 > 21" 10 + test_tracepoints $trace_command "(21 < 42 ? 0 : 1) == 0" 10 18955_i386_failure + test_tracepoints $trace_command "(42 <= 42 ? 0 : 1) == 0" 10 + test_tracepoints $trace_command "(42 >= 42 ? 0 : 1) == 0" 10 + test_tracepoints $trace_command "(42 > 21 ? 0 : 1) == 0" 10 18955_i386_failure + test_tracepoints $trace_command "\$trace_timestamp >= 0" 10 +}