Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Paul Gilliam <pgilliam@us.ibm.com>
To: gdb-patches@sourceware.org
Cc: Mark Kettenis <mark.kettenis@xs4all.nl>,
	jimb@red-bean.com,         gdb-patches@sources.redhat.com
Subject: Re: [PATCH] add 'rs6000_in_function_epilogue_p()' (Revised, again)
Date: Sat, 03 Dec 2005 04:53:00 -0000	[thread overview]
Message-ID: <200512021551.43510.pgilliam@us.ibm.com> (raw)
In-Reply-To: <200512021956.jB2Ju5YN000928@elgar.sibelius.xs4all.nl>

On Friday 02 December 2005 11:56, Mark Kettenis wrote:
> > From: Paul Gilliam <pgilliam@us.ibm.com>
> > Date: Fri, 2 Dec 2005 11:20:22 -0800
> > 
> > And here is the revised patch:
> > 
> > 2005-12-02  Paul Gilliam  <pgilliam@us.ibm.com>
> > 
> >         * rs6000-tdep.c: Add new subroutine, 'rs6000_in_function_epilogue_p()'
> >         and put it into the architecture vector.
> 
> Paul,
> 
> There are a couple of problems with your patch.  Please read read the
> GNU condig standards http://www.gnu.org/prep/standards/.  Here are a
> few issues:

OK.

>  * Please put a space before the ( that starts the functions arguments.

OK

>  * ins_changes_sp contains unused variables.  Please configure gdb
>    with --enable-gdb-build-warnings=,-Werror, this'll prevent them
>    from slipping through.

The unused variables where on purpose.  They show the complete 'cracking' 
of the types of instructions we are interested in.

But I guess a comment will work as well.

>  * Please don't make your lines too long.  The emacs default
>    fill-column is 72, but in general we tolerate lines that are a bit
>    longer.  But make sure the line ends before column 79/80.

I am not sure which line you are refering to: the longest lines end in column 79.

But I'll sorten them.

>  * "break" should be put on a line of its own.

OK

>  * Always surround =, -=, etc. with spaces.

OK

> I think your patch should go in.  But it's really Andrew Cagney's and
> Kevin Buettner's call.
> 
> Mark
> 

Thank you, Mark.  The 'GNU Coding Standards' is a good start, but there is nothing
like to voice of experiance.

So if my revised patch below addresses your concerns, I'll check it in as per Kevin Buettner's message:
> On Friday 02 December 2005 12:32, Kevin Buettner wrote:
> > On Fri, 2 Dec 2005 11:20:22 -0800
> > Paul Gilliam <pgilliam@us.ibm.com> wrote:
> > 
> > >         * rs6000-tdep.c: Add new subroutine, 'rs6000_in_function_epilogue_p()'
> > >         and put it into the architecture vector.
> > 
> > Your patch is okay to commit after you address Mark's concerns.
> > 
> > Kevin
> > 
> > 

-=# Paul #=-

PS: I also fixed a typo or two.

Revised Patch:

2005-12-02  Paul Gilliam  <pgilliam@us.ibm.com>

        * rs6000-tdep.c: Add new subroutine, 'rs6000_in_function_epilogue_p()'
        and put it into the architecture vector.

Index: rs6000-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.248
diff -a -u -p -r1.248 rs6000-tdep.c
--- rs6000-tdep.c       1 Nov 2005 19:32:36 -0000       1.248
+++ rs6000-tdep.c       2 Dec 2005 23:08:10 -0000
@@ -502,6 +502,74 @@ rs6000_skip_prologue (CORE_ADDR pc)
   return pc;
 }

+static int
+insn_changes_sp (unsigned long insn)
+{
+  int opcode  = (insn>>26) & 0x03f;
+  int sd      = (insn>>21) & 0x01f;
+  int a       = (insn>>16) & 0x01f;
+  /*  b       = (insn>>11) & 0x01f  */
+  int subcode = (insn>> 1) & 0x3ff;
+  /*  rc      =  insn      & 0x001  */
+
+  if (opcode == 31 && subcode == 444 && a == 1)
+    return 1;  /* mr R1,Rn */
+  if (opcode == 14 && sd == 1)
+    return 1;  /* addi R1,Rn,simm */
+  if (opcode == 58 && sd == 1)
+    return 1;  /* ld R1,ds(Rn) */
+
+  return 0;
+}
+
+/* Return true if we are in the function's epilogue, i.e. after the
+   instruction that destroyed the function's stack frame.  */
+
+static int
+rs6000_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
+{
+  bfd_byte insn_buf[PPC_INSN_SIZE];
+  CORE_ADDR scan_pc, func_addr, func_end;
+  unsigned long insn;
+  struct frame_info *fr;
+
+  /* Find the search limits.  */
+  if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
+    return 0;
+
+  /* Get the current frame.  This may be cheap, since we might have
+     just called it in watchpoint_check, before calling
+     gdbarch_in_function_epilogue_p.  */
+
+  fr = get_current_frame ();
+
+  /* Scan forward untill next 'blr'.  */
+  for (scan_pc = pc; scan_pc < func_end; scan_pc += PPC_INSN_SIZE)
+    {
+      if (!safe_frame_unwind_memory (fr, scan_pc, insn_buf, PPC_INSN_SIZE))
+        return 0;
+      insn = extract_signed_integer (insn_buf, PPC_INSN_SIZE);
+      if (insn == 0x4e800020)
+        break;
+      if (insn_changes_sp (insn))
+        return 0;
+    }
+
+  /* Scan backward untill adjustment to stack pointer (R1).  */
+  for (scan_pc = pc-PPC_INSN_SIZE;
+       scan_pc >= func_addr;
+       scan_pc -= PPC_INSN_SIZE)
+    {
+      if (!safe_frame_unwind_memory (fr, scan_pc, insn_buf, PPC_INSN_SIZE))
+        return 0;
+      insn = extract_signed_integer (insn_buf, PPC_INSN_SIZE);
+      if (insn_changes_sp (insn))
+        return 1;
+    }
+
+  return 0;
+}
+

 /* Fill in fi->saved_regs */

@@ -3342,6 +3409,8 @@ rs6000_gdbarch_init (struct gdbarch_info
   set_gdbarch_deprecated_extract_struct_value_address (gdbarch, rs6000_extract_struct_value_address);

   set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue);
+  set_gdbarch_in_function_epilogue_p (gdbarch, rs6000_in_function_epilogue_p);
+
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
   set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc);


WARNING: multiple messages have this Message-ID
From: Paul Gilliam <pgilliam@us.ibm.com>
To: gdb-patches@sourceware.org
Cc: Mark Kettenis <mark.kettenis@xs4all.nl>,
	jimb@red-bean.com,         gdb-patches@sources.redhat.com
Subject: Re: [PATCH] add 'rs6000_in_function_epilogue_p()' (Revised, again)
Date: Sat, 03 Dec 2005 05:43:00 -0000	[thread overview]
Message-ID: <200512021551.43510.pgilliam@us.ibm.com> (raw)
Message-ID: <20051203054300.UrPK2b_ByqQ1_qsOkhBPwP1UI9OPHGSZtsVL_nOxkcQ@z> (raw)
In-Reply-To: <200512021956.jB2Ju5YN000928@elgar.sibelius.xs4all.nl>

On Friday 02 December 2005 11:56, Mark Kettenis wrote:
> > From: Paul Gilliam <pgilliam@us.ibm.com>
> > Date: Fri, 2 Dec 2005 11:20:22 -0800
> > 
> > And here is the revised patch:
> > 
> > 2005-12-02  Paul Gilliam  <pgilliam@us.ibm.com>
> > 
> >         * rs6000-tdep.c: Add new subroutine, 'rs6000_in_function_epilogue_p()'
> >         and put it into the architecture vector.
> 
> Paul,
> 
> There are a couple of problems with your patch.  Please read read the
> GNU condig standards http://www.gnu.org/prep/standards/.  Here are a
> few issues:

OK.

>  * Please put a space before the ( that starts the functions arguments.

OK

>  * ins_changes_sp contains unused variables.  Please configure gdb
>    with --enable-gdb-build-warnings=,-Werror, this'll prevent them
>    from slipping through.

The unused variables where on purpose.  They show the complete 'cracking' 
of the types of instructions we are interested in.

But I guess a comment will work as well.

>  * Please don't make your lines too long.  The emacs default
>    fill-column is 72, but in general we tolerate lines that are a bit
>    longer.  But make sure the line ends before column 79/80.

I am not sure which line you are refering to: the longest lines end in column 79.

But I'll sorten them.

>  * "break" should be put on a line of its own.

OK

>  * Always surround =, -=, etc. with spaces.

OK

> I think your patch should go in.  But it's really Andrew Cagney's and
> Kevin Buettner's call.
> 
> Mark
> 

Thank you, Mark.  The 'GNU Coding Standards' is a good start, but there is nothing
like to voice of experiance.

So if my revised patch below addresses your concerns, I'll check it in as per Kevin Buettner's message:
> On Friday 02 December 2005 12:32, Kevin Buettner wrote:
> > On Fri, 2 Dec 2005 11:20:22 -0800
> > Paul Gilliam <pgilliam@us.ibm.com> wrote:
> > 
> > >         * rs6000-tdep.c: Add new subroutine, 'rs6000_in_function_epilogue_p()'
> > >         and put it into the architecture vector.
> > 
> > Your patch is okay to commit after you address Mark's concerns.
> > 
> > Kevin
> > 
> > 

-=# Paul #=-

PS: I also fixed a typo or two.

Revised Patch:

2005-12-02  Paul Gilliam  <pgilliam@us.ibm.com>

        * rs6000-tdep.c: Add new subroutine, 'rs6000_in_function_epilogue_p()'
        and put it into the architecture vector.

Index: rs6000-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.248
diff -a -u -p -r1.248 rs6000-tdep.c
--- rs6000-tdep.c       1 Nov 2005 19:32:36 -0000       1.248
+++ rs6000-tdep.c       2 Dec 2005 23:08:10 -0000
@@ -502,6 +502,74 @@ rs6000_skip_prologue (CORE_ADDR pc)
   return pc;
 }

+static int
+insn_changes_sp (unsigned long insn)
+{
+  int opcode  = (insn>>26) & 0x03f;
+  int sd      = (insn>>21) & 0x01f;
+  int a       = (insn>>16) & 0x01f;
+  /*  b       = (insn>>11) & 0x01f  */
+  int subcode = (insn>> 1) & 0x3ff;
+  /*  rc      =  insn      & 0x001  */
+
+  if (opcode == 31 && subcode == 444 && a == 1)
+    return 1;  /* mr R1,Rn */
+  if (opcode == 14 && sd == 1)
+    return 1;  /* addi R1,Rn,simm */
+  if (opcode == 58 && sd == 1)
+    return 1;  /* ld R1,ds(Rn) */
+
+  return 0;
+}
+
+/* Return true if we are in the function's epilogue, i.e. after the
+   instruction that destroyed the function's stack frame.  */
+
+static int
+rs6000_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
+{
+  bfd_byte insn_buf[PPC_INSN_SIZE];
+  CORE_ADDR scan_pc, func_addr, func_end;
+  unsigned long insn;
+  struct frame_info *fr;
+
+  /* Find the search limits.  */
+  if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
+    return 0;
+
+  /* Get the current frame.  This may be cheap, since we might have
+     just called it in watchpoint_check, before calling
+     gdbarch_in_function_epilogue_p.  */
+
+  fr = get_current_frame ();
+
+  /* Scan forward untill next 'blr'.  */
+  for (scan_pc = pc; scan_pc < func_end; scan_pc += PPC_INSN_SIZE)
+    {
+      if (!safe_frame_unwind_memory (fr, scan_pc, insn_buf, PPC_INSN_SIZE))
+        return 0;
+      insn = extract_signed_integer (insn_buf, PPC_INSN_SIZE);
+      if (insn == 0x4e800020)
+        break;
+      if (insn_changes_sp (insn))
+        return 0;
+    }
+
+  /* Scan backward untill adjustment to stack pointer (R1).  */
+  for (scan_pc = pc-PPC_INSN_SIZE;
+       scan_pc >= func_addr;
+       scan_pc -= PPC_INSN_SIZE)
+    {
+      if (!safe_frame_unwind_memory (fr, scan_pc, insn_buf, PPC_INSN_SIZE))
+        return 0;
+      insn = extract_signed_integer (insn_buf, PPC_INSN_SIZE);
+      if (insn_changes_sp (insn))
+        return 1;
+    }
+
+  return 0;
+}
+

 /* Fill in fi->saved_regs */

@@ -3342,6 +3409,8 @@ rs6000_gdbarch_init (struct gdbarch_info
   set_gdbarch_deprecated_extract_struct_value_address (gdbarch, rs6000_extract_struct_value_address);

   set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue);
+  set_gdbarch_in_function_epilogue_p (gdbarch, rs6000_in_function_epilogue_p);
+
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
   set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc);


  parent reply	other threads:[~2005-12-02 23:20 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-30 23:56 [PATCH] add 'rs6000_in_function_epilogue_p()' Paul Gilliam
2005-12-01  5:21 ` Jim Blandy
2005-12-01 18:27   ` Paul Gilliam
2005-12-01 20:14     ` Paul Gilliam
2005-12-02  1:13 ` Jim Blandy
2005-12-02  1:23   ` Daniel Jacobowitz
2005-12-02 20:12     ` Paul Gilliam
2005-12-02 20:17       ` Paul Gilliam
2005-12-03  3:05       ` Jim Blandy
2005-12-02 23:38         ` Jim Blandy
2005-12-04 20:19         ` Daniel Jacobowitz
2005-12-04 18:59           ` Daniel Jacobowitz
2005-12-04 20:48           ` Jim Blandy
2005-12-04 21:12             ` Jim Blandy
2005-12-04 21:16             ` Daniel Jacobowitz
2005-12-04 21:22               ` Jim Blandy
2005-12-02  4:02   ` Joel Brobecker
2005-12-02 18:44   ` Mark Kettenis
2005-12-02 19:15   ` [PATCH] add 'rs6000_in_function_epilogue_p()' (Revised) Paul Gilliam
2005-12-02 20:28     ` Mark Kettenis
2005-12-02 21:19       ` Daniel Jacobowitz
2005-12-02 21:21         ` Mark Kettenis
2005-12-03  4:53       ` Paul Gilliam [this message]
2005-12-03  5:43         ` [PATCH] add 'rs6000_in_function_epilogue_p()' (Revised, again) Paul Gilliam
2005-12-02 21:44     ` [PATCH] add 'rs6000_in_function_epilogue_p()' (Revised) Kevin Buettner
2005-12-06 15:20       ` Paul Gilliam
2005-12-06 15:15         ` Paul Gilliam
2005-12-08  4:42         ` Kevin Buettner
2006-01-11 17:44       ` Paul Gilliam
2006-01-12  0:12         ` Paul Gilliam
2006-01-12 23:53           ` Paul Gilliam
2006-01-13 21:05             ` Mark Kettenis
2006-01-17  3:46               ` Paul Gilliam
2006-01-17 19:29                 ` Mark Kettenis
2006-02-09 17:46                 ` Kevin Buettner
2005-12-02 22:19     ` Jim Blandy
2005-12-02 22:28       ` Daniel Jacobowitz
2005-12-02 23:20         ` Jim Blandy
2005-12-03 12:48       ` Paul Gilliam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200512021551.43510.pgilliam@us.ibm.com \
    --to=pgilliam@us.ibm.com \
    --cc=gdb-patches@sources.redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jimb@red-bean.com \
    --cc=mark.kettenis@xs4all.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox