1e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris/*
2e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris * Copyright (C) 2016 The Android Open Source Project
3e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris *
4e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris * Licensed under the Apache License, Version 2.0 (the "License");
5e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris * you may not use this file except in compliance with the License.
6e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris * You may obtain a copy of the License at
7e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris *
8e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris *      http://www.apache.org/licenses/LICENSE-2.0
9e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris *
10e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris * Unless required by applicable law or agreed to in writing, software
11e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris * distributed under the License is distributed on an "AS IS" BASIS,
12e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris * See the License for the specific language governing permissions and
14e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris * limitations under the License.
15e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris */
16e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris
17e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris#ifndef _LIBUNWINDSTACK_SYMBOLS_H
18e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris#define _LIBUNWINDSTACK_SYMBOLS_H
19e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris
20e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris#include <stdint.h>
21e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris
22e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris#include <string>
23e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris#include <vector>
24e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris
25d226a5140989f509a0ed3e2723f05d5fc93ce8dfChristopher Ferrisnamespace unwindstack {
26d226a5140989f509a0ed3e2723f05d5fc93ce8dfChristopher Ferris
27e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris// Forward declaration.
28e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferrisclass Memory;
29e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris
30e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferrisclass Symbols {
31e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  struct Info {
32e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris    Info(uint64_t start_offset, uint64_t end_offset, uint64_t str_offset)
33e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris        : start_offset(start_offset), end_offset(end_offset), str_offset(str_offset) {}
34e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris    uint64_t start_offset;
35e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris    uint64_t end_offset;
36e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris    uint64_t str_offset;
37e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  };
38e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris
39e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris public:
40e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  Symbols(uint64_t offset, uint64_t size, uint64_t entry_size, uint64_t str_offset,
41e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris          uint64_t str_size);
42e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  virtual ~Symbols() = default;
43e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris
44e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  const Info* GetInfoFromCache(uint64_t addr);
45e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris
46e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  template <typename SymType>
47e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  bool GetName(uint64_t addr, uint64_t load_bias, Memory* elf_memory, std::string* name,
48e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris               uint64_t* func_offset);
49e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris
50150db124f3f3c0f8e1c341fd33c6c64310e0ac39Christopher Ferris  template <typename SymType>
51150db124f3f3c0f8e1c341fd33c6c64310e0ac39Christopher Ferris  bool GetGlobal(Memory* elf_memory, const std::string& name, uint64_t* memory_address);
52150db124f3f3c0f8e1c341fd33c6c64310e0ac39Christopher Ferris
53e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  void ClearCache() {
54e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris    symbols_.clear();
55e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris    cur_offset_ = offset_;
56e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  }
57e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris
58e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris private:
59e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  uint64_t cur_offset_;
60e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  uint64_t offset_;
61e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  uint64_t end_;
62e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  uint64_t entry_size_;
63e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  uint64_t str_offset_;
64e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  uint64_t str_end_;
65e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris
66e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris  std::vector<Info> symbols_;
67e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris};
68e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris
69d226a5140989f509a0ed3e2723f05d5fc93ce8dfChristopher Ferris}  // namespace unwindstack
70d226a5140989f509a0ed3e2723f05d5fc93ce8dfChristopher Ferris
71e7ba4cc222597aef308cae6e94abfe00b7d2e5d8Christopher Ferris#endif  // _LIBUNWINDSTACK_SYMBOLS_H
72