Re-enable libunwind for arm.

Update to handle the new optimized way that libunwind works.

In addition, a small refactor of the BacktraceMap code.

A few new tests of for good measure.

Change-Id: I2f9b4f5ad5a0dfe907b31febee76e4b9b94fb76f
diff --git a/libbacktrace/Corkscrew.cpp b/libbacktrace/Corkscrew.cpp
index fd31a26..efeee2e 100644
--- a/libbacktrace/Corkscrew.cpp
+++ b/libbacktrace/Corkscrew.cpp
@@ -65,7 +65,8 @@
     }
     map.name = cur_map->name;
 
-    maps_.push_back(map);
+    // The maps are in descending order, but we want them in ascending order.
+    maps_.push_front(map);
 
     cur_map = cur_map->next;
   }
@@ -93,8 +94,8 @@
     it->stack_size = cork_frames[i].stack_size;
     it->func_offset = 0;
 
-    it->map = backtrace_obj_->FindMap(it->pc);
-    it->func_name = backtrace_obj_->GetFunctionName(it->pc, &it->func_offset);
+    it->map = FindMap(it->pc);
+    it->func_name = GetFunctionName(it->pc, &it->func_offset);
   }
   return true;
 }
@@ -119,7 +120,7 @@
   *offset = 0;
 
   Dl_info info;
-  const backtrace_map_t* map = backtrace_obj_->FindMap(pc);
+  const backtrace_map_t* map = FindMap(pc);
   if (map) {
     if (dladdr((const void*)pc, &info)) {
       if (info.dli_sname) {
@@ -158,19 +159,10 @@
 CorkscrewThread::~CorkscrewThread() {
 }
 
-bool CorkscrewThread::Init() {
-  if (backtrace_obj_->GetMap() == NULL) {
-    // Trigger the map object creation, which will create the corkscrew
-    // map information.
-    return BuildMap();
-  }
-  return true;
-}
-
 void CorkscrewThread::ThreadUnwind(
     siginfo_t* siginfo, void* sigcontext, size_t num_ignore_frames) {
   backtrace_frame_t cork_frames[MAX_BACKTRACE_FRAMES];
-  CorkscrewMap* map = static_cast<CorkscrewMap*>(backtrace_obj_->GetMap());
+  CorkscrewMap* map = static_cast<CorkscrewMap*>(GetMap());
   ssize_t num_frames = unwind_backtrace_signal_arch(
       siginfo, sigcontext, map->GetMapInfo(), cork_frames,
       num_ignore_frames, MAX_BACKTRACE_FRAMES);
@@ -204,12 +196,11 @@
 }
 
 bool CorkscrewPtrace::Unwind(size_t num_ignore_frames) {
-  ptrace_context_ = load_ptrace_context(backtrace_obj_->Tid());
+  ptrace_context_ = load_ptrace_context(Tid());
 
   backtrace_frame_t frames[MAX_BACKTRACE_FRAMES];
   ssize_t num_frames = unwind_backtrace_ptrace(
-      backtrace_obj_->Tid(), ptrace_context_, frames, num_ignore_frames,
-      MAX_BACKTRACE_FRAMES);
+      Tid(), ptrace_context_, frames, num_ignore_frames, MAX_BACKTRACE_FRAMES);
 
   return GenerateFrameData(frames, num_frames);
 }
@@ -246,3 +237,15 @@
   CorkscrewThread* thread_obj = new CorkscrewThread();
   return new BacktraceThread(thread_obj, thread_obj, tid, map);
 }
+
+//-------------------------------------------------------------------------
+// BacktraceMap create function.
+//-------------------------------------------------------------------------
+BacktraceMap* BacktraceMap::Create(pid_t pid) {
+  BacktraceMap* map = new CorkscrewMap(pid);
+  if (!map->Build()) {
+    delete map;
+    return NULL;
+  }
+  return map;
+}