blob: 1448a4b565a5e5155446bf3c007a8943d289f1ea [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
David Srbecky85b5fec2018-02-23 18:06:13 +000032class Memory;
33struct MapInfo;
34
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000035class DexFile : protected art_api::dex::DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080036 public:
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080037 virtual ~DexFile() = default;
Christopher Ferris0b06a592018-01-19 10:26:36 -080038
David Srbecky85b5fec2018-02-23 18:06:13 +000039 bool GetFunctionName(uint64_t dex_pc, std::string* method_name, uint64_t* method_offset);
Christopher Ferris0b06a592018-01-19 10:26:36 -080040
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000041 static std::unique_ptr<DexFile> Create(uint64_t dex_file_offset_in_memory, Memory* memory,
42 MapInfo* info);
Christopher Ferris0b06a592018-01-19 10:26:36 -080043
44 protected:
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000045 DexFile(art_api::dex::DexFile&& art_dex_file) : art_api::dex::DexFile(std::move(art_dex_file)) {}
David Srbecky85b5fec2018-02-23 18:06:13 +000046
47 uint64_t addr_ = 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:
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000052 static std::unique_ptr<DexFileFromFile> Create(uint64_t dex_file_offset_in_file,
53 const std::string& file);
Christopher Ferris0b06a592018-01-19 10:26:36 -080054
55 private:
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000056 DexFileFromFile(art_api::dex::DexFile&& art_dex_file) : DexFile(std::move(art_dex_file)) {}
Christopher Ferris0b06a592018-01-19 10:26:36 -080057};
58
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080059class DexFileFromMemory : public DexFile {
Christopher Ferris0b06a592018-01-19 10:26:36 -080060 public:
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000061 static std::unique_ptr<DexFileFromMemory> Create(uint64_t dex_file_offset_in_memory,
62 Memory* memory, const std::string& name);
Christopher Ferris0b06a592018-01-19 10:26:36 -080063
64 private:
Martin Stjernholmbb4f2b42018-12-19 14:28:33 +000065 DexFileFromMemory(art_api::dex::DexFile&& art_dex_file, std::vector<uint8_t>&& memory)
66 : DexFile(std::move(art_dex_file)), memory_(std::move(memory)) {}
67
Christopher Ferris0b06a592018-01-19 10:26:36 -080068 std::vector<uint8_t> memory_;
69};
70
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080071} // namespace unwindstack
72
73#endif // _LIBUNWINDSTACK_DEX_FILE_H