callstack_emscripten.cpp 877 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2012-2026 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: MIT
  4. */
  5. #include "core/platform.h"
  6. #if CROWN_PLATFORM_EMSCRIPTEN
  7. #include "core/debug/callstack.h"
  8. #include "core/memory/allocator.h"
  9. #include "core/memory/globals.h"
  10. #include <emscripten/emscripten.h>
  11. namespace crown
  12. {
  13. namespace debug
  14. {
  15. s32 callstack_init()
  16. {
  17. return 0;
  18. }
  19. void callstack_shutdown()
  20. {
  21. CE_NOOP();
  22. }
  23. void callstack(log_internal::System system, LogSeverity::Enum severity)
  24. {
  25. int size = emscripten_get_callstack(EM_LOG_C_STACK | EM_LOG_JS_STACK, NULL, 0);
  26. char *data = (char *)default_allocator().allocate(size);
  27. emscripten_get_callstack(EM_LOG_C_STACK | EM_LOG_JS_STACK, data, size);
  28. log_internal::logx(severity, system, data);
  29. default_allocator().deallocate(data);
  30. }
  31. } // namespace debug
  32. } // namespace crown
  33. #endif // if CROWN_PLATFORM_EMSCRIPTEN