|
3 | 3 | // Distributed under the GPL v3 License, see LICENSE.notice.txt |
4 | 4 |
|
5 | 5 | #include <cstddef> |
6 | | -#include <cstdint> |
7 | 6 | #include <iterator> |
8 | 7 | #include <span> |
9 | 8 |
|
10 | 9 | #include "runtime-light/coroutine/async-stack.h" |
11 | 10 | #include "runtime-light/coroutine/coroutine-state.h" |
| 11 | +#include "runtime-light/k2-platform/k2-api.h" |
| 12 | +#include "runtime-light/state/instance-state.h" |
12 | 13 | #include "runtime-light/stdlib/diagnostics/backtrace.h" |
13 | 14 | #include "runtime-light/utils/logs.h" |
14 | 15 |
|
@@ -40,17 +41,19 @@ size_t async_frames(std::span<void*> addresses, kphp::coro::async_stack_frame* t |
40 | 41 |
|
41 | 42 | } // namespace |
42 | 43 |
|
43 | | -namespace kphp::diagnostic { |
| 44 | +namespace kphp::diagnostic::impl { |
44 | 45 |
|
45 | | -size_t backtrace(std::span<void*> addresses) noexcept { |
46 | | - auto& async_stack_root{CoroutineInstanceState::get().coroutine_stack_root}; |
| 46 | +size_t async_backtrace(std::span<void*> addresses) noexcept { |
| 47 | + if (const auto* instance_state{k2::instance_state()}; instance_state != nullptr) [[likely]] { |
| 48 | + const auto& async_stack_root{instance_state->coroutine_instance_state.coroutine_stack_root}; |
47 | 49 |
|
48 | | - auto* const start_sync_frame{reinterpret_cast<kphp::coro::stack_frame*>(STACK_FRAME_ADDRESS)}; |
49 | | - auto* const stop_sync_frame{async_stack_root.stop_sync_stack_frame}; |
| 50 | + auto* const start_sync_frame{reinterpret_cast<kphp::coro::stack_frame*>(STACK_FRAME_ADDRESS)}; |
| 51 | + auto* const stop_sync_frame{async_stack_root.stop_sync_stack_frame}; |
50 | 52 |
|
51 | | - const size_t num_sync_frames{sync_frames(addresses, start_sync_frame, stop_sync_frame)}; |
52 | | - const size_t num_async_frames{async_frames(addresses.subspan(num_sync_frames), async_stack_root.top_async_stack_frame)}; |
53 | | - return num_sync_frames + num_async_frames; |
| 53 | + const size_t num_sync_frames{sync_frames(addresses, start_sync_frame, stop_sync_frame)}; |
| 54 | + const size_t num_async_frames{async_frames(addresses.subspan(num_sync_frames), async_stack_root.top_async_stack_frame)}; |
| 55 | + return num_sync_frames + num_async_frames; |
| 56 | + } |
| 57 | + return 0; |
54 | 58 | } |
55 | | - |
56 | | -} // namespace kphp::diagnostic |
| 59 | +} // namespace kphp::diagnostic::impl |
0 commit comments