Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 May 2010 11:34:48 -0700
From:      Juli Mallett <jmallett@FreeBSD.org>
To:        "M. Warner Losh" <imp@bsdimp.com>
Cc:        freebsd-mips@freebsd.org
Subject:   Re: Fix mips64 ddb backtracing
Message-ID:  <AANLkTilOsMI9JN-Z4is_5-py-y8zDe4kDtpJFxuv0Pw3@mail.gmail.com>
In-Reply-To: <20100527.100314.539398516089941831.imp@bsdimp.com>
References:  <4BFDA036.7080502@gmail.com> <20100527.100314.539398516089941831.imp@bsdimp.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, May 27, 2010 at 09:03, M. Warner Losh <imp@bsdimp.com> 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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTilOsMI9JN-Z4is_5-py-y8zDe4kDtpJFxuv0Pw3>