UnwindMap.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (C) 2014 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 _LIBBACKTRACE_UNWIND_MAP_H
  17. #define _LIBBACKTRACE_UNWIND_MAP_H
  18. #include <pthread.h>
  19. #include <stdint.h>
  20. #include <sys/types.h>
  21. #include <backtrace/BacktraceMap.h>
  22. // The unw_map_cursor_t structure is different depending on whether it is
  23. // the local or remote version. In order to get the correct version, include
  24. // libunwind.h first then this header.
  25. class UnwindMap : public BacktraceMap {
  26. public:
  27. explicit UnwindMap(pid_t pid);
  28. unw_map_cursor_t* GetMapCursor() { return &map_cursor_; }
  29. protected:
  30. unw_map_cursor_t map_cursor_;
  31. };
  32. class UnwindMapRemote : public UnwindMap {
  33. public:
  34. explicit UnwindMapRemote(pid_t pid);
  35. virtual ~UnwindMapRemote();
  36. bool Build() override;
  37. private:
  38. bool GenerateMap();
  39. };
  40. class UnwindMapLocal : public UnwindMap {
  41. public:
  42. UnwindMapLocal();
  43. virtual ~UnwindMapLocal();
  44. bool Build() override;
  45. void FillIn(uint64_t addr, backtrace_map_t* map) override;
  46. void LockIterator() override { pthread_rwlock_rdlock(&map_lock_); }
  47. void UnlockIterator() override { pthread_rwlock_unlock(&map_lock_); }
  48. private:
  49. bool GenerateMap();
  50. bool map_created_;
  51. pthread_rwlock_t map_lock_;
  52. };
  53. #endif // _LIBBACKTRACE_UNWIND_MAP_H