Check for data races when reading JIT/DEX entries.

Update the entries only when the list is modified by the runtime.

Check that the list wasn't concurrently modified when being read.

Bug: 124287208
Test: libunwindstack_test
Test: art/test.py -b --host -r -t 137-cfi
Change-Id: I87ba70322053a01b3d5be1fdf6310e1dc21bb084
diff --git a/libunwindstack/DexFile.cpp b/libunwindstack/DexFile.cpp
index eaf867f..d8d5a24 100644
--- a/libunwindstack/DexFile.cpp
+++ b/libunwindstack/DexFile.cpp
@@ -35,22 +35,31 @@
 std::unique_ptr<DexFile> DexFile::Create(uint64_t dex_file_offset_in_memory, Memory* memory,
                                          MapInfo* info) {
   if (!info->name.empty()) {
-    std::unique_ptr<DexFile> dex_file =
+    std::unique_ptr<DexFile> dex_file_from_file =
         DexFileFromFile::Create(dex_file_offset_in_memory - info->start + info->offset, info->name);
-    if (dex_file) {
-      return dex_file;
+    if (dex_file_from_file) {
+      dex_file_from_file->addr_ = dex_file_offset_in_memory;
+      return dex_file_from_file;
     }
   }
-  return DexFileFromMemory::Create(dex_file_offset_in_memory, memory, info->name);
+  std::unique_ptr<DexFile> dex_file_from_memory =
+      DexFileFromMemory::Create(dex_file_offset_in_memory, memory, info->name);
+  if (dex_file_from_memory) {
+    dex_file_from_memory->addr_ = dex_file_offset_in_memory;
+    return dex_file_from_memory;
+  }
+  return nullptr;
 }
 
-bool DexFile::GetMethodInformation(uint64_t dex_offset, std::string* method_name,
-                                   uint64_t* method_offset) {
+bool DexFile::GetFunctionName(uint64_t dex_pc, std::string* method_name, uint64_t* method_offset) {
+  uint64_t dex_offset = dex_pc - addr_;
   art_api::dex::MethodInfo method_info = GetMethodInfoForOffset(dex_offset, false);
   if (method_info.offset == 0) {
     return false;
   }
-  *method_name = method_info.name;
+  if (method_name != nullptr) {
+    *method_name = method_info.name;
+  }
   *method_offset = dex_offset - method_info.offset;
   return true;
 }