Skip to content

Base implementation of catching exceptions made in C stubs#433

Open
SturdyPose wants to merge 15 commits intomirage:mainfrom
SturdyPose:sturdypose/add-stack-tracing-for-nullptrs
Open

Base implementation of catching exceptions made in C stubs#433
SturdyPose wants to merge 15 commits intomirage:mainfrom
SturdyPose:sturdypose/add-stack-tracing-for-nullptrs

Conversation

@SturdyPose
Copy link
Copy Markdown

@SturdyPose SturdyPose commented Feb 20, 2026

The goal of this PR is to fix #430

  • Add base implementation for catching segmentation faults with try catch block
  • Implementation for windows stacktraces
  • Implementation for linux stacktraces
  • Credit author for collecting windows stack trace in the comments - https://smhk.net/note/2025/03/c-stack-trace-in-windows/
  • Update stubs.expected file
  • Export different exception structs like SegFault
  • Make working JS backend build

Open to any feedback. :)

Copy link
Copy Markdown
Collaborator

@MisterDA MisterDA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bit of mixed indentation in the C file, please reformat the Windows code to be consistent with the rest.

@SturdyPose
Copy link
Copy Markdown
Author

Applied clang-format on source

@SturdyPose
Copy link
Copy Markdown
Author

Seems like windows containers are broken because they don't have npm and I'm unsure why mac is not catching the exception... 🤔

@SturdyPose
Copy link
Copy Markdown
Author

Yeah, I'll need to rethink the implementation of reporting it back to ocaml -> might not be possible at all. There can be stack corruption and that would lead to undeterministic results. Do you think that reporting it to stderr would be good enough?

@MisterDA
Copy link
Copy Markdown
Collaborator

For the unix part maybe you need a signal handler on the ocaml side instead?

@SturdyPose
Copy link
Copy Markdown
Author

Well from what I gathered online is that signals can be interpreted differently for each unix like system. For example apple platform is handling signals differently than linux systems, and even linux distros themselves can handle those differently, so I reckon that it won't make much difference adding signal handler on ocaml side. There's also problem when you throw a signal like SEGFAULT, you can't reliably catch it and especially returning back to ocaml's managed memory. I think that only course of action is to just print into stderror.

Such a headache. :D

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.

Alcotest silently fails when aborted from C stub

2 participants