BacktraceCurrent.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (C) 2013 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_BACKTRACE_CURRENT_H
  17. #define _LIBBACKTRACE_BACKTRACE_CURRENT_H
  18. #include <stdint.h>
  19. #include <sys/types.h>
  20. #include <backtrace/Backtrace.h>
  21. // The signal used to cause a thread to dump the stack.
  22. #if defined(__GLIBC__)
  23. // In order to run the backtrace_tests on the host, we can't use
  24. // the internal real time signals used by GLIBC. To avoid this,
  25. // use SIGRTMIN for the signal to dump the stack.
  26. #define THREAD_SIGNAL SIGRTMIN
  27. #else
  28. #define THREAD_SIGNAL (__SIGRTMIN+1)
  29. #endif
  30. class BacktraceMap;
  31. class BacktraceCurrent : public Backtrace {
  32. public:
  33. BacktraceCurrent(pid_t pid, pid_t tid, BacktraceMap* map) : Backtrace(pid, tid, map) {}
  34. virtual ~BacktraceCurrent() {}
  35. size_t Read(uint64_t addr, uint8_t* buffer, size_t bytes) override;
  36. bool ReadWord(uint64_t ptr, word_t* out_value) override;
  37. bool Unwind(size_t num_ignore_frames, void* ucontext) override;
  38. protected:
  39. bool DiscardFrame(const backtrace_frame_data_t& frame);
  40. private:
  41. bool UnwindThread(size_t num_ignore_frames);
  42. virtual bool UnwindFromContext(size_t num_ignore_frames, void* ucontext) = 0;
  43. };
  44. #endif // _LIBBACKTRACE_BACKTRACE_CURRENT_H