Added overlap checking to Addrcheck, mostly just moving things around.  In
particular, renamed mc_replace_strmem.c as mac_replace_strmem.c;  the 'mac'
prefix indicates it's shared between Memcheck and Addrcheck.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1774 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/memcheck/Makefile.am b/memcheck/Makefile.am
index e938507..3463d2c 100644
--- a/memcheck/Makefile.am
+++ b/memcheck/Makefile.am
@@ -16,11 +16,11 @@
 	mac_leakcheck.c \
 	mac_malloc_wrappers.c \
 	mac_needs.c \
+	mac_replace_strmem.c \
 	mc_main.c \
 	mc_clientreqs.c \
 	mc_errcontext.c \
 	mc_from_ucode.c \
-	mc_replace_strmem.c \
 	mc_translate.c \
 	mc_helpers.S
 vgskin_memcheck_so_LDFLAGS = -shared
@@ -36,5 +36,5 @@
 	mc_constants.h	\
 	mc_include.h
 
-mc_replace_strmem.o: CFLAGS += -fno-omit-frame-pointer
+mac_replace_strmem.o: CFLAGS += -fno-omit-frame-pointer
 
diff --git a/memcheck/mac_needs.c b/memcheck/mac_needs.c
index daec938..e90151e 100644
--- a/memcheck/mac_needs.c
+++ b/memcheck/mac_needs.c
@@ -287,6 +287,13 @@
          MAC_(pp_AddrInfo)(VG_(get_error_address)(err), &err_extra->addrinfo);
          break;
 
+      case OverlapErr:
+         VG_(message)(Vg_UserMsg, 
+                      "Source and destination overlap in %s",
+                      VG_(get_error_string)(err));
+         VG_(pp_ExeContext)( VG_(get_error_where)(err) );
+         break;
+
       case LeakErr: {
          /* Totally abusing the types of these spare fields... oh well. */
          UInt n_this_record   = (UInt)VG_(get_error_address)(err);
@@ -464,6 +471,16 @@
    VG_(maybe_record_error)( tst, FreeMismatchErr, a, /*s*/NULL, &err_extra );
 }
 
+
+void MAC_(record_overlap_error) ( ThreadState* tst, Char* function )
+{
+   MAC_Error err_extra;
+
+   MAC_(clear_MAC_Error)( &err_extra );
+   VG_(maybe_record_error)( tst, OverlapErr, /*addr*/0, function, &err_extra );
+}
+
+
 /* Updates the copy with address info if necessary (but not for LeakErrs). */
 UInt SK_(update_extra)( Error* err )
 {
diff --git a/memcheck/mc_replace_strmem.c b/memcheck/mac_replace_strmem.c
similarity index 96%
rename from memcheck/mc_replace_strmem.c
rename to memcheck/mac_replace_strmem.c
index 0f1ce07..f40128f 100644
--- a/memcheck/mc_replace_strmem.c
+++ b/memcheck/mac_replace_strmem.c
@@ -2,7 +2,7 @@
 /*--------------------------------------------------------------------*/
 /*--- Replacements for strcpy(), memcpy() et al, which run on the  ---*/
 /*--- simulated CPU.                                               ---*/
-/*---                                          mc_replace_strmem.c ---*/
+/*---                                         mac_replace_strmem.c ---*/
 /*--------------------------------------------------------------------*/
 
 /*
@@ -84,7 +84,7 @@
 {
    Char buf[256];
    snprintf(buf, 100, "%s(%p, %p)", s, dst, src );
-   VALGRIND_NON_SIMD_tstCALL1( MC_(record_overlap_error), buf );
+   VALGRIND_NON_SIMD_tstCALL1( MAC_(record_overlap_error), buf );
 }
 
 static __inline__
@@ -92,7 +92,7 @@
 {
    Char buf[256];
    snprintf(buf, 100, "%s(%p, %p, %d)", s, dst, src, n );
-   VALGRIND_NON_SIMD_tstCALL1( MC_(record_overlap_error), buf );
+   VALGRIND_NON_SIMD_tstCALL1( MAC_(record_overlap_error), buf );
 }
 
 char* strrchr ( const char* s, int c )
@@ -281,5 +281,5 @@
 
 
 /*--------------------------------------------------------------------*/
-/*--- end                                      mc_replace_strmem.c ---*/
+/*--- end                                     mac_replace_strmem.c ---*/
 /*--------------------------------------------------------------------*/
diff --git a/memcheck/mac_shared.h b/memcheck/mac_shared.h
index 5cb9893..ffdf83b 100644
--- a/memcheck/mac_shared.h
+++ b/memcheck/mac_shared.h
@@ -304,6 +304,7 @@
 extern void MAC_(record_jump_error)        ( ThreadState* tst, Addr a );
 extern void MAC_(record_free_error)        ( ThreadState* tst, Addr a );
 extern void MAC_(record_freemismatch_error)( ThreadState* tst, Addr a );
+extern void MAC_(record_overlap_error)     ( ThreadState* tst, Char* function );
 
 extern void MAC_(pp_shared_SkinError)      ( Error* err);
 
diff --git a/memcheck/mc_errcontext.c b/memcheck/mc_errcontext.c
index 9eb0ae8..5539b22 100644
--- a/memcheck/mc_errcontext.c
+++ b/memcheck/mc_errcontext.c
@@ -114,13 +114,6 @@
          MAC_(pp_AddrInfo)(VG_(get_error_address)(err), &err_extra->addrinfo);
          break;
 
-      case OverlapErr:
-         VG_(message)(Vg_UserMsg, 
-                      "Source and destination overlap in %s",
-                      VG_(get_error_string)(err));
-         VG_(pp_ExeContext)( VG_(get_error_where)(err) );
-         break;
-
       default: 
          MAC_(pp_shared_SkinError)(err);
          break;
@@ -143,7 +136,7 @@
    VG_(maybe_record_error)( tst, ValueErr, /*addr*/0, /*s*/NULL, &err_extra );
 }
 
-/* These two called from non-generated code */
+/* This called from non-generated code */
 
 void MC_(record_user_error) ( ThreadState* tst, Addr a, Bool isWrite )
 {
@@ -157,14 +150,6 @@
    VG_(maybe_record_error)( tst, UserErr, a, /*s*/NULL, &err_extra );
 }
 
-void MC_(record_overlap_error) ( ThreadState* tst, Char* function )
-{
-   MAC_Error err_extra;
-
-   MAC_(clear_MAC_Error)( &err_extra );
-   VG_(maybe_record_error)( tst, OverlapErr, /*addr*/0, function, &err_extra );
-}
-
 /*------------------------------------------------------------*/
 /*--- Suppressions                                         ---*/
 /*------------------------------------------------------------*/
diff --git a/memcheck/mc_include.h b/memcheck/mc_include.h
index 63aee18..40458dc 100644
--- a/memcheck/mc_include.h
+++ b/memcheck/mc_include.h
@@ -113,14 +113,14 @@
 /*--- Functions                                            ---*/
 /*------------------------------------------------------------*/
 
-/* Functions defined in vg_memcheck_helpers.S */
+/* Functions defined in mc_helpers.S */
 extern void MC_(helper_value_check4_fail) ( void );
 extern void MC_(helper_value_check2_fail) ( void );
 extern void MC_(helper_value_check1_fail) ( void );
 extern void MC_(helper_value_check0_fail) ( void );
 
 
-/* Functions defined in vg_memcheck.c */
+/* Functions defined in mc_main.c */
 extern void MC_(helperc_STOREV4) ( Addr, UInt );
 extern void MC_(helperc_STOREV2) ( Addr, UInt );
 extern void MC_(helperc_STOREV1) ( Addr, UInt );
@@ -151,15 +151,14 @@
                Bool setting /* True <=> set vbits,  False <=> get vbits */ 
             );
 
-/* Functions defined in vg_memcheck_clientreqs.c */
+/* Functions defined in mc_clientreqs.c */
 extern Bool MC_(client_perm_maybe_describe)( Addr a, AddrInfo* ai );
 extern void MC_(show_client_block_stats) ( void );
 
 
-/* Functions defined in vg_memcheck_errcontext.c */
+/* Functions defined in mc_errcontext.c */
 extern void MC_(record_value_error)  ( ThreadState* tst, Int size );
 extern void MC_(record_user_error)   ( ThreadState* tst, Addr a, Bool isWrite );
-extern void MC_(record_overlap_error)( ThreadState* tst, Char* function );
 
 
 #endif
diff --git a/memcheck/tests/filter_stderr b/memcheck/tests/filter_stderr
index 1c0a295..4d7aaf8 100755
--- a/memcheck/tests/filter_stderr
+++ b/memcheck/tests/filter_stderr
@@ -7,8 +7,8 @@
 # Anonymise addresses
 $dir/../../tests/filter_addresses                       |
 
-# Anonymise line numbers in mc_replace_strmem.c
-sed "s/mc_replace_strmem.c:[0-9]\+/mc_replace_strmem.c:.../"  |
+# Anonymise line numbers in mac_replace_strmem.c
+sed "s/mac_replace_strmem.c:[0-9]\+/mac_replace_strmem.c:.../"  |
 
 $dir/../../tests/filter_test_paths                      |
 
diff --git a/memcheck/tests/overlap.stderr.exp b/memcheck/tests/overlap.stderr.exp
index 02180eb..6468d48 100644
--- a/memcheck/tests/overlap.stderr.exp
+++ b/memcheck/tests/overlap.stderr.exp
@@ -1,41 +1,41 @@
 Source and destination overlap in memcpy(0x........, 0x........, 21)
-   at 0x........: memcpy (mc_replace_strmem.c:...)
+   at 0x........: memcpy (mac_replace_strmem.c:...)
    by 0x........: main (overlap.c:40)
    by 0x........: __libc_start_main (...libc...)
    by 0x........: ...
 
 Source and destination overlap in memcpy(0x........, 0x........, 21)
-   at 0x........: memcpy (mc_replace_strmem.c:...)
+   at 0x........: memcpy (mac_replace_strmem.c:...)
    by 0x........: main (overlap.c:42)
    by 0x........: __libc_start_main (...libc...)
    by 0x........: ...
 
 Source and destination overlap in strncpy(0x........, 0x........, 21)
-   at 0x........: strncpy (mc_replace_strmem.c:...)
+   at 0x........: strncpy (mac_replace_strmem.c:...)
    by 0x........: main (overlap.c:45)
    by 0x........: __libc_start_main (...libc...)
    by 0x........: ...
 
 Source and destination overlap in strncpy(0x........, 0x........, 21)
-   at 0x........: strncpy (mc_replace_strmem.c:...)
+   at 0x........: strncpy (mac_replace_strmem.c:...)
    by 0x........: main (overlap.c:47)
    by 0x........: __libc_start_main (...libc...)
    by 0x........: ...
 
 Source and destination overlap in strcpy(0x........, 0x........)
-   at 0x........: strcpy (mc_replace_strmem.c:...)
+   at 0x........: strcpy (mac_replace_strmem.c:...)
    by 0x........: main (overlap.c:54)
    by 0x........: __libc_start_main (...libc...)
    by 0x........: ...
 
 Source and destination overlap in strncat(0x........, 0x........, 21)
-   at 0x........: strncat (mc_replace_strmem.c:...)
+   at 0x........: strncat (mac_replace_strmem.c:...)
    by 0x........: main (overlap.c:112)
    by 0x........: __libc_start_main (...libc...)
    by 0x........: ...
 
 Source and destination overlap in strncat(0x........, 0x........, 21)
-   at 0x........: strncat (mc_replace_strmem.c:...)
+   at 0x........: strncat (mac_replace_strmem.c:...)
    by 0x........: main (overlap.c:113)
    by 0x........: __libc_start_main (...libc...)
    by 0x........: ...