Repository navigation
Uncaught exception: a stack trace under the error, always - #840
Merged
Merged
Conversation
Under "uncaught exception: ...", the frames the exception was thrown from, from an executable's runtime and from the JIT, on Windows and Linux (TypeScript/UncaughtStackTrace.h). Not only with --di: the frames are walked only on the way out of a failed program. --di adds what a frame can say: - Windows exe: without --di there is no PDB, so a frame is `program.exe+0x126c` and a line says to compile with --di; with --di dbghelp (loaded only then) gives function and line. - Linux exe: the symbol table names the functions; with --di addr2line, when installed, adds the line. - JIT: a JITEventListener names the JIT'd functions (no lines). On Windows a `finally` is a catch-all that throws again, so the exception that reaches the filter starts where the outermost `finally` is. A vectored handler copies the context of every throw that is not a rethrow, and the trace is walked from that first throw (the frames are still on the stack, under the catch blocks). Linux needs nothing: a `finally` is a cleanup the search passes, and std::terminate() runs where the throw found no catch. Left out of the trace: the throw itself (RaiseException, _CxxThrowException, __cxa_throw), the C runtime's startup after main (on Windows found by main's address, even with no names) and, in the JIT, tslang's own frames. Tests: throw_through_finally.ts under gc/rc/own - JIT names, and an executable with and without --di. ctest: Windows 7073/7073, Linux 7057/7057. An rc --opt executable grows by 5 KB (279040 -> 284160). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…)'s dialog A 32-bit program that threw what nothing caught ended in abort()'s message box, which an unattended run waits on forever: tslang/runtime/CMakeLists.txt, which builds the x86 runtime, never had UncaughtException.cpp, so exe.cpp did not take the handler. With the handler, x86 needed three more things: - describeUncaught: an x86 throw's record has 3 parameters and its ThrowInfo holds addresses (a base of 0), not 4 with image-relative references - the description was empty. - tslang keeps the frame pointer in every function for 32-bit Windows (obj.cpp): LLVM omitted it even at -O0, and the caller of such a function was missing from the trace. The trace walks the chain of frame pointers; StackWalk64 lost the same frames. - names from dbghelp only from a PDB that matches the image: a --di build's PDB beside a later build without --di, under the same name, named frames after unrelated functions. Tests: x86 twins of the trace tests (TSLANG_TEST_X86), gc/rc/own with and without --di. ctest with TSLANG_TEST_X86: the same 35 x86 failures with and without the frame pointers (@cpp classes on i686, x86 link symbols, 32-bit u64 bugs), none from this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
An uncaught exception now prints the frames it was thrown from under
uncaught exception: .... It works from executables and from the JIT, on Windows and Linux. The trace is always printed;--diadds source lines where they are available.--diprogram.exe+0x126cper frame, plus "(compile with --di for function names and source lines)"--di/usr/bin/addr2linewhen installedHow it works
TypeScript/UncaughtStackTrace.h, used byTypeScriptAsyncRuntime/UncaughtException.cppandtslang/jit.cpp.RtlVirtualUnwindwalks from the throw's context. It also covers JIT'd code, which registers its.pdata._Unwind_Backtraceruns from the terminate handler.finallyon Windows: MSVC lowersfinallyto catch-all plus rethrow, so the exception that reaches the filter starts at the outermostfinally. A vectored handler copies the context of each new throw (not of rethrows), and the trace walks from that first throw. Its frames are still on the stack, under the catch blocks. Linux needs none of this: there afinallyis a cleanup, which the search for a handler passes.RaiseException,_CxxThrowException,__cxa_throw;main. On Windows,mainis found by its address, so this works even when no frame has a name;JITEventListenerrecords each JIT'd function's name, address and size.x86 Windows (second commit)
abort()'s message box, becausetslang/runtime/CMakeLists.txt, which builds the x86 runtime, never hadUncaughtException.cpp. It now prints the error and a trace, like x64.describeUncaughtnow reads that form too.obj.cpp). LLVM omitted it even at-O0, which dropped callers from the trace. The x86 walk follows the EBP chain.--dibuild gave wrong names.TSLANG_TEST_X86. With x86 tests on, 35 other x86 tests fail, and exactly the same 35 fail with the frame-pointer change turned off.Known gaps
--jit-native: source lines come from its PDB, but afinallythere still starts the trace at the rethrow, because the DLL has its own C runtime.Tests
uncaught/throw_through_finally.ts, run under gc, rc and own:--di, checking the expected output for each platform;--di, checking file:line on Windows, and on Linux whenaddr2lineis installed.--optexecutable grows by 5 KB (279,040 → 284,160 bytes).🤖 Generated with Claude Code