Merge patch from JeremyF:

56-chained-accounting

Fix accounting for chained blocks, by only counting real unchain
events, rather than the unchains used to establish the initial call to
VG_(patch_me) at the jump site.

Also a minor cleanup of the jump delta calculation in synth_jcond_lit.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1340 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/vg_from_ucode.c b/coregrind/vg_from_ucode.c
index 645988c..5085b43 100644
--- a/coregrind/vg_from_ucode.c
+++ b/coregrind/vg_from_ucode.c
@@ -1053,6 +1053,17 @@
    return (*cp == 0xE9);		/* 0xE9 -- jmp */
 }
 
+static 
+Bool is_fresh_jumpsite(UChar *cp)
+{
+   return
+      cp[0] == 0x0F &&		/* UD2 */
+      cp[1] == 0x0B &&
+      cp[2] == 0x0F &&		/* UD2 */
+      cp[3] == 0x0B &&
+      cp[4] == 0x90;		/* NOP */
+}
+
 /* Predicate used in sanity checks elsewhere - returns true if all
    jump-sites are calls to VG_(patch_me) */
 Bool VG_(is_unchained_jumpsite)(Addr a)
@@ -1098,12 +1109,14 @@
    if (VG_(is_unchained_jumpsite)(a))
       return;			/* don't write unnecessarily */
 
+   if (!is_fresh_jumpsite(cp))
+      VG_(bb_dechain_count)++;     /* update stats */
+
    *cp++ = 0xE8;		/* call */
    *cp++ = (delta >>  0) & 0xff;
    *cp++ = (delta >>  8) & 0xff;
    *cp++ = (delta >> 16) & 0xff;
    *cp++ = (delta >> 24) & 0xff;
-   VG_(bb_dechain_count)++;     /* update stats */
 }
 
 /* This doesn't actually generate a call to VG_(patch_me), but
@@ -1569,11 +1582,10 @@
 		mov    $0x4000d190,%eax			// 5
 		mov    %eax, VGOFF_(m_eip)(%ebp)	// 3
 		call   0x40050f9a <vgPlain_patch_me>	// 5
-		$01					// 1
 	1:	mov    $0x4000d042,%eax
 		call   0x40050f9a <vgPlain_patch_me>
       */
-      delta = 5+3+5+1 -1;
+      delta = 5+3+5;
    } else
       delta = 5+1;