From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26296 invoked by alias); 1 Mar 2012 09:00:35 -0000 Received: (qmail 26278 invoked by uid 22791); 1 Mar 2012 09:00:33 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Mar 2012 09:00:16 +0000 Received: from nat-dem.mentorg.com ([195.212.93.2] helo=eu2-mail.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1S31rz-0006g5-Gz from Thomas_Schwinge@mentor.com ; Thu, 01 Mar 2012 01:00:15 -0800 Received: from feldtkeller.schwinge.homeip.net ([172.30.64.112]) by eu2-mail.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 1 Mar 2012 10:00:14 +0100 From: Thomas Schwinge To: Kevin Buettner , gdb-patches@sourceware.org Subject: Re: [PATCH] [SH] Prologue skipping if there is none In-Reply-To: <87r4xd528y.fsf@schwinge.name> References: <87pqdgciho.fsf@schwinge.name> <20120215075413.1313f7fa@mesquite.lan> <20120215165907.33f2e9a6@mesquite.lan> <8739aad9il.fsf@schwinge.name> <20120216182544.36b41a1b@mesquite.lan> <87mx8da3b9.fsf@schwinge.name> <20120220162029.2082b6a1@mesquite.lan> <87wr7c7aop.fsf@schwinge.name> <20120224144657.36bbd09f@mesquite.lan> <87r4xd528y.fsf@schwinge.name> User-Agent: Notmuch/0.9-101-g81dad07 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Thu, 01 Mar 2012 09:00:00 -0000 Message-ID: <87d38w4rxr.fsf@schwinge.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" 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-03/txt/msg00008.txt.bz2 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-length: 6248 Hi! On Wed, 29 Feb 2012 12:05:01 +0100, I wrote: > And, as already reported, there is this progression for sh-linux-gnu: >=20 > -FAIL: gdb.base/gdb1250.exp: setting breakpoint at abort > +PASS: gdb.base/gdb1250.exp: backtrace from abort >=20 > The PLT stub for abort happens to be the last one in the .plt section, > and (I suppose) your more advanced limit_pc/func_end mechanism (instead > of hard-coding 28 instructions) helps to avoid hitting the > end-of-.plt-section border. (The question is whether it really makes > sense to go looking for a prologue in a PLT stub, but that's what GDB is > currently doing, and it should be without harm.) Here is a patch to fix this ``break abort'' FAIL; no regressions for sh-linux-gnu and sh-elf. * sh-tdep.c (sh_skip_prologue): Provide an upper limit on the function prologue to sh_analyze_prologue. (sh_analyze_prologue): Make better use of such an upper limit, and generally be more cautious about accessing memory. Index: gdb/sh-tdep.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/sh-tdep.c,v retrieving revision 1.239 diff -u -p -r1.239 sh-tdep.c --- gdb/sh-tdep.c 27 Feb 2012 16:40:48 -0000 1.239 +++ gdb/sh-tdep.c 1 Mar 2012 08:48:23 -0000 @@ -534,22 +534,18 @@ sh_breakpoint_from_pc (struct gdbarch *g =20 static CORE_ADDR sh_analyze_prologue (struct gdbarch *gdbarch, - CORE_ADDR pc, CORE_ADDR current_pc, + CORE_ADDR pc, CORE_ADDR limit_pc, struct sh_frame_cache *cache, ULONGEST fpscr) { enum bfd_endian byte_order =3D gdbarch_byte_order (gdbarch); ULONGEST inst; - CORE_ADDR opc; int offset; int sav_offset =3D 0; int r3_val =3D 0; int reg, sav_reg =3D -1; =20 - if (pc >=3D current_pc) - return current_pc; - cache->uses_fp =3D 0; - for (opc =3D pc + (2 * 28); pc < opc; pc +=3D 2) + for (; pc < limit_pc; pc +=3D 2) { inst =3D read_memory_unsigned_integer (pc, 2, byte_order); /* See where the registers will be saved to. */ @@ -594,6 +590,7 @@ sh_analyze_prologue (struct gdbarch *gdb { sav_reg =3D reg; offset =3D (inst & 0xff) << 1; + /* TODO: check that this is a valid address. */ sav_offset =3D read_memory_integer ((pc + 4) + offset, 2, byte_order); } @@ -608,13 +605,15 @@ sh_analyze_prologue (struct gdbarch *gdb { sav_reg =3D reg; offset =3D (inst & 0xff) << 2; + /* TODO: check that this is a valid address. */ sav_offset =3D read_memory_integer (((pc & 0xfffffffc) + 4) + offset, 4, byte_order); } } } - else if (IS_MOVI20 (inst)) + else if (IS_MOVI20 (inst) + && (pc + 2 < limit_pc)) { if (sav_reg < 0) { @@ -623,14 +622,15 @@ sh_analyze_prologue (struct gdbarch *gdb { sav_reg =3D reg; sav_offset =3D GET_SOURCE_REG (inst) << 16; - /* MOVI20 is a 32 bit instruction! */ - pc +=3D 2; sav_offset - |=3D read_memory_unsigned_integer (pc, 2, byte_order); + |=3D read_memory_unsigned_integer (pc + 2, 2, byte_order); /* Now sav_offset contains an unsigned 20 bit value. It must still get sign extended. */ if (sav_offset & 0x00080000) sav_offset |=3D 0xfff00000; + + /* MOVI20 is a 32-bit instruction. */ + pc +=3D 2; } } } @@ -656,14 +656,16 @@ sh_analyze_prologue (struct gdbarch *gdb } else if (IS_MOV_SP_FP (inst)) { + pc +=3D 2; + limit_pc =3D min (limit_pc, pc + (2 * 6)); /* NUMERO MYSTERIOSO */ + cache->uses_fp =3D 1; /* At this point, only allow argument register moves to other registers or argument register moves to @(X,fp) which are moving the register arguments onto the stack area allocated by a former add somenumber to SP call. Don't allow moving to an fp indirect address above fp + cache->sp_offset. */ - pc +=3D 2; - for (opc =3D pc + 12; pc < opc; pc +=3D 2) + for (; pc < limit_pc; pc +=3D 2) { inst =3D read_memory_integer (pc, 2, byte_order); if (IS_MOV_ARG_TO_IND_R14 (inst)) @@ -686,7 +688,8 @@ sh_analyze_prologue (struct gdbarch *gdb } break; } - else if (IS_JSR (inst)) + else if (IS_JSR (inst) + && (pc + 2 < limit_pc)) { /* We have found a jsr that has been scheduled into the prologue. If we continue the scan and return a pc someplace after this, @@ -716,13 +719,13 @@ sh_analyze_prologue (struct gdbarch *gdb static CORE_ADDR sh_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) { - CORE_ADDR post_prologue_pc, func_addr; + CORE_ADDR post_prologue_pc, func_addr, func_end_addr, limit_pc; struct sh_frame_cache cache; =20 /* See if we can determine the end of the prologue via the symbol table. If so, then return either PC, or the PC after the prologue, whichever is greater. */ - if (find_pc_partial_function (pc, NULL, &func_addr, NULL)) + if (find_pc_partial_function (pc, NULL, &func_addr, &func_end_addr)) { post_prologue_pc =3D skip_prologue_using_sal (gdbarch, func_addr); if (post_prologue_pc !=3D 0) @@ -732,8 +735,20 @@ sh_skip_prologue (struct gdbarch *gdbarc /* Can't determine prologue from the symbol table, need to examine instructions. */ =20 + /* Find an upper limit on the function prologue using the debug + information. If the debug information could not be used to provide + that bound, then use an arbitrary large number as the upper bound. */ + limit_pc =3D skip_prologue_using_sal (gdbarch, pc); + if (limit_pc =3D=3D 0) + limit_pc =3D pc + (2 * 28); /* NUMERO MYSTERIOSO */ + + /* Do not allow limit_pc to be past the function end, if we know + where that end is... */ + if (func_end_addr !=3D 0) + limit_pc =3D min (limit_pc, func_end_addr); + cache.sp_offset =3D -4; - post_prologue_pc =3D sh_analyze_prologue (gdbarch, pc, (CORE_ADDR) -1, &= cache, 0); + post_prologue_pc =3D sh_analyze_prologue (gdbarch, pc, limit_pc, &cache,= 0); if (cache.uses_fp) pc =3D post_prologue_pc; =20 Gr=C3=BC=C3=9Fe, Thomas --=-=-= Content-Type: application/pgp-signature Content-length: 489 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQEcBAEBAgAGBQJPTzqQAAoJENuKOtuXzphJD/wH/0MWiRqpftGEz/wn/Wnv2MUC C+MSWRzphdIgye4sTUaSrvMVsIMg0IVNRdO+QGpIGTYaPZ0Yru6oyXXjjyJYA2Qa sbtITQFZGCC9myuW1Yp0/NBl+XBeA66OA2R1yiWvOOEiE6y8o9TvkGcBIPEvM0Jp GaXpE8no9hBK6qJnDSJFuS+bZU3hpAVDFR4Hdy7CNeD2qioItsTzWB7mgwIWcYsW VVp/2WJ2HyOA1x+8JX4dKZ1XSH7I3XOIzZuFiMDNc0zrYL49hZvd7y35YH7f48lk PM0X9seLU3t78aZ1LC0IWn/5mW16nKB0LuiA1bhldng6/hAXcGrNvKdrHn1W90U= =7fq7 -----END PGP SIGNATURE----- --=-=-=--