This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 11/16] test, btrace: add branch trace tests


From: Markus Metzger <markus.t.metzger@intel.com>

Add tests covering btrace enable/disable/auto and btrace list.

2012-05-23 Markus Metzger <markus.t.metzger@intel.com>

  * .gitignore: add gdb/testsuite/gdb.btrace/list.x

  gdb/testsuite/
  * configure.ac: Add gdb.btrace makefile

  gdb/testsuite/lib/
  * btrace.exp: New file

  gdb/testsuite/gdb.btrace/
  * Makefile.in: New file
  * enable.exp: New file
  * list.exp: New file
  * list.s: New file


---
 .gitignore                                 |    2 +
 gdb/testsuite/configure.ac                 |    2 +-
 gdb/testsuite/gdb.btrace/Makefile.in       |   13 ++
 gdb/testsuite/gdb.btrace/dec.c             |    4 +
 gdb/testsuite/gdb.btrace/enable.exp        |   83 ++++++++++++++
 gdb/testsuite/gdb.btrace/inc.c             |    4 +
 gdb/testsuite/gdb.btrace/list.exp          |  169 ++++++++++++++++++++++++++++
 gdb/testsuite/gdb.btrace/list.s            |   68 +++++++++++
 gdb/testsuite/gdb.btrace/list_function.c   |   12 ++
 gdb/testsuite/gdb.btrace/list_function.exp |   59 ++++++++++
 gdb/testsuite/lib/btrace.exp               |   72 ++++++++++++
 11 files changed, 487 insertions(+), 1 deletions(-)
 create mode 100755 gdb/testsuite/gdb.btrace/Makefile.in
 create mode 100644 gdb/testsuite/gdb.btrace/dec.c
 create mode 100644 gdb/testsuite/gdb.btrace/enable.exp
 create mode 100644 gdb/testsuite/gdb.btrace/inc.c
 create mode 100644 gdb/testsuite/gdb.btrace/list.exp
 create mode 100644 gdb/testsuite/gdb.btrace/list.s
 create mode 100644 gdb/testsuite/gdb.btrace/list_function.c
 create mode 100644 gdb/testsuite/gdb.btrace/list_function.exp
 create mode 100644 gdb/testsuite/lib/btrace.exp

diff --git a/.gitignore b/.gitignore
index dc1bf3f..94e43b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,3 +38,5 @@ lost+found
 
 *.log
 *.sum
+
+gdb/testsuite/gdb.btrace/list.x
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 @@
+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. <markus.t.metzger@intel.com>
+#
+# 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/>.
+
+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. <markus.t.metzger@intel.com>
+#
+# 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/>.
+
+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
@@ -0,0 +1,68 @@
+# Copyright 2012 Free Software Foundation, Inc.
+#
+# Contributed by Intel Corp. <markus.t.metzger@intel.com>
+#
+# 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/>.
+
+        .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 @@
+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. <markus.t.metzger@intel.com>
+#
+# 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 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
+
+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. <markus.t.metzger@intel.com>
+#
+# 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/>.
+
+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
+
+    gdb_test_multiple "btrace enable" "check btrace support" {
+        -re "You can't do that when your target is.*" {
+            unsupported "target does not support btrace"
+            set skip 1
+        }
+        -re "Couldn't enable branch tracing.*Operation not supported" {
+            unsupported "target does not support btrace"
+            set skip 1
+        }
+        -re "$gdb_prompt $" {}
+    }
+    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"
+}
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]