Reinstate Addrcheck.  Some of the tests fail -- some of the leak ones
because the added VG_(find_root_memory)() is just a stub.  And there's a
problem with overlap checking that I haven't worked out yet.  Still it's a
start.  The commit also brings Memcheck back into the build process,
although mc_main.c is entirely commented out at the moment.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3352 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/Makefile.am b/Makefile.am
index 315e219..3fcc289 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,7 +5,9 @@
 
 ## include must be first for tool.h
 ## addrcheck must come after memcheck, for mac_*.o
-TOOLS =		none \
+TOOLS =		memcheck \
+		addrcheck \
+		none \
 		lackey \
 		corecheck \
 		massif
diff --git a/addrcheck/ac_main.c b/addrcheck/ac_main.c
index a911741..05a3b5c 100644
--- a/addrcheck/ac_main.c
+++ b/addrcheck/ac_main.c
@@ -571,7 +571,7 @@
                               Char* s, Addr base, SizeT size, Bool isWrite )
 {
    Bool ok;
-   Addr bad_addr;
+   Addr bad_addr = 0;   // Initialise to shut gcc up
 
    VGP_PUSHCC(VgpCheckMem);
 
@@ -624,7 +624,7 @@
                                    Char* s, Addr str )
 {
    Bool ok = True;
-   Addr bad_addr;
+   Addr bad_addr = 0;   // Initialise to shut gcc up
 
    VGP_PUSHCC(VgpCheckMem);
 
diff --git a/coregrind/vg_memory.c b/coregrind/vg_memory.c
index f4a0a4d..2a05966 100644
--- a/coregrind/vg_memory.c
+++ b/coregrind/vg_memory.c
@@ -1173,6 +1173,33 @@
    VG_(munmap)((void *)s->addr, s->len);
 }
 
+/* We'll call any RW mmaped memory segment, within the client address
+   range, which isn't SF_CORE, a root. */
+void VG_(find_root_memory)(void (*add_rootrange)(Addr a, SizeT sz))
+{
+   //VG_(message)(Vg_UserMsg, "Warning: VG_(find_root_memory) -- doing nothing");
+   //VG_(message)(Vg_UserMsg, "leak checking probably won't work as a result");
+#if 0
+   Segment *s;
+
+   for(s = VG_(first_segment)(); s != NULL; s = VG_(next_segment)(s)) {
+      UInt flags = s->flags & (SF_SHARED|SF_MMAP|SF_VALGRIND|SF_CORE|SF_STACK|SF
+_DEVICE);
+      if (flags != SF_MMAP && flags != SF_STACK)
+         continue;
+      if ((s->prot & (VKI_PROT_READ|VKI_PROT_WRITE)) != (VKI_PROT_READ|VKI_PROT_
+WRITE))
+         continue;
+      if (!VG_(is_client_addr)(s->addr) ||
+          !VG_(is_client_addr)(s->addr+s->len))
+         continue;
+
+      (*add_rootrange)(s->addr, s->len);
+   }
+#endif
+}
+
+
 /*--------------------------------------------------------------------*/
 /*--- Querying memory layout                                       ---*/
 /*--------------------------------------------------------------------*/
@@ -1184,7 +1211,6 @@
 
 Bool VG_(is_shadow_addr)(Addr a)
 {
-vg_assert(0);
    return a >= VG_(shadow_base) && a < VG_(shadow_end);
 }
 
diff --git a/memcheck/Makefile.am b/memcheck/Makefile.am
index 66cab64..7624d7e 100644
--- a/memcheck/Makefile.am
+++ b/memcheck/Makefile.am
@@ -17,9 +17,8 @@
 	mac_leakcheck.c \
 	mac_malloc_wrappers.c \
 	mac_needs.c \
-	mc_main.c \
 	mc_errcontext.c \
-	mc_from_ucode.c \
+	mc_main.c \
 	mc_translate.c
 vgtool_memcheck_so_LDFLAGS = -shared
 
diff --git a/memcheck/mac_malloc_wrappers.c b/memcheck/mac_malloc_wrappers.c
index cb84181..7250353 100644
--- a/memcheck/mac_malloc_wrappers.c
+++ b/memcheck/mac_malloc_wrappers.c
@@ -526,6 +526,49 @@
    die_and_free_mem ( tid, mc, prev_chunk, mp->rzB );
 }
 
+/*------------------------------------------------------------*/
+/*--- Statistics printing                                  ---*/
+/*------------------------------------------------------------*/
+
+typedef
+   struct {
+      UInt  nblocks;
+      SizeT nbytes;
+   }
+   MallocStats;
+
+static void malloc_stats_count_chunk(VgHashNode* node, void* d) {
+   MAC_Chunk* mc = (MAC_Chunk*)node;
+   MallocStats *ms = (MallocStats *)d;
+
+   ms->nblocks ++;
+   ms->nbytes  += mc->size;
+}
+
+void MAC_(print_malloc_stats) ( void )
+{
+   MallocStats ms;
+  
+   ms.nblocks = 0;
+   ms.nbytes = 0;
+   
+   if (VG_(clo_verbosity) == 0)
+      return;
+
+   /* Count memory still in use. */
+   VG_(HT_apply_to_all_nodes)(MAC_(malloc_list), malloc_stats_count_chunk, &ms);
+
+   VG_(message)(Vg_UserMsg, 
+                "malloc/free: in use at exit: %d bytes in %d blocks.",
+                ms.nbytes, ms.nblocks);
+   VG_(message)(Vg_UserMsg, 
+                "malloc/free: %d allocs, %d frees, %u bytes allocated.",
+                cmalloc_n_mallocs,
+                cmalloc_n_frees, cmalloc_bs_mallocd);
+   if (VG_(clo_verbosity) > 1)
+      VG_(message)(Vg_UserMsg, "");
+}
+
 /*--------------------------------------------------------------------*/
-/*--- end                                    mac_malloc_wrappers.c ---*/
+/*--- end                                                          ---*/
 /*--------------------------------------------------------------------*/
diff --git a/memcheck/mac_needs.c b/memcheck/mac_needs.c
index 745d03f..28a828e 100644
--- a/memcheck/mac_needs.c
+++ b/memcheck/mac_needs.c
@@ -829,50 +829,6 @@
 #endif
 
 /*------------------------------------------------------------*/
-/*--- Statistics printing                                  ---*/
-/*------------------------------------------------------------*/
-
-typedef
-   struct {
-      UInt  nblocks;
-      SizeT nbytes;
-   }
-   MallocStats;
-
-static void malloc_stats_count_chunk(VgHashNode* node, void* d) {
-   MAC_Chunk* mc = (MAC_Chunk*)node;
-   MallocStats *ms = (MallocStats *)d;
-
-   ms->nblocks ++;
-   ms->nbytes  += mc->size;
-}
-
-static void print_malloc_stats ( void )
-{
-   MallocStats ms;
-  
-   ms.nblocks = 0;
-   ms.nbytes = 0;
-   
-   /* Mmm... more lexical scoping */
-   if (VG_(clo_verbosity) == 0)
-      return;
-
-   /* Count memory still in use. */
-   VG_(HT_apply_to_all_nodes)(MAC_(malloc_list), malloc_stats_count_chunk, &ms);
-
-   VG_(message)(Vg_UserMsg, 
-                "malloc/free: in use at exit: %d bytes in %d blocks.",
-                ms.nbytes, ms.nblocks);
-   VG_(message)(Vg_UserMsg, 
-                "malloc/free: %d allocs, %d frees, %u bytes allocated.",
-                cmalloc_n_mallocs,
-                cmalloc_n_frees, cmalloc_bs_mallocd);
-   if (VG_(clo_verbosity) > 1)
-      VG_(message)(Vg_UserMsg, "");
-}
-
-/*------------------------------------------------------------*/
 /*--- Common initialisation + finalisation                 ---*/
 /*------------------------------------------------------------*/
 
@@ -885,7 +841,7 @@
 
 void MAC_(common_fini)(void (*leak_check)(LeakCheckMode mode))
 {
-   print_malloc_stats();
+   MAC_(print_malloc_stats)();
 
    if (VG_(clo_verbosity) == 1) {
       if (MAC_(clo_leak_check) == LC_Off)
diff --git a/memcheck/mac_replace_strmem.c b/memcheck/mac_replace_strmem.c
index 6c8b71d..0e4012f 100644
--- a/memcheck/mac_replace_strmem.c
+++ b/memcheck/mac_replace_strmem.c
@@ -352,7 +352,7 @@
    return dst;
 }
 
-void *memset(void *s, int c, size_t n)
+void *memset(void *s, Int c, SizeT n)
 {
    unsigned char *cp = s;
 
diff --git a/memcheck/mac_shared.h b/memcheck/mac_shared.h
index 2f6ad58..3b83b10 100644
--- a/memcheck/mac_shared.h
+++ b/memcheck/mac_shared.h
@@ -374,6 +374,8 @@
 extern void MAC_(pp_LeakError)(void* vl, UInt n_this_record, 
                                          UInt n_total_records); 
                            
+extern void MAC_(print_malloc_stats) ( void );
+
 extern void MAC_(do_detect_memory_leaks) (
           LeakCheckMode mode,
           Bool (*is_valid_64k_chunk) ( UInt ),
diff --git a/memcheck/mc_main.c b/memcheck/mc_main.c
index c4cef5b..c101175 100644
--- a/memcheck/mc_main.c
+++ b/memcheck/mc_main.c
@@ -88,7 +88,7 @@
    misaligned address.  
 */
 
-
+#if 0
 /*------------------------------------------------------------*/
 /*--- Function declarations.                               ---*/
 /*------------------------------------------------------------*/
@@ -1891,6 +1891,7 @@
 }
 
 VG_DETERMINE_INTERFACE_VERSION(TL_(pre_clo_init), 9./8)
+#endif
 
 /*--------------------------------------------------------------------*/
 /*--- end                                                mc_main.c ---*/