This commit completely overhauls the leak checker.  In particular:

- It heavily refactors the code:  uses better names for things, splits up
  complex functions that behaved very differently depending on how they were
  called, removes some redundancies, and generally makes it much simpler and
  easier to follow.

- It adds lots of comments, both inline, and also a big explanatory one at
  the top which makes it clear exactly how the leak checker works and also
  exactly what is meant by definite, possible, and indirect leaks.  It also
  has some ideas for future improvements.

- All tabs have been converted to spaces.

It also improves the functionality:

- Previously if you did --leak-check=summary, indirect and suppressed
  blocks were counted as definite leaks.  Now they are done properly, and so
  the summary results from --leak-check=summary match those from
  --leak-check=yes.

- Previously, some possibly reachable blocks were miscategorised as
  definitely reachable, because only the pointer to the block itself was
  considered, not any preceding pointers in the chain.  This is now fixed.

- Added memcheck/tests/leak-cases, which fully tests all the possible
  combinations of directly/indirectly reachable and possibly/definitely
  reachable.

And it improves the manual quite a bit, and the FAQ a little bit.

This doesn't fix the leak checker to handle MALLOCLIKE_BLOCK works that have
been taken from within malloc'd blocks, but I think I know how to do it and
hope to do so in a subsequent commit.

It also changes all instances of "<constant>memcheck</constant>" in the
Memcheck manual to "Memcheck", for consistency and because "Memcheck" is
easier to write.  There's one similar case for DRD but I didn't change that.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9330 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/memcheck/mc_include.h b/memcheck/mc_include.h
index 0f5f66a..5d4e8f3 100644
--- a/memcheck/mc_include.h
+++ b/memcheck/mc_include.h
@@ -55,14 +55,15 @@
    }
    MC_AllocKind;
    
-/* Nb: first two fields must match core's VgHashNode. */
+/* This describes a heap block. Nb: first two fields must match core's
+ * VgHashNode. */
 typedef
    struct _MC_Chunk {
       struct _MC_Chunk* next;
-      Addr         data;            // ptr to actual block
-      SizeT        szB : (sizeof(UWord)*8)-2; // size requested; 30 or 62 bits
-      MC_AllocKind allockind : 2;   // which wrapper did the allocation
-      ExeContext*  where;           // where it was allocated
+      Addr         data;            // Address of the actual block.
+      SizeT        szB : (sizeof(SizeT)*8)-2; // Size requested; 30 or 62 bits.
+      MC_AllocKind allockind : 2;   // Which operation did the allocation.
+      ExeContext*  where;           // Where it was allocated.
    }
    MC_Chunk;
 
@@ -227,18 +228,15 @@
 /*--- Leak checking                                        ---*/
 /*------------------------------------------------------------*/
 
-/* A block is either 
-   -- Proper-ly reached; a pointer to its start has been found
-   -- Interior-ly reached; only an interior pointer to it has been found
-   -- Unreached; so far, no pointers to any part of it have been found. 
-   -- IndirectLeak; leaked, but referred to by another leaked block
-*/
 typedef 
    enum { 
-      Unreached    =0, 
-      IndirectLeak =1,
-      Interior     =2, 
-      Proper       =3
+      Unreached    =0,  // Not reached, ie. leaked. 
+                        //   (At best, only reachable from itself via a cycle.
+      IndirectLeak =1,  // Leaked, but reachable from another leaked block
+                        //   (be it Unreached or IndirectLeak).
+      Possible     =2,  // Possibly reachable from root-set;  involves at
+                        //   least one interior-pointer along the way.
+      Reachable    =3   // Definitely reachable from root-set.
   }
   Reachedness;
 
@@ -274,16 +272,15 @@
       Reachedness  loss_mode;
       /* Number of blocks and total # bytes involved. */
       SizeT        total_bytes;
-      SizeT        indirect_bytes;
+      SizeT        indirect_szB;
       UInt         num_blocks;
    }
    LossRecord;
 
-void MC_(do_detect_memory_leaks) (
-        ThreadId tid, LeakCheckMode mode,
-        Bool (*is_within_valid_secondary) ( Addr ),
-        Bool (*is_valid_aligned_word)     ( Addr )
-     );
+void MC_(detect_memory_leaks) ( ThreadId tid, LeakCheckMode mode );
+
+Bool MC_(is_valid_aligned_word)     ( Addr a );
+Bool MC_(is_within_valid_secondary) ( Addr a );
 
 void MC_(pp_LeakError)(UInt n_this_record, UInt n_total_records,
                        LossRecord* l);