Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Pierre Muller" <muller@ics.u-strasbg.fr>
To: "'Joel Brobecker'" <brobecker@adacore.com>,
		"'Mark Kettenis'" <mark.kettenis@xs4all.nl>
Cc: <gdb-patches@sourceware.org>
Subject: [RFA] i386-tdep.c: Add i386_skip_noop function; updated
Date: Fri, 25 Jan 2008 16:46:00 -0000	[thread overview]
Message-ID: <000001c85f70$9a33c8c0$ce9b5a40$@u-strasbg.fr> (raw)
In-Reply-To: <20080125161247.GJ3979@adacore.com>

  Joel,
  I took your suggestions into account.

  I hope this sounds better for everyone.


ChangeLog entry:
2008-01-25  Pierre Muller  <muller@ics.u-strasbg.fr>

	* i386-tdep.c (i386_skip_noop): New function.
	(i386_analyze_prologue): Call i386_skip_noop function.


Index: gdb/i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.248
diff -u -p -r1.248 i386-tdep.c
--- gdb/i386-tdep.c     11 Jan 2008 13:20:00 -0000      1.248
+++ gdb/i386-tdep.c     25 Jan 2008 16:35:10 -0000
@@ -632,6 +632,39 @@ struct i386_insn i386_frame_setup_skip_i
   { 0 }
 };

+
+/* Check whether PC points to a no-op instruction.  */
+static CORE_ADDR
+i386_skip_noop (CORE_ADDR pc)
+{
+  gdb_byte op[2];
+
+  if (read_memory_nobpt (pc, (gdb_byte *) &op, 2) != 0)
+    return pc;
+/* Some functions in Microsoft's system dlls start with a
+   `mov %edi,%edi' instruction, which is effectively a 2-byte `nop'.
+   This instruction is used for hot patching support, together with
+   5 bytes of slack before the function.  Later, when hot-patching, the
+   2-byte op can be replaced with a relative jump 5 bytes back.  The
+   5-byte slack is large enough to hold a jump into anywhere in
+   the 32-bit address space.
+   A 2-byte nop is used to be sure that no thread is executing
+   the instruction at byte 1 of the function, so the patching can be
+   performed atomically.  */
+
+/* We've heard of a couple of code generation tools that do something
similar
+   as Microsoft and insert nop instructions at the start of a function to
be
+   patched up later.  So other targets could benefit from the same code.
+   And calling this function unconditionally keeps the code simple.  */
+
+  if (op[0] == 0x8b && op[1] == 0xff) /* mov %edi,%edi */
+    {
+      return pc + 2;
+    }
+
+  return pc;
+}
+
 /* Check whether PC points at a code that sets up a new stack frame.
    If so, it updates CACHE and returns the address of the first
    instruction after the sequence that sets up the frame or LIMIT,
@@ -817,6 +850,7 @@ static CORE_ADDR
 i386_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
                       struct i386_frame_cache *cache)
 {
+  pc = i386_skip_noop (pc);
   pc = i386_follow_jump (pc);
   pc = i386_analyze_struct_return (pc, current_pc, cache);
   pc = i386_skip_probe (pc);





  reply	other threads:[~2008-01-25 16:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-10 16:45 [RFC] Enhance backtrace for microsoft system DLL calls Pierre Muller
2007-12-10 17:37 ` Pedro Alves
2007-12-10 18:08   ` Daniel Jacobowitz
2007-12-10 18:41 ` Pedro Alves
2007-12-11 10:44 ` Mark Kettenis
2007-12-11 17:29   ` Pierre Muller
2008-01-14 10:16     ` [RFC-v2] " Pierre Muller
2008-01-24  0:52       ` Pedro Alves
2008-01-24 17:51       ` Mark Kettenis
2008-01-25 14:16         ` [RFA] i386-tdep.c: Add i386_skip_noop function Pierre Muller
2008-01-25 16:38           ` Joel Brobecker
2008-01-25 16:46             ` Pierre Muller [this message]
2008-01-25 17:05               ` [RFA] i386-tdep.c: Add i386_skip_noop function; updated Mark Kettenis
2008-01-25 17:26                 ` Joel Brobecker
2008-01-25 18:50                 ` Pierre Muller

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='000001c85f70$9a33c8c0$ce9b5a40$@u-strasbg.fr' \
    --to=muller@ics.u-strasbg.fr \
    --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