From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3764 invoked by alias); 30 May 2012 20:44:26 -0000 Received: (qmail 3745 invoked by uid 22791); 30 May 2012 20:44:20 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 30 May 2012 20:44:03 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q4UKhxZg012956 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 30 May 2012 16:44:00 -0400 Received: from host2.jankratochvil.net (ovpn-116-47.ams2.redhat.com [10.36.116.47]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q4UKhkXi018469 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 30 May 2012 16:43:49 -0400 Date: Wed, 30 May 2012 20:44:00 -0000 From: Jan Kratochvil To: markus.t.metzger@intel.com Cc: kettenis@gnu.org, gdb-patches@sourceware.org, markus.t.metzger@gmail.com Subject: Re: [PATCH 11/16] test, btrace: add branch trace tests Message-ID: <20120530204346.GI20633@host2.jankratochvil.net> References: <1337772151-20265-1-git-send-email-markus.t.metzger@intel.com> <1337772151-20265-12-git-send-email-markus.t.metzger@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1337772151-20265-12-git-send-email-markus.t.metzger@intel.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-05/txt/msg01064.txt.bz2 On Wed, 23 May 2012 13:22:26 +0200, markus.t.metzger@intel.com wrote: > --- a/.gitignore > +++ b/.gitignore > @@ -38,3 +38,5 @@ lost+found > > *.log > *.sum > + > +gdb/testsuite/gdb.btrace/list.x This is excessive. > diff --git a/gdb/testsuite/configure.ac b/gdb/testsuite/configure.ac > index d9ab9f7..164a505 100644 > --- a/gdb/testsuite/configure.ac > +++ b/gdb/testsuite/configure.ac > @@ -98,4 +98,4 @@ AC_OUTPUT([Makefile \ > gdb.mi/Makefile gdb.modula2/Makefile gdb.multi/Makefile \ > gdb.objc/Makefile gdb.opencl/Makefile gdb.opt/Makefile gdb.pascal/Makefile \ > gdb.python/Makefile gdb.reverse/Makefile gdb.stabs/Makefile \ > - gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile]) > + gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile gdb.btrace/Makefile]) > diff --git a/gdb/testsuite/gdb.btrace/Makefile.in b/gdb/testsuite/gdb.btrace/Makefile.in > new file mode 100755 > index 0000000..16afe0a > --- /dev/null > +++ b/gdb/testsuite/gdb.btrace/Makefile.in > @@ -0,0 +1,13 @@ > +VPATH = @srcdir@ > +srcdir = @srcdir@ > + > +.PHONY: all clean mostlyclean distclean realclean > + > +all info install-info dvi install uninstall installcheck check: > + @echo "Nothing to be done for $@..." > + > +clean mostlyclean: > + -rm -f *.o *.x *.diff *~ *.bad core > + > +distclean maintainer-clean realclean: clean > + -rm -f Makefile config.status config.log gdb.log gdb.sum > diff --git a/gdb/testsuite/gdb.btrace/dec.c b/gdb/testsuite/gdb.btrace/dec.c > new file mode 100644 > index 0000000..abe1ff5 > --- /dev/null > +++ b/gdb/testsuite/gdb.btrace/dec.c > @@ -0,0 +1,4 @@ Missing copyright header. > +extern int dec (int x) > +{ > + return x - 1; > +} > diff --git a/gdb/testsuite/gdb.btrace/enable.exp b/gdb/testsuite/gdb.btrace/enable.exp > new file mode 100644 > index 0000000..a312ee3 > --- /dev/null > +++ b/gdb/testsuite/gdb.btrace/enable.exp > @@ -0,0 +1,83 @@ > +# Copyright 2012 Free Software Foundation, Inc. > +# > +# Contributed by Intel Corp. > +# > +# 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 . > + > +if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } { > + verbose "Tests ignored for all but x86 based targets." > + return > +} > + > +load_lib btrace.exp > + > +set testfile "list" > + > +# check for btrace support > +if { [skip_btrace_tests] } { continue } > + > +# start fresh - without an executable > +gdb_exit > +gdb_start > + > + > +# automatic enabling can be turned on without an inferior > +gdb_test_no_output "btrace enable auto" "btrace enable 1.0" > + > +# we cannot enable it twice > +gdb_test "btrace enable auto" "Automatic branch trace enabling already on." "btrace enable 1.1" > + > +# but we can disable it > +gdb_test_no_output "btrace disable auto" "btrace enable 1.2" > + > +# we cannot disable it twice > +gdb_test "btrace disable auto" "Automatic branch trace enabling already off." "btrace enable 1.3" > + > +# we cannot enable/disable trace without a thread > +gdb_test "btrace enable" "Couldn't enable branch tracing: no inferior thread." "btrace enable 2.0" > +gdb_test "btrace disable" "Couldn't disable branch tracing: no inferior thread." "btrace enable 2.1" > + > + > +# start a debuggee program > +if { [set binfile [btrace_assemble ${testfile}]] == "" } { > + untested ${testfile}.exp > + return -1 > +} > + > +gdb_reinitialize_dir $srcdir/$subdir > +gdb_load $binfile > + > +# automatic enabling is off. > +runto test_1 > + > +# since we support btrace, we should be able to enable it > +gdb_test_no_output "btrace enable" "btrace enable 3.0" > + > +# btrace is now enabled; we should not be able to enable it twice > +gdb_test "btrace enable" "Couldn't enable branch tracing.*" "btrace enable 3.1" > + > +# btrace is still enabled; we should be able to disable it > +gdb_test_no_output "btrace disable" "btrace enable 3.2" > + > +# btrace is now disabled; we should not be able to disable it twice > +gdb_test "btrace disable" "Couldn't disable branch tracing.*" "btrace enable 3.3" > + > +# rerun with automatic enabling on > +gdb_test_no_output "btrace enable auto" > +runto test_1 > + > +# btrace is implicitly enabled; we should not be able to enable it twice > +gdb_test "btrace enable" "Couldn't enable branch tracing.*" "btrace enable 4.0" > + > +return 0 > diff --git a/gdb/testsuite/gdb.btrace/inc.c b/gdb/testsuite/gdb.btrace/inc.c > new file mode 100644 > index 0000000..03966f3 > --- /dev/null > +++ b/gdb/testsuite/gdb.btrace/inc.c > @@ -0,0 +1,4 @@ > +extern int inc (int x) > +{ > + return x + 1; > +} > diff --git a/gdb/testsuite/gdb.btrace/list.exp b/gdb/testsuite/gdb.btrace/list.exp > new file mode 100644 > index 0000000..de33b59 > --- /dev/null > +++ b/gdb/testsuite/gdb.btrace/list.exp > @@ -0,0 +1,169 @@ > +# Copyright 2012 Free Software Foundation, Inc. > +# > +# Contributed by Intel Corp. > +# > +# 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 . > + > +if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } { > + verbose "Tests ignored for all but x86 based targets." > + return > +} > + > +load_lib btrace.exp > + > +set testfile "list" > + > +# check for btrace support > +if { [skip_btrace_tests] } { continue } > + > +# start fresh - without an executable > +gdb_exit > +gdb_start > + > +if { [set binfile [btrace_assemble ${testfile}]] == "" } { > + untested ${testfile}.exp > + return -1 > +} > + > +gdb_reinitialize_dir $srcdir/$subdir > +gdb_load $binfile > + > +# Automatically enable branch tracing. > +gdb_test_no_output "btr enable auto" > + > +# Make sure we don't die when enabling trace for a newly created thread. > +runto test_1 > +# we expect some trace at this point, but we don't really know how much or how > +# it would look like. Ignore it. > + > +# Reset branch trace so we get predictable output. > +btrace_reset_trace > + > +gdb_test "stepi" "0x0*400200 in test_1_sub.*" "" > + > +gdb_test "btr list /af" " > +1 *0x0*400200 - 0x0*400200 in test_1_sub \\(\\)" "btrace list 1.1" > + > +# We assume 5 bytes for call. > +gdb_test "stepi" "0x0*400215 in test_1.*" "" > + > +# We assume 5 bytes for call. > +gdb_test "btr list /af" " > +1 *0x0*400215 - 0x0*400215 in test_1 \\(\\)\r > +2 *0x0*400200 - 0x0*400200 in test_1_sub \\(\\)" "btrace list 1.2" > + > +gdb_test "stepi" "0x0*400200 in test_1_sub.*" "" > +gdb_test "stepi" "0x0*40021a in test_1.*" "" > + > +# We assume 5 bytes for call. > +gdb_test "btr list /af" " > +1 *0x0*40021a - 0x0*40021a in test_1 \\(\\)\r > +2 *0x0*400200 - 0x0*400200 in test_1_sub \\(\\)\r > +3 *0x0*400215 - 0x0*400215 in test_1 \\(\\)\r > +4 *0x0*400200 - 0x0*400200 in test_1_sub \\(\\)" "btrace list 1.3" > + > +# List a single block. > +gdb_test "btr list /af 2" " > +2 *0x0*400200 - 0x0*400200 in test_1_sub \\(\\)" "btrace list 1.4" > + > +# List a range of blocks. > +gdb_test "btr list /af 2-4" " > +2 *0x0*400200 - 0x0*400200 in test_1_sub \\(\\)\r > +3 *0x0*400215 - 0x0*400215 in test_1 \\(\\)\r > +4 *0x0*400200 - 0x0*400200 in test_1_sub \\(\\)" "btrace list 1.5" > + > +# We ignore too big upper bounds. > +gdb_test "btr list /af 3-9" " > +3 *0x0*400215 - 0x0*400215 in test_1 \\(\\)\r > +4 *0x0*400200 - 0x0*400200 in test_1_sub \\(\\)" "btrace list 1.6" > + > +# If the entire range is out of bounds, the list is empty. > +gdb_test "btr list /a 9-18" "" "btrace list 1.7" > + > +# Check modifiers individually > +gdb_test "btr list /a 2" " > +2 *0x0*400200 - 0x0*400200" "btrace list 1.8" > + > +gdb_test "btr list /f 2" " > +2 *in test_1_sub \\(\\)" "btrace list 1.9" > + > +# Check order of modifiers > +gdb_test "btr list /fa 2" " > +2 *0x0*400200 - 0x0*400200 in test_1_sub \\(\\)" "btrace list 1.10" > + > +gdb_test "btr list /f /a 2" " > +2 *0x0*400200 - 0x0*400200 in test_1_sub \\(\\)" "btrace list 1.11" > + > +gdb_test "btr list /a /f 2" " > +2 *0x0*400200 - 0x0*400200 in test_1_sub \\(\\)" "btrace list 1.12" > + > + > +# Proceed to the next test. > +runto test_2 > + > +# Reset branch trace so we get predictable output. > +btrace_reset_trace > + > +# We assume 1 byte for nop. > +gdb_test "stepi" "0x0*400231 in test_2.*" "" > + > +# We have not seen a branch, yet, so there is no trace. > +gdb_test "btr list" "No trace." "btrace list 2.1" > + > +gdb_test "stepi" "0x0*400220 in test_2_sub.*" "" > + > +gdb_test "btr list /af" " > +1 *0x0*400220 - 0x0*400220 in test_2_sub \\(\\)" "btrace list 2.2" > + > +# We assume 1 byte for nop. > +gdb_test "stepi" "0x0*400221 in test_2_sub.*" "" > + > +# We assume 1 byte for nop. > +gdb_test "btr list /af" " > +1 *0x0*400220 - 0x0*400221 in test_2_sub \\(\\)" "btrace list 2.3" > + > +# We assume 1 byte for nop. > +gdb_test "stepi" "0x0*400222 in test_2_sub.*" "" > + > +# We assume 1 byte for nop. > +gdb_test "btr list /af" " > +1 *0x0*400220 - 0x0*400222 in test_2_sub \\(\\)" "btrace list 2.4" > + > + > +# Proceed to the next test. > +runto test_3 > + > +# Reset branch trace so we get predictable output. > +btrace_reset_trace > + > +gdb_test "stepi" "0x0*400260 in test_3.*" "" > + > +gdb_test "btr list /af" " > +1 *0x0*400260 - 0x0*400260 in test_3 \\(\\)" "btrace list 3.1" > + > +gdb_test "stepi" "0x0*400250 in test_3.*" "" > + > +gdb_test "btr list /af" " > +1 *0x0*400250 - 0x0*400250 in test_3 \\(\\)\r > +2 *0x0*400260 - 0x0*400260 in test_3 \\(\\)" "btrace list 3.2" > + > +# We assume 1 byte for nop. > +gdb_test "stepi" "0x0*400251 in test_3.*" "" > + > +# We assume 1 byte for nop. > +gdb_test "btr list /af" " > +1 *0x0*400250 - 0x0*400251 in test_3 \\(\\)\r > +2 *0x0*400260 - 0x0*400260 in test_3 \\(\\)" "btrace list 3.3" > + > +return 0 > diff --git a/gdb/testsuite/gdb.btrace/list.s b/gdb/testsuite/gdb.btrace/list.s > new file mode 100644 > index 0000000..7659a8b > --- /dev/null > +++ b/gdb/testsuite/gdb.btrace/list.s It should end with .S as it is used in GDB. It should have i386 in its name as it is x86-specific file. > @@ -0,0 +1,68 @@ > +# Copyright 2012 Free Software Foundation, Inc. > +# > +# Contributed by Intel Corp. > +# > +# 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 . > + > + .text > + .globl _start > + .globl main > + .globl test_1 > + .globl test_2 > + .globl test_3 > + .align 0x100 # 0x400100 > +_start: > + call main > + hlt > + > + .align 0x10 # 0x400110 > +main: > + call test_1 > + call test_2 > + call test_3 > + ret > + > + .align 0x100 # 0x400200 > +test_1_sub: > + ret > + > + .align 0x10 # 0x400210 > +test_1: > + call test_1_sub > + call test_1_sub > + nop > + ret > + > + .align 0x10 # 0x400220 > +test_2_sub: > + nop > + nop > + ret > + > + .align 0x10 # 0x400230 > +test_2: > + nop > + call test_2_sub > + ret > + > + .align 0x10 # 0x400240 > +test_3: > + jmp .L3.1 > + .align 0x10 # 0x400250 > +.L3.2: > + nop > + ret > + .align 0x10 # 0x400260 > +.L3.1: > + jmp .L3.2 > diff --git a/gdb/testsuite/gdb.btrace/list_function.c b/gdb/testsuite/gdb.btrace/list_function.c > new file mode 100644 > index 0000000..0372126 > --- /dev/null > +++ b/gdb/testsuite/gdb.btrace/list_function.c > @@ -0,0 +1,12 @@ Missing copyright header. > +extern int inc (int); > +extern int dec (int); > + > +extern int main (void) > +{ > + int x = 0; > + > + x = inc (x); > + x = dec (x); > + > + return x; /* End of main breakpoint location */ > +} > diff --git a/gdb/testsuite/gdb.btrace/list_function.exp b/gdb/testsuite/gdb.btrace/list_function.exp > new file mode 100644 > index 0000000..9585289 > --- /dev/null > +++ b/gdb/testsuite/gdb.btrace/list_function.exp > @@ -0,0 +1,59 @@ > +# Copyright 2012 Free Software Foundation, Inc. > +# > +# Contributed by Intel Corp. > +# > +# 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 btrace.exp > + > +set testfile "list_function" > +set srcfile ${testfile}.c > +set binfile ${objdir}/${subdir}/${testfile}.x > + > +set sources "${srcdir}/${subdir}/${srcfile} ${srcdir}/${subdir}/inc.c ${srcdir}/${subdir}/dec.c" > + > +# check for btrace support > +if { [skip_btrace_tests] } { continue } > + > +if { [gdb_compile "${sources}" "${binfile}" executable {debug}] != "" } { > + untested list_function.exp > + return -1 > +} > +# start fresh - without an executable > +gdb_exit > +gdb_start > + > +gdb_reinitialize_dir $srcdir/$subdir > +gdb_load $binfile Why not to use prepare_for_testing here? > + > +if ![runto_main] then { > + fail "Can't run to main" > + return 0 > +} > + > +set bp_location [gdb_get_line_number "End of main breakpoint location"] > + > +gdb_breakpoint $bp_location > + > +gdb_test_no_output "btr enable" > + > +gdb_continue_to_breakpoint "cont to $bp_location" ".*$srcfile:$bp_location.*" > + > +gdb_test "btr list /f" " > +1 *in main \\(\\)\r > +2 *in dec \\(\\)\r > +3 *in main \\(\\)\r > +4 *in inc \\(\\)" "btrace list function 1.0" > + > +return 0 > diff --git a/gdb/testsuite/lib/btrace.exp b/gdb/testsuite/lib/btrace.exp > new file mode 100644 > index 0000000..92ca50f > --- /dev/null > +++ b/gdb/testsuite/lib/btrace.exp > @@ -0,0 +1,72 @@ > +# Copyright 2012 Free Software Foundation, Inc. > +# > +# Contributed by Intel Corp. > +# > +# 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 . > + > +proc btrace_assemble { testfile } { > + global srcdir > + global objdir > + global subdir > + > + set srcfile ${srcdir}/${subdir}/${testfile}.s > + set objfile ${objdir}/${subdir}/${testfile}.o > + set binfile ${objdir}/${subdir}/${testfile}.x > + > + if {[target_assemble ${srcfile} ${objfile} ""] != ""} { return "" } > + > + if {[target_link ${objfile} ${binfile} "-Ttext 0x400100"] != ""} { return "" } > + > + return ${binfile} > +} > + > +proc skip_btrace_tests {} { > + global gdb_prompt > + > + set testfile "list" > + set skip 0 > + > + if { [set binfile [btrace_assemble ${testfile}]] == "" } { > + return 1 > + } > + > + gdb_exit > + gdb_start > + gdb_load $binfile > + > + runto main Rather always check for 'runto' error codes, it sometimes happens and the rest of testfile does not recover well in such case. > + > + gdb_test_multiple "btrace enable" "check btrace support" { > + -re "You can't do that when your target is.*" { Missing termination: -re "You can't do that when your target is.*\r\n$gdb_prompt $" { As otherwise it will be racy, the leftover prompt can be read in by next gdb_test. > + unsupported "target does not support btrace" > + set skip 1 Here should be: xfail "check btrace support" > + } > + -re "Couldn't enable branch tracing.*Operation not supported" { Again. > + unsupported "target does not support btrace" > + set skip 1 Here should be: xfail "check btrace support" > + } > + -re "$gdb_prompt $" {} One may disagree but I think this block should contain: pass "check btrace support" > + } > + gdb_exit > + remote_file build delete $testfile > + > + return $skip > +} > + > +proc btrace_reset_trace {} { > + gdb_test_no_output "btr disable" > + gdb_test_no_output "btr enable" > + > + gdb_test "btr list" "No trace." "reset btrace" For real correctness either gdb_test "btr list" "No trace\\." "reset btrace" or: gdb_test "btr list" {No trace\.} "reset btrace" > +} > -- > 1.7.1 Thanks, Jan