[patch] amd64-tdep.c: Recognize both variations of "mov %rsp,%rbp".

Doug Evans dje@google.com
Wed Apr 4 01:46:00 GMT 2012


Hi.

A code generator was using the other encoding of "mov %rsp,%rbp",
and this was confusing gdb.

Seems obvious, but I'll give it a few days for comment before
I check it in.

2012-04-03  Doug Evans  <dje@google.com>

	* amd64-tdep.c (amd64_analyze_prologue): Recognize both variations of
	"mov %rsp,%rbp".

==== amd64-tdep.c ====
--- amd64-tdep.c~
+++ amd64-tdep.c
@@ -1865,7 +1865,7 @@
    We will handle only functions beginning with:
 
       pushq %rbp        0x55
-      movq %rsp, %rbp   0x48 0x89 0xe5
+      movq %rsp, %rbp   0x48 0x89 0xe5 (or 0x48 0x8b 0xec)
 
    Any function that doesn't start with this sequence will be assumed
    to have no prologue and thus no valid frame pointer in %rbp.  */
@@ -1876,7 +1876,9 @@
 			struct amd64_frame_cache *cache)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  static gdb_byte proto[3] = { 0x48, 0x89, 0xe5 }; /* movq %rsp, %rbp */
+  /* There are two variations of movq %rsp, %rbp.  */
+  static const gdb_byte mov_rsp_rbp_1[3] = { 0x48, 0x89, 0xe5 };
+  static const gdb_byte mov_rsp_rbp_2[3] = { 0x48, 0x8b, 0xec };
   gdb_byte buf[3];
   gdb_byte op;
 
@@ -1900,7 +1902,8 @@
 
       /* Check for `movq %rsp, %rbp'.  */
       read_memory (pc + 1, buf, 3);
-      if (memcmp (buf, proto, 3) != 0)
+      if (memcmp (buf, mov_rsp_rbp_1, 3) != 0
+	  && memcmp (buf, mov_rsp_rbp_2, 3) != 0)
 	return pc + 1;
 
       /* OK, we actually have a frame.  */



More information about the Gdb-patches mailing list