From: Martin Simmons <martin@lispworks.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Prevent internal-error when computing $pc in ARM assembly code
Date: Fri, 12 Jun 2015 15:09:00 -0000 [thread overview]
Message-ID: <201506121509.t5CF9JUg012570@higson.cam.lispworks.com> (raw)
In-Reply-To: <20150612132113.GC2609@adacore.com> (message from Joel Brobecker on Fri, 12 Jun 2015 09:21:13 -0400)
>>>>> On Fri, 12 Jun 2015 09:21:13 -0400, Joel Brobecker said:
>
> Looks good. A few little things in your new testcase...
>
> > +++ b/gdb/testsuite/gdb.arch/arm-r11-non-pointer.S
> > @@ -0,0 +1,45 @@
> > +/* Copyright 2010-2015 Free Software Foundation, Inc.
>
> Did you really mean for the date range to be 2010-2015?
> If yes, then great. If not, can you adjust it?
I started with the code from another testcase, but it has pretty much all been
rewriten now so I've adjusted it to be 2015.
> > +set testfile "arm-r11-non-pointer"
> > +set srcfile ${testfile}.S
> > +set binfile ${objdir}/${subdir}/${testfile}
>
> Can you use "standard_testfile .S" instead of the 3 commands above?
>
> > +set additional_flags "-Wa,-g"
> > +
> > +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $additional_flags]] != "" } {
> > + untested arm-r11-non-pointer.exp
> > + return -1
> > +}
> > +
> > +# Get things started.
> > +
> > +clean_restart ${testfile}
>
> Can you use prepare_for_testing instead of gdb_compile and
> clean_restart?
>
> > +gdb_test "x/i \$pc" \
> > + ".*bl.*0x.*" \
> > + "x/i pc"
> > +
> > +gdb_test "stepi" \
> > + "\\\?\\\? \\\(\\\) at .*$srcfile:.*" \
> > + "stepi"
> > +
> > +gdb_test "x/i \$pc" \
> > + ".*ldr.*r11,.*" \
> > + "x/i pc"
> > +
> > +gdb_test "stepi" \
> > + "\\\?\\\? \\\(\\\) at .*$srcfile:.*" \
> > + "stepi"
> > +
> > +gdb_test "x/i \$pc" \
> > + ".*mov.*r11,.*r11.*" \
> > + "x/i pc"
> > +
>
> We require that all test "labels" be unique. Would you mind ammending
> them to make them so. Eg: replace the first "x/i pc" by "x/i pc at
> such and such instruction", etc. Same for the "stepi" ones.
OK, all done in the new version below.
gdb/ChangeLog:
* arm-tdep.c (arm_analyze_prologue): Read memory without throwing an
exception, to allow debugging of assembly code.
gdb/testsuite/ChangeLog:
* gdb.arch/arm-r11-non-pointer.S: New file.
* gdb.arch/arm-r11-non-pointer.exp: New file.
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index c99f2a9..fd07bca 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -1669,8 +1669,12 @@ arm_analyze_prologue (struct gdbarch *gdbarch,
current_pc < prologue_end;
current_pc += 4)
{
- unsigned int insn
- = read_memory_unsigned_integer (current_pc, 4, byte_order_for_code);
+ unsigned int insn;
+ gdb_byte buf[4];
+
+ if (target_read_memory (current_pc, buf, 4))
+ break;
+ insn = extract_unsigned_integer (buf, 4, byte_order_for_code);
if (insn == 0xe1a0c00d) /* mov ip, sp */
{
diff --git a/gdb/testsuite/gdb.arch/arm-r11-non-pointer.S b/gdb/testsuite/gdb.arch/arm-r11-non-pointer.S
new file mode 100644
index 0000000..40729fb
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/arm-r11-non-pointer.S
@@ -0,0 +1,45 @@
+/* Copyright 2015 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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/>. */
+
+ .syntax unified
+ .text
+ .type main,%function
+#if defined (__thumb__)
+ .code 16
+ .thumb_func
+#endif
+
+ .align 2
+textdataregion:
+ .word dataregion
+
+ .globl main
+main:
+ stmfd sp!, {r3, lr}
+ bl .L0
+ movs r0, #0
+ ldmfd sp!, {r3, pc}
+ .size main, .-main
+
+.L0: ldr r11, textdataregion
+ mov r11, r11
+ mov pc, lr
+
+ .data
+ .align 2
+dataregion:
+ .word 64,65,66,67
diff --git a/gdb/testsuite/gdb.arch/arm-r11-non-pointer.exp b/gdb/testsuite/gdb.arch/arm-r11-non-pointer.exp
new file mode 100644
index 0000000..d633a78
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/arm-r11-non-pointer.exp
@@ -0,0 +1,60 @@
+# Copyright 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 <http://www.gnu.org/licenses/>.
+
+# This file is part of the gdb testsuite.
+
+# Test arm non-pointer in r11.
+
+if {![istarget "arm*-*-*"]} then {
+ verbose "Skipping arm r11 non-pointer tests."
+ return
+}
+
+standard_testfile .S
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} $srcfile [list debug "additional_flags=-Wa,-g"]] } {
+ return -1
+}
+
+if ![runto_main] then {
+ fail "Can't run to main"
+ return 0
+}
+
+gdb_test "x/i \$pc" \
+ ".*bl.*0x.*" \
+ "x/i pc at bl"
+
+gdb_test "stepi" \
+ "\\\?\\\? \\\(\\\) at .*$srcfile:.*" \
+ "stepi from bl to ldr"
+
+gdb_test "x/i \$pc" \
+ ".*ldr.*r11,.*" \
+ "x/i pc at ldr"
+
+gdb_test "stepi" \
+ "\\\?\\\? \\\(\\\) at .*$srcfile:.*" \
+ "stepi from ldr to mov"
+
+gdb_test "x/i \$pc" \
+ ".*mov.*r11,.*r11.*" \
+ "x/i pc at mov"
+
+##########################################
+
+# Done, run program to exit.
+
+gdb_continue_to_end "arm-r11-non-pointer"
next prev parent reply other threads:[~2015-06-12 15:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-20 9:49 Martin Simmons
2015-06-09 18:44 ` Joel Brobecker
2015-06-11 17:25 ` Martin Simmons
2015-06-12 13:21 ` Joel Brobecker
2015-06-12 15:09 ` Martin Simmons [this message]
2015-06-12 17:58 ` Joel Brobecker
2015-06-15 10:02 ` Yao Qi
2015-06-15 13:36 ` Joel Brobecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201506121509.t5CF9JUg012570@higson.cam.lispworks.com \
--to=martin@lispworks.com \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox