Skip to content

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

Open
clockwork-labs-bot wants to merge 4 commits intonoa/better-module-backtracesfrom
bot/csharp-cpp-module-backtraces-on-577
Open

Improve module backtraces for C# and C++ bindings#4786
clockwork-labs-bot wants to merge 4 commits intonoa/better-module-backtracesfrom
bot/csharp-cpp-module-backtraces-on-577

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)

Stacks on top of #577.

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

Pushed 680e8c8dd and 044097627 to this branch.

This is now stacked on the generic marker change from #577, and the C# / C++ follow-up uses __spacetimedb_begin_short_backtrace in generated dispatch wrappers and C++ handler wrappers so those languages participate in the same short-backtrace fencepost scheme. C# codegen snapshots were updated to match.

cc @coolreader18

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