Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@codesourcery.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: Mark Kettenis <mark.kettenis@xs4all.nl>, <gdb-patches@sourceware.org>
Subject: Re: [RFA 1/2] mips: Switch inferior function calls to ON_STACK method.
Date: Tue, 08 May 2012 20:26:00 -0000	[thread overview]
Message-ID: <alpine.DEB.1.10.1205081912220.18334@tp.orcam.me.uk> (raw)
In-Reply-To: <20120508160542.GB15555@adacore.com>

On Tue, 8 May 2012, Joel Brobecker wrote:

> > After some thinking I realised that the reliance on signal delivery to 
> > work properly to trap non-executable stack may actually be a problem for 
> > bare-iron targets.
> 
> IMO, I think we can start worrying about those when we actually
> encounter the problem; and I am assuming that this is not going to
> be specific to mips.

 I don't consider this a showstopper for your change either; in particular 
it does not apply to Linux kernel debugging because except from one or two 
obscure corner cases of some very old hardware that did not have memory at 
0 (except from a page worth shadow area for exception handlers) Linux runs 
its own code using unmapped segments so no memory access permissions 
apply.

 But I decided the issue had to be noted.

> Are we still good to go with this patch? Attached is the latest
> version. For any additional comments that you'd like to be added
> (in particular, with respect to what you just pointed out), I suggest
> add them as a followup patch.  This way, this one is out of the way,
> and we can just focus on the comments themselves.

 I agree about the comments.  However it's just struck me there's 
something weird about your code, see below.

> I am also adding a second patch, which shows the changes I made
> in this iteration.

 Thanks, that's useful.

> diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
> index 9a3c7fb..68ac858 100644
> --- a/gdb/mips-tdep.c
> +++ b/gdb/mips-tdep.c
> @@ -3009,6 +3009,37 @@ mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
>    return align_down (addr, 16);
>  }
>  
> +/* Implement the "push_dummy_call" gdbarch method.  */
> +
> +static CORE_ADDR
> +mips_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
> +		      CORE_ADDR funaddr, struct value **args,
> +		      int nargs, struct type *value_type,
> +		      CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
> +		      struct regcache *regcache)
> +{
> +  int bp_len;
> +  static gdb_byte nop_insn[] = { 0, 0, 0, 0 };
> +
> +  *bp_addr = sp;
> +  gdbarch_breakpoint_from_pc (gdbarch, bp_addr, &bp_len);

 You set bp_addr to SP here, so you rely on the stack pointer to have been 
implicitly adjusted down below the current frame by call_function_by_hand 
(or otherwise the breakpoint would occupy a valid stack frame location at 
this point -- which is dangerous if software breakpoints are used).  I 
find it a bit fragile, how about putting the breakpoint entirely in space 
allocated here?

 Then I think that you can avoid the call to gdbarch_breakpoint_from_pc, 
just as I noted in the microMIPS consideration.  We know that for an 
aligned stack location it's always going to return 4 in bp_len anyway and 
if we want to go below the top of the stack, then we sort of get into a 
chicken and egg problem -- we'll only know how far to go below SP once 
we've called this function, but to call it we need to know the location to 
ask about first.

 Fortunately getting this value exactly right does not really matter -- we 
just need enough space to cover the worst case.  So I suggest this 
instead:

  CORE_ADDR addr;

  addr = sp - sizeof (nop_insn);

so that the breakpoint itself is below the requested SP...

> +
> +  /* The breakpoint layer automatically adjusts the address of
> +     breakpoints inserted in a branch delay slot.  With enough
> +     bad luck, the 4 bytes located just before our breakpoint
> +     instruction could look like a branch instruction, and thus
> +     trigger the adjustement, and break the function call entirely.
> +     So, we reserve those 4 bytes and write a nop instruction
> +     to prevent that from happening.  */
> +  write_memory (*bp_addr - bp_len, nop_insn, sizeof (nop_insn));
> +  sp = mips_frame_align (gdbarch, *bp_addr - 2 * bp_len);

... and then, consequently:

  write_memory (addr - sizeof (nop_insn), nop_insn, sizeof (nop_insn));
  sp = mips_frame_align (gdbarch, addr - sizeof (nop_insn));

  *bp_addr = addr;

(note that in your variation you write the NOP into space of bp_len bytes 
-- as noted above we know that this is going to be 4 anyway, but strictly 
speaking this is risky as it does not tie the number of bytes written to 
the space available).

 OK with these adjustments and sorry that I missed this previously.

  Maciej


  reply	other threads:[~2012-05-08 20:26 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-03 19:03 Getting rid of AT_SYMBOL inferior call method Joel Brobecker
2012-05-03 19:03 ` [RFA 1/2] mips: Switch inferior function calls to ON_STACK method Joel Brobecker
2012-05-03 21:09   ` Maciej W. Rozycki
2012-05-03 21:50     ` Joel Brobecker
2012-05-03 23:29       ` Maciej W. Rozycki
2012-05-04 20:58         ` Joel Brobecker
2012-05-04 21:19           ` Mark Kettenis
2012-05-04 23:25             ` Maciej W. Rozycki
2012-05-05 11:45               ` Mark Kettenis
2012-05-08 15:08                 ` Maciej W. Rozycki
2012-05-08 16:06                   ` Joel Brobecker
2012-05-08 20:26                     ` Maciej W. Rozycki [this message]
2012-05-08 20:43                       ` Joel Brobecker
2012-05-08 22:08                         ` Joel Brobecker
2012-05-09  7:32                           ` Maciej W. Rozycki
2012-05-09  8:24                             ` Mark Kettenis
2012-05-09  9:14                               ` Maciej W. Rozycki
2012-05-09 16:08                                 ` Tom Tromey
2012-05-09 14:35                               ` Joel Brobecker
2012-05-14  9:44                                 ` Maciej W. Rozycki
2012-05-14 15:01                                   ` Joel Brobecker
2012-05-14 16:48                                     ` Maciej W. Rozycki
2012-06-11 10:14                                   ` Maciej W. Rozycki
2012-05-09  6:21                         ` Maciej W. Rozycki
2012-05-04 22:41           ` Maciej W. Rozycki
2012-05-04 21:34     ` Mark Kettenis
2012-05-05  1:31       ` Maciej W. Rozycki
2012-05-03 21:44   ` Mark Kettenis
2012-05-03 21:58     ` Joel Brobecker
2012-05-04  2:11       ` Yao Qi
2012-05-03 22:03   ` Joel Brobecker
2012-05-03 19:03 ` [commit 2/2] Remove AT_SYMBOL Joel Brobecker
2012-05-09 14:37   ` Joel Brobecker

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.1205081912220.18334@tp.orcam.me.uk \
    --to=macro@codesourcery.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --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