From owner-freebsd-mips@FreeBSD.ORG Thu May 27 18:35:10 2010 Return-Path: Delivered-To: freebsd-mips@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1382E106566B for ; Thu, 27 May 2010 18:35:10 +0000 (UTC) (envelope-from juli@clockworksquid.com) Received: from mail-vw0-f54.google.com (mail-vw0-f54.google.com [209.85.212.54]) by mx1.freebsd.org (Postfix) with ESMTP id C4F6D8FC1E for ; Thu, 27 May 2010 18:35:09 +0000 (UTC) Received: by vws12 with SMTP id 12so330003vws.13 for ; Thu, 27 May 2010 11:35:08 -0700 (PDT) Received: by 10.220.122.86 with SMTP id k22mr7885535vcr.25.1274985308589; Thu, 27 May 2010 11:35:08 -0700 (PDT) MIME-Version: 1.0 Sender: juli@clockworksquid.com Received: by 10.220.199.70 with HTTP; Thu, 27 May 2010 11:34:48 -0700 (PDT) In-Reply-To: <20100527.100314.539398516089941831.imp@bsdimp.com> References: <4BFDA036.7080502@gmail.com> <20100527.100314.539398516089941831.imp@bsdimp.com> From: Juli Mallett Date: Thu, 27 May 2010 11:34:48 -0700 X-Google-Sender-Auth: Cn_wazYB3Gdv1Vh_g3zcAHxUOWA Message-ID: To: "M. Warner Losh" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-mips@freebsd.org Subject: Re: Fix mips64 ddb backtracing X-BeenThere: freebsd-mips@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to MIPS List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 May 2010 18:35:10 -0000 On Thu, May 27, 2010 at 09:03, M. Warner Losh wrote: > : @@ -140,7 +150,7 @@ > : =A0 =A0 =A0 } > : =A0 =A0 =A0 /* check for bad SP: could foul up next frame */ > : =A0 =A0 =A0 /*XXX MIPS64 bad: this hard-coded SP is lame */ > : - =A0 =A0 if (sp & 3 || sp < 0x80000000) { > : + =A0 =A0 if (sp & 3 || (uintptr_t) sp < 0xffffffff80000000ULL) { > > This is wrong. =A0sp should be cast to intptr_t to have it still work > with 32-bit debugging. =A0Unsigned sp will be 0x80000000, which will > trigger this case. Actually, it's worse than that. As far as unsigned quantities go, XKPHYS and XKSEG addresses are less than CKSEG0 addresses, so if your thread is using an at all 64-bit aware kernel, you're going to have trouble here. The right thing to do is to check for whether the high bit is set. Checking whether (intptr_t)sp is negative is probably the closest thing to a universal solution you're going to want. > : =A0 =A0 =A0 =A0 =A0 =A0 =A0 (*printfn) ("SP 0x%x: not in kernel\n", sp)= ; > : =A0 =A0 =A0 =A0 =A0 =A0 =A0 ra =3D3D 0; > : =A0 =A0 =A0 =A0 =A0 =A0 =A0 subr =3D3D 0; > : @@ -181,7 +191,7 @@ > : =A0 =A0 =A0 } > : =A0 =A0 =A0 /* check for bad PC */ > : =A0 =A0 =A0 /*XXX MIPS64 bad: These hard coded constants are lame */ > : - =A0 =A0 if (pc & 3 || pc < (uintptr_t)0x80000000) { > : + =A0 =A0 if (pc & 3 || (uintptr_t)pc < 0xffffffff80000000ULL) { > > Ditto. Likewise. > : =A0 =A0 =A0 =A0 =A0 =A0 =A0 (*printfn) ("PC 0x%x: not in kernel\n", pc)= ; > : =A0 =A0 =A0 =A0 =A0 =A0 =A0 ra =3D3D 0; > : =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto done; > : @@ -337,17 +349,18 @@ > : =A0 =A0 =A0 } > : =3D20 > : =A0done: > : - =A0 =A0 (*printfn) ("%s+%x (", fn_name(subr), pc - subr); > : + =A0 =A0 (*printfn) ("%s+%lx (", fn_name(subr), (unsigned long) (pc - = subr)); > : =A0 =A0 =A0 for (j =3D3D 0; j < 4; j ++) { > : =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (j > 0) > : =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (*printfn)(","); > : =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (valid_args[j]) > : - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (*printfn)("%x", args[j]); > : + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (*printfn)("%lx", (unsigned l= ong) args[j]); > > These casts aren't right. =A0We should likely be using intmax_t here and > %j. Yep. > : =A0 =A0 =A0 =A0 =A0 =A0 =A0 else > : =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (*printfn)("?"); > : =A0 =A0 =A0 } > : =3D20 > : - =A0 =A0 (*printfn) (") ra %x sp %x sz %d\n", ra, sp, stksize); > : + =A0 =A0 (*printfn) (") ra %lx sp %lx sz %ld\n", (unsigned long) ra, > : + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (unsigned long) sp, (long) stksize); > : =3D20 > > These casts aren't right. =A0We should likely be using intmax_t here and > %j. I agree once again :) > : =A0 =A0 =A0 if (ra) { > : =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (pc =3D3D=3D3D ra && stksize =3D3D=3D3D = 0) > : Juli.