Symbols.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  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. #ifndef _LIBUNWINDSTACK_SYMBOLS_H
  17. #define _LIBUNWINDSTACK_SYMBOLS_H
  18. #include <stdint.h>
  19. #include <string>
  20. #include <vector>
  21. namespace unwindstack {
  22. // Forward declaration.
  23. class Memory;
  24. class Symbols {
  25. struct Info {
  26. Info(uint64_t start_offset, uint64_t end_offset, uint64_t str_offset)
  27. : start_offset(start_offset), end_offset(end_offset), str_offset(str_offset) {}
  28. uint64_t start_offset;
  29. uint64_t end_offset;
  30. uint64_t str_offset;
  31. };
  32. public:
  33. Symbols(uint64_t offset, uint64_t size, uint64_t entry_size, uint64_t str_offset,
  34. uint64_t str_size);
  35. virtual ~Symbols() = default;
  36. const Info* GetInfoFromCache(uint64_t addr);
  37. template <typename SymType>
  38. bool GetName(uint64_t addr, Memory* elf_memory, std::string* name, uint64_t* func_offset);
  39. template <typename SymType>
  40. bool GetGlobal(Memory* elf_memory, const std::string& name, uint64_t* memory_address);
  41. void ClearCache() {
  42. symbols_.clear();
  43. cur_offset_ = offset_;
  44. }
  45. private:
  46. uint64_t cur_offset_;
  47. uint64_t offset_;
  48. uint64_t end_;
  49. uint64_t entry_size_;
  50. uint64_t str_offset_;
  51. uint64_t str_end_;
  52. std::vector<Info> symbols_;
  53. };
  54. } // namespace unwindstack
  55. #endif // _LIBUNWINDSTACK_SYMBOLS_H