blob: 3d67a6a5b3e3c4103794cc2e7a489dacfc063f5a [file] [log] [blame]
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdint.h>
18#include <sys/mman.h>
19#include <sys/stat.h>
20#include <sys/types.h>
21#include <unistd.h>
22
23#include <memory>
24
25#include <unwindstack/DexFiles.h>
26#include <unwindstack/MapInfo.h>
27#include <unwindstack/Memory.h>
28
29#include "DexFile.h"
30
31namespace unwindstack {
32
33DexFiles::DexFiles(std::shared_ptr<Memory>& memory) : memory_(memory) {}
34
35DexFiles::~DexFiles() {
36 for (auto& entry : files_) {
37 delete entry.second;
38 }
39}
40
41DexFile* DexFiles::GetDexFile(uint64_t dex_file_offset, MapInfo* info) {
42 // Lock while processing the data.
43 std::lock_guard<std::mutex> guard(files_lock_);
44 DexFile* dex_file;
45 auto entry = files_.find(dex_file_offset);
46 if (entry == files_.end()) {
47 dex_file = DexFile::Create(dex_file_offset, memory_.get(), info);
48 files_[dex_file_offset] = dex_file;
49 } else {
50 dex_file = entry->second;
51 }
52 return dex_file;
53}
54
55void DexFiles::GetMethodInformation(uint64_t dex_offset, MapInfo* info, std::string* method_name,
56 uint64_t* method_offset) {
57 DexFile* dex_file = GetDexFile(dex_offset, info);
58 if (dex_file != nullptr) {
59 dex_file->GetMethodInformation(dex_offset, method_name, method_offset);
60 }
61}
62
63void DexFiles::SetArch(ArchEnum) {}
64
65} // namespace unwindstack