1 /*
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 
17 #pragma once
18 
19 #include <stdint.h>
20 
21 #include <memory>
22 #include <mutex>
23 #include <string>
24 #include <unordered_map>
25 #include <vector>
26 
27 #include <unwindstack/Elf.h>
28 #include <unwindstack/Memory.h>
29 
30 namespace unwindstack {
31 
32 // Forward declarations.
33 class Maps;
34 class MapInfo;
35 
36 class Global {
37  public:
38   explicit Global(std::shared_ptr<Memory>& memory);
39   Global(std::shared_ptr<Memory>& memory, std::vector<std::string>& search_libs);
40   virtual ~Global() = default;
41 
42   void SetArch(ArchEnum arch);
43 
arch()44   ArchEnum arch() { return arch_; }
45 
46  protected:
47   bool Searchable(const std::string& name);
48   void FindAndReadVariable(Maps* maps, const char* variable);
49 
50   virtual bool ReadVariableData(uint64_t offset) = 0;
51 
52   virtual void ProcessArch() = 0;
53 
54   ArchEnum arch_ = ARCH_UNKNOWN;
55 
56   std::shared_ptr<Memory> memory_;
57   std::vector<std::string> search_libs_;
58 };
59 
60 }  // namespace unwindstack
61