linux-mips
[Top] [All Lists]

Re: [PATCH] dump_stack() based on prologue code analysis

To: vagabon.xyz@gmail.com
Subject: Re: [PATCH] dump_stack() based on prologue code analysis
From: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Date: Tue, 01 Aug 2006 00:33:11 +0900 (JST)
Cc: linux-mips@linux-mips.org, ralf@linux-mips.org
In-reply-to: <44CE1494.4080801@innova-card.com>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <44CDCA46.3030707@innova-card.com> <20060731.223923.115609520.anemo@mba.ocn.ne.jp> <44CE1494.4080801@innova-card.com>
Sender: linux-mips-bounce@linux-mips.org
On Mon, 31 Jul 2006 16:32:52 +0200, Franck Bui-Huu <vagabon.xyz@gmail.com> 
wrote:
> Well could we use "sizeof(union mips_instruction)" so nobody won't
> make the same mistake ?
> 
>               if (i >= info->func_size / sizeof(union mips_instruction))
>                       break;

Indeed.

> BTW I omit the first condition "info->func_size != 0" because
> normally a func has a no null size. If it has we should stop
> right now.
 
Yes.  I can not remember why "info->func_size != 0" is there...

> We should also test this condition _before_ testing that "*ip" is
> a jal instruction, shouldn't we ?

Yes, and we can hold the condition indo the "for" statement.


Subject: [PATCH] make get_frame_info() more readable.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>

diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index 8709a46..949efaf 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -286,18 +286,17 @@ static int get_frame_info(struct mips_fr
        int i;
        void *func = info->func;
        union mips_instruction *ip = (union mips_instruction *)func;
+       int max_insns =
+               min(128UL, info->func_size / sizeof(union mips_instruction));
        info->pc_offset = -1;
        info->frame_size = 0;
-       for (i = 0; i < 128; i++, ip++) {
+       for (i = 0; i < max_insns; i++, ip++) {
                /* if jal, jalr, jr, stop. */
                if (ip->j_format.opcode == jal_op ||
                    (ip->r_format.opcode == spec_op &&
                     (ip->r_format.func == jalr_op ||
                      ip->r_format.func == jr_op)))
                        break;
-
-               if (info->func_size && i >= info->func_size / 4)
-                       break;
                if (
 #ifdef CONFIG_32BIT
                    ip->i_format.opcode == addiu_op &&

<Prev in Thread] Current Thread [Next in Thread>