Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@codesourcery.com>
To: Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>
Cc: <gdb-patches@sourceware.org>
Subject: [committed] Fix MIPS frame prologue scan problem
Date: Sun, 24 Feb 2013 12:55:00 -0000	[thread overview]
Message-ID: <alpine.DEB.1.10.1302240235020.6762@tp.orcam.me.uk> (raw)
In-Reply-To: <alpine.DEB.1.10.1211261641120.11298@tp.orcam.me.uk>

On Mon, 26 Nov 2012, Maciej W. Rozycki wrote:

> > > But in mips32_scan_prologue,
> > > the first
> > >   ADDI $s8,$sp,LocalSize
> > > instruction,
> > >   interpreted it in mips32_scan_prologue function
> > > but ended up with a wrong position of my
> > > non-ABI standard frame pointer
> > > because it changed frame pointer register from sp to s8 register,
> > > but kept frame_offset value as set by the
> > >   SUBI $sp, $sp, LocalSize
> > > instruction
> > >   analyzed before.
> > > 
> > >   Thus GDB wrongly ends up with a
> > > frame pointer located a
> > >   value of $s8 register (as from ADDI instruction analysis)
> > > + LocalSize (from SUBI instruction)
> > > 
> > >   This means that of
> > >   $sp is say at address addr
> > >   $s8  is at addr +LocalSize
> > > and the virtual frame pointer
> > >   $fp at  $s8 + LocalSize = addr + 2 * LocalSize
> > > 
> > > 
> > >   This means that it would be better to remove
> > > analysis of the ADDI $s8, $sp, LocalSize
> > > than to leave the current behavior.
> > > 
> > >   I think that we should either use my proposed patch,
> > > or completely remove the analysis of this ADDI $s8, $sp, LocalSize...
> 
>  Given the ambiguities noted above and following the principle of being 
> liberal as to what to accept I agree your proposal makes sense.  I am 
> fairly sure though that in the presence of a hard frame pointer ($fp) it 
> is that value we should rely on as it's there for a reason.

 Thanks for your patience.  I have now looked through it in depth and your 
observation is actually a regression introduced sometime between 4.16 and 
4.17, probably when the function was rewritten when MIPS16 support was 
added sometime in 1997 and the original heuristic_proc_desc code forked 
into mips32_heuristic_proc_desc and mips16_heuristic_proc_desc, which is 
how the respective functions were called back then.

 Before that regression frame_offset was unconditionally forced to zero 
whenever $fp was used to hold the virtual frame pointer -- the only use 
case supported for $fp back then.  Original code read:

    if (has_frame_reg) {
	PROC_FRAME_REG(&temp_proc_desc) = 30;
	PROC_FRAME_OFFSET(&temp_proc_desc) = 0;
    }
    else {
	PROC_FRAME_REG(&temp_proc_desc) = SP_REGNUM;
	PROC_FRAME_OFFSET(&temp_proc_desc) = frame_size;
    }

After the problematic change the PROC_FRAME_OFFSET(&temp_proc_desc) = 0 
assignment was lost.

 I have therefore applied the change below; no change is needed for MIPS16 
or microMIPS analysers as they use different code -- with frame_adjust 
holding the extra frame adjustment in the corresponding case (it may make 
sense to make all the three pieces more uniform, but that's another 
matter).

 This is not a code path that is ever used with modern GCC or it would 
have likely been spotted much earlier than 15 years after the regression 
and it is therefore not really covered by the test suite.  I have run it 
regardless, for the MIPS/Linux target and a couple multilibs, just for the 
peace of mind.

 Again, thanks for your patience and apologies to take so long.

  Maciej

2013-02-24  Maciej W. Rozycki  <macro@codesourcery.com>

	gdb/
	* mips-tdep.c (mips32_scan_prologue): Reset frame_offset to zero
	if $fp is used as the virtual frame pointer.

Index: gdb-fsf-trunk-quilt/gdb/mips-tdep.c
===================================================================
--- gdb-fsf-trunk-quilt.orig/gdb/mips-tdep.c	2013-02-24 00:29:58.000000000 +0000
+++ gdb-fsf-trunk-quilt/gdb/mips-tdep.c	2013-02-24 01:34:10.834052078 +0000
@@ -3316,6 +3316,7 @@ mips32_scan_prologue (struct gdbarch *gd
 	      frame_reg = 30;
 	      frame_addr = get_frame_register_signed
 		(this_frame, gdbarch_num_regs (gdbarch) + 30);
+	      frame_offset = 0;
 
 	      alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
 	      if (alloca_adjust > 0)


  reply	other threads:[~2013-02-24 12:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-13 12:20 [RFC] " Pierre Muller
2012-06-21 22:17 ` PING " Pierre Muller
2012-06-21 23:12 ` Maciej W. Rozycki
2012-06-22  6:53   ` Pierre Muller
2012-11-26 16:05     ` PING " Pierre Muller
2012-11-26 21:27       ` Maciej W. Rozycki
2013-02-24 12:55         ` Maciej W. Rozycki [this message]
2013-02-24 21:52           ` [committed] " Pierre Muller
2013-02-25 18:15             ` Maciej W. Rozycki
     [not found]           ` <512a8b93.0956420a.2e81.ffffd74aSMTPIN_ADDED_BROKEN@mx.google.com>
2013-02-27 18:15             ` Pedro Alves

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=alpine.DEB.1.10.1302240235020.6762@tp.orcam.me.uk \
    --to=macro@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pierre.muller@ics-cnrs.unistra.fr \
    /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