]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-127503: Improve tracebacks on Emscripten when there is a trap (#131158)
authorHood Chatham <roberthoodchatham@gmail.com>
Thu, 13 Mar 2025 00:28:15 +0000 (01:28 +0100)
committerGitHub <noreply@github.com>
Thu, 13 Mar 2025 00:28:15 +0000 (08:28 +0800)
Modifies the behavior of the interpreter on crash under Emscripten:
1. No Python traceback shown on segfault/trap
2. The JavaScript source line is shown

The JavaScript source line is super long and completely unenlightening,
whereas the Python traceback is very helpful.

Lib/test/test_isinstance.py
Tools/wasm/emscripten/node_entry.mjs
configure
configure.ac

index 4f98cbb3762a98154b42cc93a6e0d88dd856b5fe..daad00e86432d059b06dc9251e393eb6edd803bf 100644 (file)
@@ -327,6 +327,7 @@ class TestIsInstanceIsSubclass(unittest.TestCase):
             with self.assertRaises(RecursionError):
                 issubclass(Failure(), int)
 
+    @support.skip_emscripten_stack_overflow()
     def test_infinite_cycle_in_bases(self):
         """Regression test for bpo-30570."""
         class X:
index 98b8f572a7e7624fb2f8d6ceb2c3cd4aee503aa1..166df40742b7fc4946b401076352d9b508655126 100644 (file)
@@ -32,6 +32,8 @@ const thisProgramIndex = process.argv.findIndex((x) =>
 
 const settings = {
   preRun(Module) {
+    // Globally expose API object so we can access it if we raise on startup.
+    globalThis.Module = Module;
     mountDirectories(Module);
     Module.FS.chdir(process.cwd());
     Object.assign(Module.ENV, process.env);
@@ -45,4 +47,12 @@ const settings = {
   arguments: process.argv.slice(thisProgramIndex + 1),
 };
 
-await EmscriptenModule(settings);
+try {
+  await EmscriptenModule(settings);
+} catch(e) {
+  // Show JavaScript exception and traceback
+  console.warn(e);
+  // Show Python exception and traceback
+  Module.__Py_DumpTraceback(2, Module._PyGILState_GetThisThreadState());
+  process.exit(1);
+}
index 677d0e8840676fb3bdbe5a8d392fea80fd0b2ae0..d0ae103014a3010158efbd8088bdebff9052d6c3 100755 (executable)
--- a/configure
+++ b/configure
@@ -9631,7 +9631,7 @@ fi
 
         as_fn_append LINKFORSHARED " -sFORCE_FILESYSTEM -lidbfs.js -lnodefs.js -lproxyfs.js -lworkerfs.js"
     as_fn_append LINKFORSHARED " -sEXPORTED_RUNTIME_METHODS=FS,callMain,ENV"
-    as_fn_append LINKFORSHARED " -sEXPORTED_FUNCTIONS=_main,_Py_Version,__PyRuntime,__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET"
+    as_fn_append LINKFORSHARED " -sEXPORTED_FUNCTIONS=_main,_Py_Version,__PyRuntime,__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET,_PyGILState_GetThisThreadState,__Py_DumpTraceback"
     as_fn_append LINKFORSHARED " -sSTACK_SIZE=5MB"
 
     if test "x$enable_wasm_dynamic_linking" = xyes
index 7ff0251b71838698a8e89dc9e8b343bde68d3619..8bb0f1c6ef4a49a8a86fca0d272898aa4e20328e 100644 (file)
@@ -2370,7 +2370,7 @@ AS_CASE([$ac_sys_system],
     dnl Include file system support
     AS_VAR_APPEND([LINKFORSHARED], [" -sFORCE_FILESYSTEM -lidbfs.js -lnodefs.js -lproxyfs.js -lworkerfs.js"])
     AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_RUNTIME_METHODS=FS,callMain,ENV"])
-    AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_FUNCTIONS=_main,_Py_Version,__PyRuntime,__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET"])
+    AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_FUNCTIONS=_main,_Py_Version,__PyRuntime,__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET,_PyGILState_GetThisThreadState,__Py_DumpTraceback"])
     AS_VAR_APPEND([LINKFORSHARED], [" -sSTACK_SIZE=5MB"])
 
     AS_VAR_IF([enable_wasm_dynamic_linking], [yes], [