If a race error is detected, check to see whether the raced-on address
is inside a heap block, and if so, print the allocation point of the
heap block.  It's stupid not to do this considering that the
implementation already keeps track of all mallocs and frees.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11089 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c
index 19dd1f9..2f4e13b 100644
--- a/helgrind/hg_main.c
+++ b/helgrind/hg_main.c
@@ -3868,6 +3868,36 @@
 }
 
 
+/* For error creation: map 'data_addr' to a malloc'd chunk, if any.
+   Slow linear search. */
+
+static inline Bool addr_is_in_MM_Chunk( MallocMeta* mm, Addr a )
+{
+   if (a < mm->payload) return False;
+   if (a >= mm->payload + mm->szB) return False;
+   return True;
+}
+
+void HG_(mm_find_containing_block)( /*OUT*/ExeContext** where,
+                                    /*OUT*/Addr*        payload,
+                                    /*OUT*/SizeT*       szB,
+                                    Addr                data_addr )
+{
+   MallocMeta* mm;
+   /* Well, this totally sucks.  But without using an interval tree or
+      some such, it's hard to see how to do better. */
+   VG_(HT_ResetIter)(hg_mallocmeta_table);
+   while ( (mm = VG_(HT_Next)(hg_mallocmeta_table)) ) {
+      if (UNLIKELY(addr_is_in_MM_Chunk(mm, data_addr))) {
+         *where   = mm->where;
+         *payload = mm->payload;
+         *szB     = mm->szB;
+         return;
+      }
+   }
+}
+
+
 /*--------------------------------------------------------------*/
 /*--- Instrumentation                                        ---*/
 /*--------------------------------------------------------------*/