Skip to content

Improve module backtraces for C# and C++ bindings#4785

Closed
clockwork-labs-bot wants to merge 1 commit intomasterfrom
bot/csharp-cpp-module-backtraces
Closed

Improve module backtraces for C# and C++ bindings#4785
clockwork-labs-bot wants to merge 1 commit intomasterfrom
bot/csharp-cpp-module-backtraces

Conversation

@clockwork-labs-bot
Copy link
Copy Markdown
Collaborator

Summary

  • preserve C# reducer/procedure/view dispatcher frames in module backtraces with MethodImplOptions.NoInlining
  • preserve C++ reducer/procedure/view user function frames in module backtraces with __attribute__((noinline))
  • log reducer exceptions in the C# runtime like procedures and views already do

Testing

  • dotnet test BSATN.Runtime.Tests.csproj
  • clang++ -fsyntax-only (bindings macro syntax check)

Follows the intent of #577 for the C# and C++ module bindings.

Mirror the backtrace improvements from PR #577 (Rust/TS) to the C# and
C++ module bindings so that stack traces captured by the host show
actual reducer/procedure/view function names instead of anonymous
wrappers.

C# changes:
- Add [MethodImpl(NoInlining)] to all generated Invoke() methods in
  reducer, procedure, and view dispatcher classes. This prevents the
  JIT/AOT from inlining these frames away, ensuring they appear as
  named WASM functions in wasmtime-captured backtraces.
- Add Log.Error() in the reducer error handler for consistency with
  procedures and views, which already log full exceptions.

C++ changes:
- Add __attribute__((noinline)) to user function definitions in all
  macro variants: SPACETIMEDB_REDUCER, SPACETIMEDB_REDUCER_NAMED,
  SPACETIMEDB_INIT, SPACETIMEDB_CLIENT_CONNECTED,
  SPACETIMEDB_CLIENT_DISCONNECTED, SPACETIMEDB_VIEW,
  SPACETIMEDB_VIEW_NAMED, SPACETIMEDB_PROCEDURE, and
  SPACETIMEDB_PROCEDURE_NAMED. This ensures the actual user function
  name appears as a distinct frame in WASM backtraces rather than
  being optimized into the surrounding lambda wrappers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clockwork-labs-bot
Copy link
Copy Markdown
Collaborator Author

Superseded by #4786, which is correctly stacked on top of #577.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant