Move map data into backtrace data proper.

The backtrace structure used to include a pointer to a backtrace_map_t
that represented the map data for a particular pc. This introduced a
race condition where the pointer could be discarded, but the backtrace
structure still contained a pointer to garbage memory. Now all of the map
information is right in the structure.

Bug: 19028453
Change-Id: If7088a73f3c6bf1f3bc8cdd2bb4b62e7cab831c0
diff --git a/libbacktrace/backtrace_test.cpp b/libbacktrace/backtrace_test.cpp
index 8002ed6..76aabd1 100644
--- a/libbacktrace/backtrace_test.cpp
+++ b/libbacktrace/backtrace_test.cpp
@@ -688,6 +688,25 @@
   delete map3;
 }
 
+TEST(libbacktrace, fillin_erases) {
+  BacktraceMap* back_map = BacktraceMap::Create(getpid());
+
+  backtrace_map_t map;
+
+  map.start = 1;
+  map.end = 3;
+  map.flags = 1;
+  map.name = "Initialized";
+  back_map->FillIn(0, &map);
+  delete back_map;
+
+  ASSERT_FALSE(BacktraceMap::IsValid(map));
+  ASSERT_EQ(static_cast<uintptr_t>(0), map.start);
+  ASSERT_EQ(static_cast<uintptr_t>(0), map.end);
+  ASSERT_EQ(0, map.flags);
+  ASSERT_EQ("", map.name);
+}
+
 TEST(libbacktrace, format_test) {
   UniquePtr<Backtrace> backtrace(Backtrace::Create(getpid(), BACKTRACE_CURRENT_THREAD));
   ASSERT_TRUE(backtrace.get() != NULL);
@@ -697,13 +716,8 @@
   frame.pc = 2;
   frame.sp = 0;
   frame.stack_size = 0;
-  frame.map = NULL;
   frame.func_offset = 0;
 
-  backtrace_map_t map;
-  map.start = 0;
-  map.end = 0;
-
   // Check no map set.
   frame.num = 1;
 #if defined(__LP64__)
@@ -714,8 +728,8 @@
             backtrace->FormatFrameData(&frame));
 
   // Check map name empty, but exists.
-  frame.map = &map;
-  map.start = 1;
+  frame.map.start = 1;
+  frame.map.end = 1;
 #if defined(__LP64__)
   EXPECT_EQ("#01 pc 0000000000000001  <unknown>",
 #else
@@ -726,9 +740,9 @@
 
   // Check relative pc is set and map name is set.
   frame.pc = 0x12345679;
-  frame.map = &map;
-  map.name = "MapFake";
-  map.start =  1;
+  frame.map.name = "MapFake";
+  frame.map.start =  1;
+  frame.map.end =  1;
 #if defined(__LP64__)
   EXPECT_EQ("#01 pc 0000000012345678  MapFake",
 #else