UnwindStack.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (C) 2017 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_STACK_H
  17. #define _LIBBACKTRACE_UNWIND_STACK_H
  18. #include <stdint.h>
  19. #include <string>
  20. #include <backtrace/BacktraceMap.h>
  21. #include <unwindstack/Memory.h>
  22. #include "BacktraceCurrent.h"
  23. #include "BacktracePtrace.h"
  24. class UnwindStackCurrent : public BacktraceCurrent {
  25. public:
  26. UnwindStackCurrent(pid_t pid, pid_t tid, BacktraceMap* map);
  27. virtual ~UnwindStackCurrent() = default;
  28. std::string GetFunctionNameRaw(uint64_t pc, uint64_t* offset) override;
  29. bool UnwindFromContext(size_t num_ignore_frames, void* ucontext) override;
  30. };
  31. class UnwindStackPtrace : public BacktracePtrace {
  32. public:
  33. UnwindStackPtrace(pid_t pid, pid_t tid, BacktraceMap* map);
  34. virtual ~UnwindStackPtrace() = default;
  35. bool Unwind(size_t num_ignore_frames, void* context) override;
  36. std::string GetFunctionNameRaw(uint64_t pc, uint64_t* offset) override;
  37. size_t Read(uint64_t addr, uint8_t* buffer, size_t bytes) override;
  38. private:
  39. unwindstack::MemoryRemote memory_;
  40. };
  41. class UnwindStackOffline : public Backtrace {
  42. public:
  43. UnwindStackOffline(ArchEnum arch, pid_t pid, pid_t tid, BacktraceMap* map, bool map_shared);
  44. bool Unwind(size_t num_ignore_frames, void* context) override;
  45. std::string GetFunctionNameRaw(uint64_t pc, uint64_t* offset) override;
  46. size_t Read(uint64_t addr, uint8_t* buffer, size_t bytes) override;
  47. bool ReadWord(uint64_t ptr, word_t* out_value) override;
  48. private:
  49. ArchEnum arch_;
  50. };
  51. #endif // _LIBBACKTRACE_UNWIND_STACK_H