Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Hui Zhu <teawater@gmail.com>
To: Michael Snyder <msnyder@vmware.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	"drow@false.org" <drow@false.org>,
	 	"kettenis@gnu.org" <kettenis@gnu.org>
Subject: Re: [RFA] epilogue unwinder for i386 (reverse 1/2)
Date: Sun, 05 Jul 2009 10:54:00 -0000	[thread overview]
Message-ID: <daef60380907050354h4a96cc4eh586880fd8efd59b8@mail.gmail.com> (raw)
In-Reply-To: <4A4EA3B3.9030107@vmware.com>

I tried this patch with ubuntu i386.  Everything is OK.

Thanks,
Hui

On Sat, Jul 4, 2009 at 08:34, Michael Snyder<msnyder@vmware.com> wrote:
> Michael Snyder wrote:
>>
>> This comes out of a discussion with Daniel, about how gcc
>> does not generate the right dwarf info to allow correct
>> frame unwinding in function epilogues, causing frame_unwind
>> to return bad results.
>>
>> It's necessary for reverse-step, which will frequently step
>> backward to the return instruction of a function.  But it also
>> provides an improvement for forward debugging, in that now,
>> without this change, if you STEPI until you are at the return
>> instruction, you will get a bad backtrace.
>>
>> The infrun changes that take advantage of this patch will follow
>> separately.
>>
>> Michael
>
> Oops, the patch wasn't meant to have that "#if 0" in it...
> corrected patch below.
>
>
>
> 2009-07-03  Michael Snyder  <msnyder@vmware.com>
>
>        * i386-tdep.c: Add a frame unwinder for function epilogues.
>        (i386_in_function_epilogue_p): New function.
>        (i386_epilogue_frame_sniffer): New function.
>        (i386_epilogue_frame_cache): New function.
>        (i386_epilogue_frame_this_id): New function.
>        (i386_epilogue_frame_unwind): New struct frame_unwind.
>        (i386_gdbarch_init): Hook the new unwinder.
>
> Index: i386-tdep.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/i386-tdep.c,v
> retrieving revision 1.280
> diff -u -p -r1.280 i386-tdep.c
> --- i386-tdep.c 2 Jul 2009 17:25:54 -0000       1.280
> +++ i386-tdep.c 4 Jul 2009 00:37:12 -0000
> @@ -1487,6 +1487,89 @@ static const struct frame_unwind i386_fr
>   NULL,
>   default_frame_sniffer
>  };
> +
> +/* Normal frames, but in a function epilogue.  */
> +
> +/* The epilogue is defined here as the RET instruction, which will
> +   follow any instruction such as LEAVE or POP EBP that destroys the
> +   function's stack frame.  */
> +
> +static int
> +i386_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
> +{
> +  gdb_byte insn;
> +
> +  if (target_read_memory (pc, &insn, 1) != 0)
> +    return 0;  /* Can't read memory at pc.  */
> +
> +  if (insn != 0xc3)    /* RET */
> +    return 0;
> +
> +  return 1;
> +}
> +
> +static int
> +i386_epilogue_frame_sniffer (const struct frame_unwind *self,
> +                            struct frame_info *this_frame,
> +                            void **this_prologue_cache)
> +{
> +  if (frame_relative_level (this_frame) == 0)
> +    return i386_in_function_epilogue_p (get_frame_arch (this_frame),
> +                                       get_frame_pc (this_frame));
> +  else
> +    return 0;
> +}
> +
> +static struct i386_frame_cache *
> +i386_epilogue_frame_cache (struct frame_info *this_frame, void
> **this_cache)
> +{
> +  struct gdbarch *gdbarch = get_frame_arch (this_frame);
> +  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> +  struct i386_frame_cache *cache;
> +  gdb_byte buf[4];
> +
> +  if (*this_cache)
> +    return *this_cache;
> +
> +  cache = i386_alloc_frame_cache ();
> +  *this_cache = cache;
> +
> +  /* Cache base will be ESP plus cache->sp_offset (-4).  */
> +  get_frame_register (this_frame, I386_ESP_REGNUM, buf);
> +  cache->base = extract_unsigned_integer (buf, 4,
> +                                         byte_order) + cache->sp_offset;
> +
> +  /* Cache pc will be the frame func.  */
> +  cache->pc = get_frame_pc (this_frame);
> +
> +  /* The saved ESP will be at cache->base plus 8.  */
> +  cache->saved_sp = cache->base + 8;
> +
> +  /* The saved EIP will be at cache->base plus 4.  */
> +  cache->saved_regs[I386_EIP_REGNUM] = cache->base + 4;
> +
> +  return cache;
> +}
> +
> +static void
> +i386_epilogue_frame_this_id (struct frame_info *this_frame,
> +                            void **this_cache,
> +                            struct frame_id *this_id)
> +{
> +  struct i386_frame_cache *cache = i386_epilogue_frame_cache (this_frame,
> +                                                             this_cache);
> +
> +  (*this_id) = frame_id_build (cache->base + 8, cache->pc);
> +}
> +
> +static const struct frame_unwind i386_epilogue_frame_unwind =
> +{
> +  NORMAL_FRAME,
> +  i386_epilogue_frame_this_id,
> +  i386_frame_prev_register,
> +  NULL,
> +  i386_epilogue_frame_sniffer
> +};
>
>
>  /* Signal trampolines.  */
> @@ -5328,7 +5411,10 @@ i386_gdbarch_init (struct gdbarch_info i
>
>   /* Helper for function argument information.  */
>   set_gdbarch_fetch_pointer_argument (gdbarch, i386_fetch_pointer_argument);
> -
> +#if 0
> +  /* Hook the function epilogue frame unwinder.  */
> +  frame_unwind_append_unwinder (gdbarch, &i386_epilogue_frame_unwind);
> +#endif
>   /* Hook in the DWARF CFI frame unwinder.  */
>   dwarf2_append_unwinders (gdbarch);
>
>
>


  reply	other threads:[~2009-07-05 10:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-04  0:26 Michael Snyder
2009-07-04  0:37 ` Michael Snyder
2009-07-05 10:54   ` Hui Zhu [this message]
2009-07-05 12:36   ` Mark Kettenis
2009-07-05 18:49     ` Daniel Jacobowitz
2009-07-05 20:46       ` Michael Snyder
2009-07-05 21:12         ` Daniel Jacobowitz
2009-07-05 20:58     ` Michael Snyder
2009-07-11 20:19       ` Michael Snyder
2009-07-12 17:07         ` Mark Kettenis
2009-07-12 17:53           ` Michael Snyder
2009-07-13  4:55             ` drow
2009-07-13 19:43               ` Michael Snyder
2009-07-13 19:44                 ` Daniel Jacobowitz
2009-07-13 20:28                   ` Michael Snyder
2009-07-13 20:20                 ` Mark Kettenis

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=daef60380907050354h4a96cc4eh586880fd8efd59b8@mail.gmail.com \
    --to=teawater@gmail.com \
    --cc=drow@false.org \
    --cc=gdb-patches@sourceware.org \
    --cc=kettenis@gnu.org \
    --cc=msnyder@vmware.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