blob: fe185dae01514c0c041c98716798618733bfd298 [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
Martin Stjernholmb49289b2018-12-14 15:26:32 +000028#include <art_api/dex_file_support.h>
Christopher Ferris0b06a592018-01-19 10:26:36 -080029
30namespace unwindstack {
Christopher Ferris0b06a592018-01-19 10:26:36 -080031
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000032class DexFile : protected art_api::dex::DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080033 public:
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080034 virtual ~DexFile() = default;
Christopher Ferris0b06a592018-01-19 10:26:36 -080035
David Srbeckyb9cc4fb2019-04-05 18:23:32 +000036 bool GetMethodInformation(uint64_t dex_offset, std::string* method_name, uint64_t* method_offset);
Christopher Ferris0b06a592018-01-19 10:26:36 -080037
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000038 static std::unique_ptr<DexFile> Create(uint64_t dex_file_offset_in_memory, Memory* memory,
39 MapInfo* info);
Christopher Ferris0b06a592018-01-19 10:26:36 -080040
41 protected:
Yong Li489c3a82020-03-19 18:43:06 +000042 DexFile(std::unique_ptr<art_api::dex::DexFile>& art_dex_file)
43 : art_api::dex::DexFile(art_dex_file) {}
Christopher Ferris0b06a592018-01-19 10:26:36 -080044};
45
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080046class DexFileFromFile : public DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080047 public:
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000048 static std::unique_ptr<DexFileFromFile> Create(uint64_t dex_file_offset_in_file,
49 const std::string& file);
Christopher Ferris0b06a592018-01-19 10:26:36 -080050
51 private:
Yong Li489c3a82020-03-19 18:43:06 +000052 DexFileFromFile(std::unique_ptr<art_api::dex::DexFile>& art_dex_file) : DexFile(art_dex_file) {}
Christopher Ferris0b06a592018-01-19 10:26:36 -080053};
54
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080055class DexFileFromMemory : public DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080056 public:
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000057 static std::unique_ptr<DexFileFromMemory> Create(uint64_t dex_file_offset_in_memory,
Sim Sun273d3f02020-04-07 02:21:32 -070058 Memory* memory, const std::string& name,
59 size_t max_size);
Christopher Ferris0b06a592018-01-19 10:26:36 -080060
61 private:
Yong Li489c3a82020-03-19 18:43:06 +000062 DexFileFromMemory(std::unique_ptr<art_api::dex::DexFile>& art_dex_file,
63 std::vector<uint8_t>&& memory)
64 : DexFile(art_dex_file), memory_(std::move(memory)) {}
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000065
Christopher Ferris0b06a592018-01-19 10:26:36 -080066 std::vector<uint8_t> memory_;
67};
68
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080069} // namespace unwindstack
70
71#endif // _LIBUNWINDSTACK_DEX_FILE_H