From owner-freebsd-mips@FreeBSD.ORG Tue Jul 14 00:27:10 2009 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 89ED41065670 for ; Tue, 14 Jul 2009 00:27:10 +0000 (UTC) (envelope-from neelnatu@yahoo.com) Received: from web34407.mail.mud.yahoo.com (web34407.mail.mud.yahoo.com [66.163.178.156]) by mx1.freebsd.org (Postfix) with SMTP id 5563B8FC14 for ; Tue, 14 Jul 2009 00:27:10 +0000 (UTC) (envelope-from neelnatu@yahoo.com) Received: (qmail 21898 invoked by uid 60001); 14 Jul 2009 00:27:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1247531229; bh=nbR/NDW0iEtcl0lRTSDsUqEug1qV9S6UKpryvNH6Oe8=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=ecLPNU/MCa3lgnxDcph3eTmkYHFx2Hzoj+b1wyVAOmB/D7qjNlc/hl6ciFVuRZYMz93odbsS8K2pE0CP3N9MluxMB809Xuf68pr6DiqwD4JBRnMWMutZy10afERxoJYOJW2Apbwt2FPYVyDtTedtOTbFz9NNb5+wv4ZyZ9knbTo= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=KOkPw3sbqyS9O5C8IuhckrkXInuQB8KD8yyI8ZjfcUDdtpFzHFqRYVr0sZHwr1CTi2AmhXI42NLOAEjinrv3nIiz8QTlfcxdwxj9VSC8gGM8hEC4uYpwv1ASesOH0ohP0E/B8RPgb4B97YaqOIV4Va07Nx7OvlWOIPt0skVX6e4=; Message-ID: <681122.20462.qm@web34407.mail.mud.yahoo.com> X-YMail-OSG: mUvs5T0VM1nRlBw84zbtij2fb.OPOzTVx3eos7HEsvdoQitfaUR.jY.niqGN9nF7nkbJbIlgZvcWM7lHxrx07mSBBvXX1a0gTTMNR48eSkJGSRHhyyJlHYzkIVkAx9HEvBINl_ZZ7WYYzcyeafCQypQlAZ7XDHyI.ZQkVFwiVspqRlLVkDmibJgVlRbxpeJhn7snHmXLW0O5HqUka4dV70uBShLJtGGlE_srRDqvK9AE4H9hI3FULQzzz8pAb7rXvaVL2Jcam3d1lLmOisDaGGSxyyCiZ5Lm4jQs_x8LVGp6Enj.p3AUoGTtwNYlq0roMO0bDJgee8_L0AQiPENUsl2z5wj6Jd.L33ySpV8- Received: from [198.95.226.228] by web34407.mail.mud.yahoo.com via HTTP; Mon, 13 Jul 2009 17:27:09 PDT X-Mailer: YahooMailClassic/5.4.17 YahooMailWebService/0.7.289.15 Date: Mon, 13 Jul 2009 17:27:09 -0700 (PDT) From: Neelkanth Natu To: freebsd-mips@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Diffs to fix ddb backtrace 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: Tue, 14 Jul 2009 00:27:10 -0000 Hi, This diff fixes a problem I encountered with ddb backtrace. The problem with looking for just 'j ra' instruction to find out the end of the previous function is that gcc does not emit that instruction for functions that are not supposed to return (for e.g. boot() or panic()). This is especially bad because the backtrace generated by calling panic() is unusable because boot() is right above panic() in the object file. This change looks for start of a function by looking for an instruction of the form: addiu sp,sp,- It so happens that gcc emits this as the first instruction for all functions that use the stack. We keep the 'j ra' method around for functions that don't use the stack. For e.g. here is backtrace output without the fix: mountroot> panic: Root mount failed, startup aborted. KDB: enter: panic [thread pid 1 tid 100001 ] Stopped at kdb_enter+0x50: lui at,0x8043 db> bt Tracing pid 1 tid 100001 td 0xc7847000 kdb_enter+50 (0,0,0,0) ra 80234d2c sz 24 80234378+9b4 (0,0,0,0) ra 803cbb98 sz 80 803a37b0+283e8 (0,0,0,0) ra 0 sz 0 pid 1 And this is the backtrace with the fix: mountroot> panic: Root mount failed, startup aborted. KDB: enter: panic [thread pid 1 tid 100001 ] Stopped at kdb_enter+0x50: lui at,0x8043 db> bt Tracing pid 1 tid 100001 td 0xc7847000 kdb_enter+50 (0,0,0,0) ra 80234d2c sz 24 panic+f8 (0,a,8059ffe4,0) ra 802be12c sz 40 vfs_mountroot+518 (0,a,8059ffe4,0) ra 801f1464 sz 96 801f13f0+74 (0,a,8059ffe4,0) ra 8020d338 sz 96 fork_exit+b0 (0,a,8059ffe4,0) ra 80395300 sz 40 fork_trampoline+10 (0,a,8059ffe4,0) ra 0 sz 0 pid 1 best Neel ==== //depot/user/neelnatu/projects_mips/src/sys/mips/mips/trap.c#1 - /amd/svlusr02.eng.netapp.com/vol/home24/neelnatu/p4/projects_mips/src/sys/mips/mips/trap.c ==== @@ -1229,7 +1229,25 @@ #if defined(DDB) || defined(DEBUG) -#define MIPS_JR_RA 0x03e00008 /* instruction code for jr ra */ +/* + * A function using a stack frame has the following instruction as the first + * one: addiu sp,sp,- + * + * We make use of this to detect starting address of a function. This works + * better than using 'j ra' instruction to signify end of the previous + * function (for e.g. functions like boot() or panic() do not actually + * emit a 'j ra' instruction). + * + * XXX the abi does not require that the addiu instruction be the first one. + */ +#define MIPS_START_OF_FUNCTION(ins) (((ins) & 0xffff8000) == 0x27bd8000) + +/* + * MIPS ABI 3.0 requires that all functions return using the 'j ra' instruction + * + * XXX gcc doesn't do this true for functions with __noreturn__ attribute. + */ +#define MIPS_END_OF_FUNCTION(ins) ((ins) == 0x03e00008) /* forward */ char *fn_name(unsigned addr); @@ -1326,9 +1344,21 @@ */ if (!subr) { va = pc - sizeof(int); - while ((instr = kdbpeek((int *)va)) != MIPS_JR_RA) + while (1) { + instr = kdbpeek((int *)va); + + if (MIPS_START_OF_FUNCTION(instr)) + break; + + if (MIPS_END_OF_FUNCTION(instr)) { + /* skip over branch-delay slot instruction */ + va += 2 * sizeof(int); + break; + } + va -= sizeof(int); - va += 2 * sizeof(int); /* skip back over branch & delay slot */ + } + /* skip over nulls which might separate .o files */ while ((instr = kdbpeek((int *)va)) == 0) va += sizeof(int);