blob: 3ce2f1edd42ca6b74e496d1178cfb8c8c6024099 [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
22#include <memory>
23#include <string>
24#include <vector>
25
26#include <dex/dex_file-inl.h>
27
28namespace unwindstack {
Christopher Ferris0b06a592018-01-19 10:26:36 -080029
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080030class DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080031 public:
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080032 DexFile() = default;
33 virtual ~DexFile() = default;
Christopher Ferris0b06a592018-01-19 10:26:36 -080034
Christopher Ferris7747b602018-01-31 19:05:19 -080035 bool GetMethodInformation(uint64_t dex_offset, std::string* method_name, uint64_t* method_offset);
Christopher Ferris0b06a592018-01-19 10:26:36 -080036
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080037 static DexFile* Create(uint64_t dex_file_offset_in_memory, Memory* memory, MapInfo* info);
Christopher Ferris0b06a592018-01-19 10:26:36 -080038
39 protected:
40 std::unique_ptr<const art::DexFile> dex_file_;
41};
42
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080043class DexFileFromFile : public DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080044 public:
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080045 DexFileFromFile() = default;
46 virtual ~DexFileFromFile();
Christopher Ferris0b06a592018-01-19 10:26:36 -080047
48 bool Open(uint64_t dex_file_offset_in_file, const std::string& name);
49
50 private:
51 void* mapped_memory_ = nullptr;
52 size_t size_ = 0;
53};
54
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080055class DexFileFromMemory : public DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080056 public:
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080057 DexFileFromMemory() = default;
58 virtual ~DexFileFromMemory() = default;
Christopher Ferris0b06a592018-01-19 10:26:36 -080059
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080060 bool Open(uint64_t dex_file_offset_in_memory, Memory* memory);
Christopher Ferris0b06a592018-01-19 10:26:36 -080061
62 private:
63 std::vector<uint8_t> memory_;
64};
65
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080066} // namespace unwindstack
67
68#endif // _LIBUNWINDSTACK_DEX_FILE_H