blob: 5797deec632a673a84c4b65e2a9eae3da4709d26 [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 Stjernholmbb4f2b42018-12-19 14:28:33 +000028#include <art_api/ext_dex_file.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
Christopher Ferris7747b602018-01-31 19:05:19 -080036 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:
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000042 DexFile(art_api::dex::DexFile&& art_dex_file) : art_api::dex::DexFile(std::move(art_dex_file)) {}
Christopher Ferris0b06a592018-01-19 10:26:36 -080043};
44
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080045class DexFileFromFile : public DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080046 public:
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000047 static std::unique_ptr<DexFileFromFile> Create(uint64_t dex_file_offset_in_file,
48 const std::string& file);
Christopher Ferris0b06a592018-01-19 10:26:36 -080049
50 private:
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000051 DexFileFromFile(art_api::dex::DexFile&& art_dex_file) : DexFile(std::move(art_dex_file)) {}
Christopher Ferris0b06a592018-01-19 10:26:36 -080052};
53
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080054class DexFileFromMemory : public DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080055 public:
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000056 static std::unique_ptr<DexFileFromMemory> Create(uint64_t dex_file_offset_in_memory,
57 Memory* memory, const std::string& name);
Christopher Ferris0b06a592018-01-19 10:26:36 -080058
59 private:
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000060 DexFileFromMemory(art_api::dex::DexFile&& art_dex_file, std::vector<uint8_t>&& memory)
61 : DexFile(std::move(art_dex_file)), memory_(std::move(memory)) {}
62
Christopher Ferris0b06a592018-01-19 10:26:36 -080063 std::vector<uint8_t> memory_;
64};
65
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080066} // namespace unwindstack
67
68#endif // _LIBUNWINDSTACK_DEX_FILE_H