absl_unwinder.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "absl_unwinder.h"
  2. #include <library/cpp/yt/backtrace/cursors/libunwind/libunwind_cursor.h>
  3. #include <absl/debugging/stacktrace.h>
  4. namespace NYT::NBacktrace {
  5. ////////////////////////////////////////////////////////////////////////////////
  6. namespace {
  7. int AbslStackUnwinder(
  8. void** frames,
  9. int* /*framesSizes*/,
  10. int maxFrames,
  11. int skipFrames,
  12. const void* /*uc*/,
  13. int* /*minDroppedFrames*/)
  14. {
  15. NBacktrace::TLibunwindCursor cursor;
  16. for (int i = 0; i < skipFrames + 1; ++i) {
  17. cursor.MoveNext();
  18. }
  19. int count = 0;
  20. for (int i = 0; i < maxFrames; ++i) {
  21. if (cursor.IsFinished()) {
  22. return count;
  23. }
  24. // IP point's to return address. Subtract 1 to get accurate line information for profiler.
  25. frames[i] = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(cursor.GetCurrentIP()) - 1);
  26. count++;
  27. cursor.MoveNext();
  28. }
  29. return count;
  30. }
  31. } // namespace
  32. void SetAbslStackUnwinder()
  33. {
  34. absl::SetStackUnwinder(AbslStackUnwinder);
  35. }
  36. ////////////////////////////////////////////////////////////////////////////////
  37. } // namespace NYT::NBacktrace