blob: c123158efda1a8a110acdae0a9ca9b8371c41ba1 [file] [log] [blame]
Christopher Ferris0b06a592018-01-19 10:26:36 -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
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080017#ifndef _LIBUNWINDSTACK_DEX_FILE_H
18#define _LIBUNWINDSTACK_DEX_FILE_H
Christopher Ferris0b06a592018-01-19 10:26:36 -080019
20#include <stdint.h>
21
David Srbecky02d0f792018-03-24 00:29:14 +000022#include <map>
Christopher Ferris0b06a592018-01-19 10:26:36 -080023#include <memory>
24#include <string>
David Srbecky02d0f792018-03-24 00:29:14 +000025#include <utility>
Christopher Ferris0b06a592018-01-19 10:26:36 -080026#include <vector>
27
28#include <dex/dex_file-inl.h>
29
30namespace unwindstack {
Christopher Ferris0b06a592018-01-19 10:26:36 -080031
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080032class DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080033 public:
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080034 DexFile() = default;
35 virtual ~DexFile() = default;
Christopher Ferris0b06a592018-01-19 10:26:36 -080036
Christopher Ferris7747b602018-01-31 19:05:19 -080037 bool GetMethodInformation(uint64_t dex_offset, std::string* method_name, uint64_t* method_offset);
Christopher Ferris0b06a592018-01-19 10:26:36 -080038
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080039 static DexFile* Create(uint64_t dex_file_offset_in_memory, Memory* memory, MapInfo* info);
Christopher Ferris0b06a592018-01-19 10:26:36 -080040
41 protected:
David Srbecky02d0f792018-03-24 00:29:14 +000042 void Init();
43
Christopher Ferris0b06a592018-01-19 10:26:36 -080044 std::unique_ptr<const art::DexFile> dex_file_;
David Srbecky02d0f792018-03-24 00:29:14 +000045 std::map<uint32_t, std::pair<uint64_t, uint32_t>> method_cache_; // dex offset to method index.
46
47 uint32_t class_def_index_ = 0;
Christopher Ferris0b06a592018-01-19 10:26:36 -080048};
49
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080050class DexFileFromFile : public DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080051 public:
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080052 DexFileFromFile() = default;
53 virtual ~DexFileFromFile();
Christopher Ferris0b06a592018-01-19 10:26:36 -080054
55 bool Open(uint64_t dex_file_offset_in_file, const std::string& name);
56
57 private:
58 void* mapped_memory_ = nullptr;
59 size_t size_ = 0;
60};
61
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080062class DexFileFromMemory : public DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080063 public:
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080064 DexFileFromMemory() = default;
65 virtual ~DexFileFromMemory() = default;
Christopher Ferris0b06a592018-01-19 10:26:36 -080066
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080067 bool Open(uint64_t dex_file_offset_in_memory, Memory* memory);
Christopher Ferris0b06a592018-01-19 10:26:36 -080068
69 private:
70 std::vector<uint8_t> memory_;
71};
72
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080073} // namespace unwindstack
74
75#endif // _LIBUNWINDSTACK_DEX_FILE_H