blob: 239b64a23fba8971f53cdf28b81b6231ea3c5f81 [file] [log] [blame]
Christopher Ferris09385e72017-04-05 13:25:04 -07001/*
2 * Copyright (C) 2016 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
17#ifndef _LIBUNWINDSTACK_MAPS_H
18#define _LIBUNWINDSTACK_MAPS_H
19
20#include <sys/types.h>
21#include <unistd.h>
22
23#include <string>
24#include <vector>
25
26#include "Elf.h"
27#include "MapInfo.h"
28
29// Special flag to indicate a map is in /dev/. However, a map in
30// /dev/ashmem/... does not set this flag.
31static constexpr int MAPS_FLAGS_DEVICE_MAP = 0x8000;
32
33class Maps {
34 public:
35 Maps() = default;
36 virtual ~Maps();
37
38 MapInfo* Find(uint64_t pc);
39
40 bool ParseLine(const char* line, MapInfo* map_info);
41
42 virtual bool Parse();
43
44 virtual const std::string GetMapsFile() const { return ""; }
45
46 typedef std::vector<MapInfo>::iterator iterator;
47 iterator begin() { return maps_.begin(); }
48 iterator end() { return maps_.end(); }
49
50 typedef std::vector<MapInfo>::const_iterator const_iterator;
51 const_iterator begin() const { return maps_.begin(); }
52 const_iterator end() const { return maps_.end(); }
53
54 size_t Total() { return maps_.size(); }
55
56 protected:
57 std::vector<MapInfo> maps_;
58};
59
60class RemoteMaps : public Maps {
61 public:
62 RemoteMaps(pid_t pid) : pid_(pid) {}
63 virtual ~RemoteMaps() = default;
64
65 virtual const std::string GetMapsFile() const override;
66
67 private:
68 pid_t pid_;
69};
70
71class LocalMaps : public RemoteMaps {
72 public:
73 LocalMaps() : RemoteMaps(getpid()) {}
74 virtual ~LocalMaps() = default;
75};
76
77class BufferMaps : public Maps {
78 public:
79 BufferMaps(const char* buffer) : buffer_(buffer) {}
80 virtual ~BufferMaps() = default;
81
82 bool Parse() override;
83
84 private:
85 const char* buffer_;
86};
87
88class FileMaps : public Maps {
89 public:
90 FileMaps(const std::string& file) : file_(file) {}
91 virtual ~FileMaps() = default;
92
93 const std::string GetMapsFile() const override { return file_; }
94
95 protected:
96 const std::string file_;
97};
98
99class OfflineMaps : public FileMaps {
100 public:
101 OfflineMaps(const std::string& file) : FileMaps(file) {}
102 virtual ~OfflineMaps() = default;
103
104 bool Parse() override;
105};
106
107#endif // _LIBUNWINDSTACK_MAPS_H