From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32300 invoked by alias); 5 Oct 2004 10:13:26 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 32284 invoked from network); 5 Oct 2004 10:13:24 -0000 Received: from unknown (HELO mail04.idc.renesas.com) (202.234.163.13) by sourceware.org with SMTP; 5 Oct 2004 10:13:24 -0000 Received: (from root@localhost) by guardian02.idc.renesas.com with id i95ADI0V014268 for gdb-patches@sources.redhat.com; Tue, 5 Oct 2004 19:13:18 +0900 (JST) Received: from unknown [172.20.8.73] by guardian02.idc.renesas.com with SMTP id VAA14267 ; Tue, 5 Oct 2004 19:13:18 +0900 Received: from mrkaisv.hoku.renesas.com ([10.145.105.245]) by rnsmtp01.hoku_r.renesas.com (8.9.3/3.7W) with ESMTP id TAA11408 for ; Tue, 5 Oct 2004 19:13:15 +0900 (JST) Received: from E5A02646 (unknown [10.145.105.81]) by mrkaisv.hoku.renesas.com (Postfix) with SMTP id 420D07981B7 for ; Tue, 5 Oct 2004 19:13:15 +0900 (JST) Message-ID: <046601c4aac3$eda73740$5169910a@E5A02646> From: "Kei Sakamoto" To: Subject: [RFA/m32r] Fix m32r frame analyzer Date: Tue, 05 Oct 2004 10:13:00 -0000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0463_01C4AB0F.5D5C5D90" X-SW-Source: 2004-10/txt/msg00078.txt.bz2 This is a multi-part message in MIME format. ------=_NextPart_000_0463_01C4AB0F.5D5C5D90 Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: 7bit Content-length: 766 Hello, The attached patch revises m32r frame analyzer. The current analyzer works fine with functions written in C. But it sometimes can't handle functions written in assembly languages correctly. It also can't recognize trap instructions as the end of prologue. # System call handlers of Linux/M32R are written in assembly # languages and use trap instructions. The attached fixes these problems. OK to commit? 2004-10-05 Kei Sakamoto * m32r-tdep.c (decode_prologue): Support functions written in assembly languages. Recognize trap instructions as the end of prologue. (m32r_frame_unwind_cache): Ditto. (m32r_skip_prologue): Extend search limit. Quit analyzing prologue if pc's location is not readable. ------=_NextPart_000_0463_01C4AB0F.5D5C5D90 Content-Type: application/octet-stream; name="m32r-tdep.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="m32r-tdep.patch" Content-length: 7186 Index: m32r-tdep.c=0A= =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=0A= RCS file: /cvs/src/src/gdb/m32r-tdep.c,v=0A= retrieving revision 1.32=0A= diff -u -r1.32 m32r-tdep.c=0A= --- m32r-tdep.c 5 Oct 2004 04:07:10 -0000 1.32=0A= +++ m32r-tdep.c 5 Oct 2004 09:26:33 -0000=0A= @@ -258,13 +258,13 @@=0A= =20=0A= static void=0A= decode_prologue (CORE_ADDR start_pc, CORE_ADDR scan_limit,=0A= - CORE_ADDR *pl_endptr)=0A= + CORE_ADDR *pl_endptr, unsigned long *framelength)=0A= {=0A= unsigned long framesize;=0A= int insn;=0A= int op1;=0A= - int maybe_one_more =3D 0;=0A= CORE_ADDR after_prologue =3D 0;=0A= + CORE_ADDR after_push =3D 0;=0A= CORE_ADDR after_stack_adjust =3D 0;=0A= CORE_ADDR current_pc;=0A= =20=0A= @@ -275,29 +275,18 @@=0A= {=0A= insn =3D read_memory_unsigned_integer (current_pc, 2);=0A= =20=0A= + if (insn =3D=3D 0x0000)=0A= + break;=0A= +=0A= /* If this is a 32 bit instruction, we dont want to examine its=0A= immediate data as though it were an instruction */=0A= if (current_pc & 0x02)=0A= {=0A= - /* Clear the parallel execution bit from 16 bit instruction */=0A= - if (maybe_one_more)=0A= - {=0A= - /* The last instruction was a branch, usually terminates=0A= - the series, but if this is a parallel instruction,=0A= - it may be a stack framing instruction */=0A= - if (!(insn & 0x8000))=0A= - {=0A= - /* nope, we are really done */=0A= - break;=0A= - }=0A= - }=0A= /* decode this instruction further */=0A= insn &=3D 0x7fff;=0A= }=0A= else=0A= {=0A= - if (maybe_one_more)=0A= - break; /* This isnt the one more */=0A= if (insn & 0x8000)=0A= {=0A= if (current_pc =3D=3D scan_limit)=0A= @@ -324,7 +313,7 @@=0A= framesize +=3D insn;=0A= }=0A= }=0A= - after_prologue =3D current_pc;=0A= + after_push =3D current_pc + 2;=0A= continue;=0A= }=0A= }=0A= @@ -363,17 +352,23 @@=0A= after_prologue =3D current_pc + 2;=0A= break; /* end of stack adjustments */=0A= }=0A= +=0A= /* Nop looks like a branch, continue explicitly */=0A= if (insn =3D=3D 0x7000)=0A= {=0A= after_prologue =3D current_pc + 2;=0A= continue; /* nop occurs between pushes */=0A= }=0A= + /* End of prolog if any of these are trap instructions */=0A= + if ((insn & 0xfff0) =3D=3D 0x10f0)=0A= + {=0A= + after_prologue =3D current_pc;=0A= + break;=0A= + }=0A= /* End of prolog if any of these are branch instructions */=0A= if ((op1 =3D=3D 0x7000) || (op1 =3D=3D 0xb000) || (op1 =3D=3D 0xf000= ))=0A= {=0A= after_prologue =3D current_pc;=0A= - maybe_one_more =3D 1;=0A= continue;=0A= }=0A= /* Some of the branch instructions are mixed with other types */=0A= @@ -383,12 +378,14 @@=0A= if ((subop =3D=3D 0x0ec0) || (subop =3D=3D 0x0fc0))=0A= {=0A= after_prologue =3D current_pc;=0A= - maybe_one_more =3D 1;=0A= continue; /* jmp , jl */=0A= }=0A= }=0A= }=0A= =20=0A= + if (framelength)=0A= + *framelength =3D framesize;=0A= +=0A= if (current_pc >=3D scan_limit)=0A= {=0A= if (pl_endptr)=0A= @@ -400,6 +397,13 @@=0A= {=0A= *pl_endptr =3D after_stack_adjust;=0A= }=0A= + else if (after_push !=3D 0)=0A= + /* We did not find a "mv fp,sp", but we DID find=0A= + a push. Is it safe to use that as the=0A= + end of the prologue? I just don't know. */=0A= + {=0A= + *pl_endptr =3D after_push;=0A= + }=0A= else=0A= /* We reached the end of the loop without finding the end=0A= of the prologue. No way to win -- we should report failure.=20=20= =0A= @@ -409,6 +413,7 @@=0A= }=0A= return;=0A= }=0A= +=0A= if (after_prologue =3D=3D 0)=0A= after_prologue =3D current_pc;=0A= =20=0A= @@ -419,13 +424,14 @@=0A= /* Function: skip_prologue=0A= Find end of function prologue */=0A= =20=0A= -#define DEFAULT_SEARCH_LIMIT 44=0A= +#define DEFAULT_SEARCH_LIMIT 128=0A= =20=0A= CORE_ADDR=0A= m32r_skip_prologue (CORE_ADDR pc)=0A= {=0A= CORE_ADDR func_addr, func_end;=0A= struct symtab_and_line sal;=0A= + LONGEST return_value;=0A= =20=0A= /* See what the symbol table says */=0A= =20=0A= @@ -447,11 +453,15 @@=0A= }=0A= else=0A= func_end =3D pc + DEFAULT_SEARCH_LIMIT;=0A= - decode_prologue (pc, func_end, &sal.end);=0A= +=0A= + /* If pc's location is not readable, just quit. */=0A= + if (!safe_read_memory_integer (pc, 4, &return_value))=0A= + return 0;=0A= +=0A= + decode_prologue (pc, func_end, &sal.end, NULL);=0A= return sal.end;=0A= }=0A= =20=0A= -=0A= struct m32r_unwind_cache=0A= {=0A= /* The previous frame's inner most stack address. Used as this=0A= @@ -480,13 +490,14 @@=0A= m32r_frame_unwind_cache (struct frame_info *next_frame,=0A= void **this_prologue_cache)=0A= {=0A= - CORE_ADDR pc;=0A= + CORE_ADDR pc, scan_limit;=0A= ULONGEST prev_sp;=0A= ULONGEST this_base;=0A= - unsigned long op;=0A= + unsigned long op, op2;=0A= int i;=0A= struct m32r_unwind_cache *info;=0A= =20=0A= +=0A= if ((*this_prologue_cache))=0A= return (*this_prologue_cache);=0A= =20=0A= @@ -496,10 +507,11 @@=0A= =20=0A= info->size =3D 0;=0A= info->sp_offset =3D 0;=0A= -=0A= info->uses_frame =3D 0;=0A= +=0A= + scan_limit =3D frame_pc_unwind (next_frame);=0A= for (pc =3D frame_func_unwind (next_frame);=0A= - pc > 0 && pc < frame_pc_unwind (next_frame); pc +=3D 2)=0A= + pc > 0 && pc < scan_limit; pc +=3D 2)=0A= {=0A= if ((pc & 2) =3D=3D 0)=0A= {=0A= @@ -513,18 +525,19 @@=0A= short n =3D op & 0xffff;=0A= info->sp_offset +=3D n;=0A= }=0A= - else if (((op >> 8) =3D=3D 0xe4) /* ld24 r4, xxxxxx; sub sp, r4 */= =0A= - && get_frame_memory_unsigned (next_frame, pc + 4,=0A= + else if (((op >> 8) =3D=3D 0xe4)=0A= + && get_frame_memory_unsigned (next_frame, pc + 2,=0A= 2) =3D=3D 0x0f24)=0A= {=0A= + /* ld24 r4, xxxxxx; sub sp, r4 */=0A= unsigned long n =3D op & 0xffffff;=0A= info->sp_offset +=3D n;=0A= - pc +=3D 2;=0A= + pc +=3D 2; /* skip sub instruction */=0A= }=0A= - else=0A= - break;=0A= =20=0A= - pc +=3D 2;=0A= + if (pc =3D=3D scan_limit)=0A= + scan_limit +=3D 2; /* extend the search */=0A= + pc +=3D 2; /* skip the immediate data */=0A= continue;=0A= }=0A= }=0A= @@ -549,12 +562,13 @@=0A= /* mv fp, sp */=0A= info->uses_frame =3D 1;=0A= info->r13_offset =3D info->sp_offset;=0A= + break; /* end of stack adjustments */=0A= + }=0A= + else if ((op & 0xfff0) =3D=3D 0x10f0)=0A= + {=0A= + /* end of prologue if this is a trap instruction */=0A= + break; /* end of stack adjustments */=0A= }=0A= - else if (op =3D=3D 0x7000)=0A= - /* nop */=0A= - continue;=0A= - else=0A= - break;=0A= }=0A= =20=0A= info->size =3D -info->sp_offset;=0A= ------=_NextPart_000_0463_01C4AB0F.5D5C5D90--