diff --git a/common/trace_helpers.cpp b/common/trace_helpers.cpp index a5d9e3f8b9..f39d23effd 100644 --- a/common/trace_helpers.cpp +++ b/common/trace_helpers.cpp @@ -34,6 +34,7 @@ const wxChar* const traceFindReplace = wxT( "KICAD_FIND_REPLACE" ); const wxChar* const kicadTraceCoords = wxT( "KICAD_COORDS" ); const wxChar* const kicadTraceKeyEvent = wxT( "KICAD_KEY_EVENTS" ); const wxChar* const kicadTraceToolStack = wxT( "KICAD_TOOL_STACK" ); +const wxChar* const kicadTraceCoroutineStack = wxT( "KICAD_COROUTINE_STACK" ); const wxChar* const traceSchLibMem = wxT( "KICAD_SCH_LIB_MEM" ); const wxChar* const traceFindItem = wxT( "KICAD_FIND_ITEM" ); const wxChar* const traceSchLegacyPlugin = wxT( "KICAD_SCH_LEGACY_PLUGIN" ); diff --git a/include/tool/coroutine.h b/include/tool/coroutine.h index e0d716b7b7..f000482bf0 100644 --- a/include/tool/coroutine.h +++ b/include/tool/coroutine.h @@ -46,6 +46,9 @@ #include #include +#include +#include + /** * Implement a coroutine. * @@ -267,6 +270,9 @@ public: m_caller.tsan_fiber = __tsan_get_current_fiber(); m_caller.own_tsan_fiber = false; #endif + + wxLogTrace( kicadTraceCoroutineStack, "COROUTINE::Call (from root)" ); + ctx.Continue( doCall( &args, aArg ) ); return Running(); @@ -283,6 +289,9 @@ public: bool Call( const COROUTINE& aCor, ArgType aArg ) { INVOCATION_ARGS args{ INVOCATION_ARGS::FROM_ROUTINE, this, aCor.m_callContext }; + + wxLogTrace( kicadTraceCoroutineStack, "COROUTINE::Call (from routine)" ); + doCall( &args, aArg ); // we will not be asked to continue @@ -307,6 +316,9 @@ public: m_caller.tsan_fiber = __tsan_get_current_fiber(); m_caller.own_tsan_fiber = false; #endif + + wxLogTrace( kicadTraceCoroutineStack, "COROUTINE::Resume (from root)" ); + ctx.Continue( doResume( &args ) ); return Running(); @@ -323,6 +335,9 @@ public: bool Resume( const COROUTINE& aCor ) { INVOCATION_ARGS args{ INVOCATION_ARGS::FROM_ROUTINE, this, aCor.m_callContext }; + + wxLogTrace( kicadTraceCoroutineStack, "COROUTINE::Resume (from routine)" ); + doResume( &args ); // we will not be asked to continue @@ -379,6 +394,9 @@ private: m_callee.tsan_fiber = __tsan_create_fiber( 0 ); m_callee.own_tsan_fiber = true; #endif + + wxLogTrace( kicadTraceCoroutineStack, "COROUTINE::doCall" ); + m_callee.ctx = libcontext::make_fcontext( sp, stackSize, callerStub ); m_running = true; @@ -417,6 +435,9 @@ private: // Tell TSAN we are changing fibers to the callee __tsan_switch_to_fiber( m_callee.tsan_fiber, 0 ); #endif + + wxLogTrace( kicadTraceCoroutineStack, "COROUTINE::jumpIn" ); + args = reinterpret_cast( libcontext::jump_fcontext( &( m_caller.ctx ), m_callee.ctx, reinterpret_cast( args ) ) @@ -434,6 +455,9 @@ private: // Tell TSAN we are changing fibers back to the caller __tsan_switch_to_fiber( m_caller.tsan_fiber, 0 ); #endif + + wxLogTrace( kicadTraceCoroutineStack, "COROUTINE::jumpOut" ); + ret = reinterpret_cast( libcontext::jump_fcontext( &( m_callee.ctx ), m_caller.ctx, reinterpret_cast( &args ) ) diff --git a/include/trace_helpers.h b/include/trace_helpers.h index 92b43e0edc..d05147a171 100644 --- a/include/trace_helpers.h +++ b/include/trace_helpers.h @@ -82,6 +82,13 @@ extern const wxChar* const kicadTraceKeyEvent; */ extern const wxChar* const kicadTraceToolStack; +/** + * Flag to enable tracing of the coroutine call stack. + * + * Use "KICAD_COROUTINE_STACK" to enable. + */ +extern const wxChar* const kicadTraceCoroutineStack; + /** * Flag to enable auto save feature debug tracing. *