Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@gnat.com>
To: gdb-patches@sources.redhat.com
Subject: [RFC] Calling mips-tdep.c:read_next_frame_reg with null frame?
Date: Mon, 11 Oct 2004 04:09:00 -0000	[thread overview]
Message-ID: <20041011040934.GD26446@gnat.com> (raw)

I am wondering what would happen if we were to call mips32_scan_prologue
with a NULL frame, which I think is something that we are doing on a
regular basis. See for instance how after_prologue that calls
heuristic_proc_desc with a NULL frame, which gets passed to scan_prologue.

There is some code in that function that does:

    frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30);

Looking at read_next_frame_reg():

        static CORE_ADDR
        read_next_frame_reg (struct frame_info *fi, int regno)
        {
          /* Always a pseudo.  */
          gdb_assert (regno >= NUM_REGS);
          if (fi == NULL)
            {
              LONGEST val;
              regcache_cooked_read_signed (current_regcache, regno, &val);
              return val;
            } 
          else
            return frame_unwind_register_signed (fi, regno);

So when the frame is null, we fetch some value from the regcache.
But what if we don't have any inferior? Looks like we have to be
a bit careful with the following code:

          else if (frame_reg == MIPS_SP_REGNUM)
            {
              unsigned alloca_adjust;

              frame_reg = 30;
              frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30);
              alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
              if (alloca_adjust > 0)
                {
                  /* FP > SP + frame_size. This may be because of
                     an alloca or somethings similar.  Fix sp to
                     "pre-alloca" value, and try again.  */
                  sp += alloca_adjust;
                  /* Need to reset the status of all registers.  Otherwise,
                     we will hit a guard that prevents the new address
                     for each register to be recomputed during the second
                     pass.  */
                  reset_saved_regs (this_cache);
                  goto restart;
                }
            }

Same for

      /* move $30,$sp.  With different versions of gas this will be either
         `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
         Accept any one of these.  */
      else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
        {
          /* New gcc frame, virtual frame pointer is at r30 + frame_size.  */
          if (frame_reg == MIPS_SP_REGNUM)
            {
              unsigned alloca_adjust;

              frame_reg = 30;
              frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30);
(etc...)

I suggest modifying the (frame_reg == SP_REGNUM) check into

        (frame_reg == SP_REGNUM && next_frame != NULL)

with a comment saying that if NEXT_FRAME is null, then we're probably
not analyzing a live frame, but just scanning the prologue. So we don't
need to do anything special for this instruction.

Thoughts?
-- 
Joel


             reply	other threads:[~2004-10-11  4:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-11  4:09 Joel Brobecker [this message]
2004-10-12 21:26 ` Andrew Cagney

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=20041011040934.GD26446@gnat.com \
    --to=brobecker@gnat.com \
    --cc=gdb-patches@sources.redhat.com \
    /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