From patchwork Fri Jun 12 15:09:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Simmons X-Patchwork-Id: 7145 Received: (qmail 91351 invoked by alias); 12 Jun 2015 15:09:29 -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 91136 invoked by uid 89); 12 Jun 2015 15:09:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: lwfs1-cam.cam.lispworks.com Received: from mail.lispworks.com (HELO lwfs1-cam.cam.lispworks.com) (46.17.166.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 12 Jun 2015 15:09:27 +0000 Received: from higson.cam.lispworks.com (higson.cam.lispworks.com [192.168.1.7]) by lwfs1-cam.cam.lispworks.com (8.14.5/8.14.5) with ESMTP id t5CF9Kst021356; Fri, 12 Jun 2015 16:09:20 +0100 (BST) (envelope-from martin@lispworks.com) Received: from higson.cam.lispworks.com (localhost.localdomain [127.0.0.1]) by higson.cam.lispworks.com (8.14.4) id t5CF9Jst012573; Fri, 12 Jun 2015 16:09:19 +0100 Received: (from martin@localhost) by higson.cam.lispworks.com (8.14.4/8.14.4/Submit) id t5CF9JUg012570; Fri, 12 Jun 2015 16:09:19 +0100 Date: Fri, 12 Jun 2015 16:09:19 +0100 Message-Id: <201506121509.t5CF9JUg012570@higson.cam.lispworks.com> From: Martin Simmons To: Joel Brobecker CC: gdb-patches@sourceware.org In-reply-to: <20150612132113.GC2609@adacore.com> (message from Joel Brobecker on Fri, 12 Jun 2015 09:21:13 -0400) Subject: Re: [PATCH] Prevent internal-error when computing $pc in ARM assembly code References: <201505200949.t4K9nlqt015737@heapu.cam.lispworks.com> <20150609184408.GG2855@adacore.com> <201506111725.t5BHP5LR031293@higson.cam.lispworks.com> <20150612132113.GC2609@adacore.com> >>>>> 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 . */ + + .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 . + +# 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"