Repository navigation
Report a Haxe exception that escapes every catch before the process ends - #489
Open
dimensionscape wants to merge 1 commit into
Open
dimensionscape wants to merge 1 commit into
dimensionscape wants to merge 1 commit into
Conversation
A Haxe exception that no C++ catch takes, as one thrown in a callback the OS or a library calls, through a noexcept function or a destructor, from the HXCPP_CATCH_SEGV handler, or out of a thread Haxe did not start, ends the process through std::terminate. GCC's runtime then printed only "terminate called after throwing an instance of 'Dynamic'", LLVM's said the same in its own words, and MSVC's printed nothing, so the Haxe error was lost without a debugger. hx::Boot now installs a terminate handler that reports a Haxe exception as main's catch does: the frames it left and those it never left, then "Error : " and the message, a line saying it escaped through native code, a message box in a program linked for the Windows subsystem, and the Android log. It then calls the handler that was there before, and aborts. It reads the exception on a thread the collector knows and outside a GC-free zone, attaching the thread or leaving the zone first, and not on the thread running a collection, which cannot allocate. A second thread that terminates meanwhile waits in a GC-free zone for the first to end the process, and a terminate from inside the report aborts. MSVC's runtime keeps a terminate handler for each thread, so there each thread installs it as it attaches to the collector.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A Haxe exception that no C++ catch takes ends the process through
std::terminate: one thrown in a callback the OS or a library calls, through anoexceptfunction or a destructor, from theHXCPP_CATCH_SEGVsignal handler, or out of the function of a thread Haxe did not start.main's catch never sees it, and the C++ runtime says at most what type was thrown. GCC's printsterminate called after throwing an instance of 'Dynamic', LLVM'slibc++abi: terminating due to uncaught exception of type Dynamic, and MSVC's nothing at all. A game built with MinGW crashed this way after an update, and the Haxe error could not be recovered without a debugger.hx::Bootnow installs a terminate handler (HaxeTerminatein src/hx/Debug.cpp). Whenstd::current_exception()holds aDynamic, it reports it asmain's catch does, then calls the handler that was installed before it, and aborts. Anything else goes straight to the previous handler.noexceptframe).HX_WIN_MAIN's catch shows.HX_WIN_MAINis defined only for the main file, so the runtime reads the subsystem from the exe's header. Android also gets the log, under theExceptiontag.abortstill end the process.The collector's state:
SetTopOfStack(&top, true), which attaches a thread the collector did not know and leaves a GC-free zone, then copies the exception onto its stack before allocating. On a thread it had to attach, the stack of frames is not the exception's and is not printed.hx::IsCollectingThread).toString, the_hx_customStackread and the stack dump are each guarded withcatch (...).MSVC's runtime keeps a terminate handler for each thread (checked here: one set on the main thread does not run for an exception escaping a
std::threador aCreateThreadthread), so with MSVC each thread also installs it as it attaches to the collector, inStackContext::onThreadAttach. A thread that never attached is not covered there. libstdc++ and libc++ keep one handler for the process.Not covered by this: with MSVC and
HXCPP_CATCH_SEGV(/EHa), a fault translated to a Haxe exception inside anoexceptfunction is not terminated at all; it reachesmain's catch, as before.Tests:
test/regression/EscapedHaxeExceptionruns five cases in child processes and checks each exits with a failure and printsError : <message>, the escape line, and the frame that threw where it has one: through anoexceptfunction, a thrown null, out of astd::threadthat attached itself, out of one that attached and detached again (the exception kept by a static, itstoStringallocating), and from native code inside a GC-free zone. Skipped on Emscripten, which has no threads.HXCPP_SINGLE_THREADED_APPandHXCPP_CATCH_SEGV.