StackTrace.cpp 961 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "il2cpp-config.h"
  2. #include "StackTrace.h"
  3. namespace il2cpp
  4. {
  5. namespace os
  6. {
  7. static Il2CppBacktraceFunc s_StackBacktraceFunc = 0;
  8. void StackTrace::WalkStack(WalkStackCallback callback, void* context, WalkOrder walkOrder)
  9. {
  10. if (s_StackBacktraceFunc == 0)
  11. {
  12. StackTrace::WalkStackNative(callback, context, walkOrder);
  13. return;
  14. }
  15. const int kMaxStackFrames = 128;
  16. Il2CppMethodPointer addrs[kMaxStackFrames];
  17. size_t size = s_StackBacktraceFunc(addrs, kMaxStackFrames);
  18. for (size_t i = 0; i < size; ++i)
  19. {
  20. const size_t index = (walkOrder == os::StackTrace::kFirstCalledToLastCalled) ? (size - i - 1) : i;
  21. if (!callback(addrs[index], context))
  22. break;
  23. }
  24. }
  25. void StackTrace::OverrideStackBacktrace(Il2CppBacktraceFunc stackBacktraceFunc)
  26. {
  27. s_StackBacktraceFunc = stackBacktraceFunc;
  28. }
  29. }
  30. }