Fix problems in libbacktrace.

- Add a wait for stop to backtrace_test. There is a possible race
  condition that is exposed when using libunwind.
- Fix a few calls to unwind function calls.

Bug: 8410085
Change-Id: I7487d687f6d4b7b05b8a96ad1c5f7183681e5c95
diff --git a/libbacktrace/unwind_remote.c b/libbacktrace/unwind_remote.c
index ebbde2e..1c624d7 100644
--- a/libbacktrace/unwind_remote.c
+++ b/libbacktrace/unwind_remote.c
@@ -46,6 +46,7 @@
   bool returnValue = true;
   backtrace->num_frames = 0;
   uintptr_t map_start;
+  unw_word_t value;
   do {
     frame = &backtrace->frames[backtrace->num_frames];
     frame->stack_size = 0;
@@ -54,18 +55,21 @@
     frame->proc_name = NULL;
     frame->proc_offset = 0;
 
-    ret = unw_get_reg(&cursor, UNW_REG_IP, &frame->pc);
+    ret = unw_get_reg(&cursor, UNW_REG_IP, &value);
     if (ret < 0) {
       ALOGW("remote_get_frames: Failed to read IP %d\n", ret);
       returnValue = false;
       break;
     }
-    ret = unw_get_reg(&cursor, UNW_REG_SP, &frame->sp);
+    frame->pc = (uintptr_t)value;
+    ret = unw_get_reg(&cursor, UNW_REG_SP, &value);
     if (ret < 0) {
       ALOGW("remote_get_frames: Failed to read SP %d\n", ret);
       returnValue = false;
       break;
     }
+    frame->sp = (uintptr_t)value;
+
     if (backtrace->num_frames) {
       backtrace_frame_data_t* prev = &backtrace->frames[backtrace->num_frames-1];
       prev->stack_size = frame->sp - prev->sp;
@@ -139,8 +143,11 @@
   backtrace_private_t* data = (backtrace_private_t*)backtrace->private_data;
   char buf[512];
 
-  if (unw_get_proc_name_by_ip(data->addr_space, pc, buf, sizeof(buf), offset,
+  *offset = 0;
+  unw_word_t value;
+  if (unw_get_proc_name_by_ip(data->addr_space, pc, buf, sizeof(buf), &value,
                               data->upt_info) >= 0 && buf[0] != '\0') {
+    *offset = (uintptr_t)value;
     char* symbol = demangle_symbol_name(buf);
     if (!symbol) {
       symbol = strdup(buf);