aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorYao Qi <yao.qi@linaro.org>2017-12-08 17:27:03 +0000
committerYao Qi <yao.qi@linaro.org>2017-12-08 17:27:03 +0000
commita738ea1d41daeec0cccb4ab6671f4f6d53bd9e18 (patch)
tree774250556f5e1468e539e5726014a277d17f6327 /gdb/testsuite
parent8e481c3ba86e512b39b16b41de24e87a17f7d968 (diff)
downloadbinutils-a738ea1d41daeec0cccb4ab6671f4f6d53bd9e18.zip
binutils-a738ea1d41daeec0cccb4ab6671f4f6d53bd9e18.tar.gz
binutils-a738ea1d41daeec0cccb4ab6671f4f6d53bd9e18.tar.bz2
Clear non-significant bits of address on memory access
ARMv8 supports tagged address, that is, the top one byte in address is ignored. It is always enabled on aarch64-linux. See https://www.kernel.org/doc/Documentation/arm64/tagged-pointers.txt The tag in the tagged address is modeled as non-significant bits in address, so this patch adds a new gdbarch method significant_addr_bit and clear the non-significant bits (the top byte in ARMv8) of the virtual address at the point before passing address to target cache layer. IOW, the address used in the target cache layer is already cleared. Before this patch, (gdb) x/x 0x0000000000411030 0x411030 <global>: 0x00000000 (gdb) x/x 0xf000000000411030 0xf000000000411030: Cannot access memory at address 0xf000000000411030 After this patch, (gdb) x/x 0x0000000000411030 0x411030 <global>: 0x00000000 (gdb) x/x 0xf000000000411030 0xf000000000411030: 0x00000000 Note that I used address_significant in paddress, but it causes a regression gdb.base/long_long.exp, because gdb clears the non-significant bits in address, but test still expects them. p/a val.oct^M $24 = 0x2ee53977053977^M (gdb) FAIL: gdb.base/long_long.exp: p/a val.oct so I defer the change there. gdb: 2017-12-08 Yao Qi <yao.qi@linaro.org> * aarch64-tdep.c (aarch64_gdbarch_init): Install gdbarch significant_addr_bit. * gdbarch.sh (significant_addr_bit): New. * gdbarch.c, gdbarch.h: Re-generated. * target.c (memory_xfer_partial): Call address_significant. * utils.c (address_significant): New function. * utils.h (address_significant): Declare. 2017-12-08 Yao Qi <yao.qi@linaro.org> gdb/testsuite: * gdb.arch/aarch64-tagged-pointer.c: New file. * gdb.arch/aarch64-tagged-pointer.exp: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-tagged-pointer.c48
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-tagged-pointer.exp67
3 files changed, 120 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 720a9ec..cc834de 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-12-08 Yao Qi <yao.qi@linaro.org>
+
+ * gdb.arch/aarch64-tagged-pointer.c: New file.
+ * gdb.arch/aarch64-tagged-pointer.exp: New file.
+
2017-12-08 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.arch/i386-sse-stack-align.exp: Cast "print" function call
diff --git a/gdb/testsuite/gdb.arch/aarch64-tagged-pointer.c b/gdb/testsuite/gdb.arch/aarch64-tagged-pointer.c
new file mode 100644
index 0000000..7c90132
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-tagged-pointer.c
@@ -0,0 +1,48 @@
+/* This file is part of GDB, the GNU debugger.
+
+ Copyright 2017 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 <stdint.h>
+
+struct s
+{
+ int i;
+};
+
+static void
+foo (void)
+{
+}
+
+int
+main (void)
+{
+ struct s s1;
+ struct s *sp1, *sp2;
+ int i = 1234;
+ int *p1, *p2;
+
+ s1.i = 1234;
+ sp1 = &s1;
+ p1 = &i;
+ /* SP1 and SP2 have different tags, but point to the same address. */
+ sp2 = (struct s *) ((uintptr_t) sp1 | 0xf000000000000000ULL);
+ p2 = (int *) ((uintptr_t) p1 | 0xf000000000000000ULL);
+
+ void (*func_ptr) (void) = foo;
+ func_ptr = (void (*) (void)) ((uintptr_t) func_ptr | 0xf000000000000000ULL);
+ sp2->i = 4321; /* breakpoint here. */
+}
diff --git a/gdb/testsuite/gdb.arch/aarch64-tagged-pointer.exp b/gdb/testsuite/gdb.arch/aarch64-tagged-pointer.exp
new file mode 100644
index 0000000..4f2b44c
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-tagged-pointer.exp
@@ -0,0 +1,67 @@
+# Copyright 2017 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/>.
+#
+# This file is part of the gdb testsuite.
+
+if {![is_aarch64_target]} {
+ verbose "Skipping ${gdb_test_file_name}."
+ return
+}
+
+standard_testfile
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
+ return -1
+}
+
+if ![runto_main] {
+ untested "could not run to main"
+ return -1
+}
+
+gdb_breakpoint [gdb_get_line_number "breakpoint here"]
+gdb_continue_to_breakpoint "breakpoint here"
+
+# Test that GDB manages caches correctly for tagged address.
+# Read from P2,
+gdb_test "x p2" "$hex:\[\t \]+0x000004d2"
+gdb_test_no_output "set variable i = 5678"
+# Test that *P2 is updated.
+gdb_test "x p2" "$hex:\[\t \]+0x0000162e"
+
+# Read from SP1->i,
+gdb_test "print sp1->i" " = 1234"
+# Write to SP2->i,
+gdb_test_no_output "set variable sp2->i = 5678"
+# Test that SP1->i is updated.
+gdb_test "print sp1->i" " = 5678"
+
+gdb_test "x/d &sp2->i" "$hex:\[\t \]+5678"
+gdb_test "x/d &sp1->i" "$hex:\[\t \]+5678"
+
+# Test that the same disassembly is got when disassembling function vs
+# tagged function pointer.
+set insn1 ""
+set insn2 ""
+set test "disassemble foo,+8"
+gdb_test_multiple $test $test {
+ -re ":\[\t \]+(\[a-z\]*)\[ \r\n\]+.*:\[\t \]+(\[a-z\]*).*$gdb_prompt $" {
+ set insn1 $expect_out(1,string)
+ set insn2 $expect_out(2,string)
+ pass $test
+ }
+}
+
+gdb_test "disassemble func_ptr,+8" \
+ ":\[\t \]+$insn1\[ \r\n\]+.*:\[\t \]+$insn2.*"