From 1ac70d22af1922ff3e829089da4712b2b9c68114 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Nov 2026 06:53:22 +0000 Subject: [PATCH 1/2] [docs] Add notes on debugging intermittent native crashes in CI Write down what helped track down the macOS arm64 cppia JIT crash fixed in #13106, so future investigations don't have to rediscover it. Kept out of AGENTS.md since it is rarely needed; point an agent to it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Va4FXG8Zex7iQytzPnDKyg --- extra/debugging-native-crashes.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 extra/debugging-native-crashes.md diff --git a/extra/debugging-native-crashes.md b/extra/debugging-native-crashes.md new file mode 100644 index 00000000000..b677fe2e803 --- /dev/null +++ b/extra/debugging-native-crashes.md @@ -0,0 +1,14 @@ +# Debugging Intermittent Native Crashes (cpp/cppia) + +Notes for the rare case of a native crash in CI that only happens some of the time. This file is not loaded automatically; point an agent to it when needed. + +Lessons from tracking down a crash that hit about 1 in 3 `mac-test (cpp, arm64)` jobs (#13105, fixed in #13106): + +- **Read the crash signature first.** With `HXCPP_CATCH_SEGV` (used by the test hosts), a SIGSEGV becomes a Haxe exception `hxSehException`; other signals such as SIGBUS or SIGABRT are not converted. The Haxe stack shows which phase crashed: in `cpp/cppia/Host.hx`, `Module.fromData` (parse, link and, with `-jit`, JIT compilation of the whole module) is a different line from `module.boot()`/`module.run()`. If the interpreted run passes and the `-jit` run crashes during `fromData`, the problem is in the JIT compile pass, before any script code runs. +- **Check when it started.** CI installs hxcpp from git master, so relate the first failures to hxcpp commits as well as Haxe commits. Count failures over many runs before blaming a recent change. +- **Get a native backtrace from CI.** Temporarily reduce the workflow to the failing job: set `if: false` on `windows64-build` and `linux-build`, which skips their dependent jobs, and cut down the `mac-test` matrix. Both `mac-build` arches are still needed for the universal binary. Then loop the failing command under `lldb --batch -o run -k "thread backtrace all" -k "frame variable *this" -k "quit 1" -- `. + - **lldb disables ASLR by default.** A layout-dependent bug may never reproduce under it. Pass `-O "settings set target.disable-aslr false"`. + - **Use Guard Malloc for heap bugs.** `settings set target.env-vars DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib` turns random heap overflows and use-after-frees into a deterministic fault at the first bad access; it is what pinpointed #13106. `MallocScribble=1` fills freed memory with `0x55`, which makes stale reads recognizable. + - The `lldb.macosx.heap` `malloc_info --stack-history` command did not work on the macOS 26 runners. +- **cppia invariant:** hxcpp's `CppiaFunction::load` casts every class method body to `ScriptCallable *` (a `FUN` expression) without checking. The interpreter only uses it through virtual methods, but the JIT calls non-virtual members on it. The cppia generator must therefore emit a `FUN` for every method body, including abstract methods, or the JIT reads out of bounds. +- **Job logs are often too large to read in one go.** Fetch them with a bounded `tail_lines` (or save them to a file) and search for `stop reason`, `hxSehException` or `Command exited with`, rather than reading them in full. From 38aa276d867ecac51f7c1ebe1b46439d1f20be48 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Nov 2026 06:57:09 +0000 Subject: [PATCH 2/2] [docs] Move the advice on large CI logs to AGENTS.md Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Va4FXG8Zex7iQytzPnDKyg --- AGENTS.md | 1 + extra/debugging-native-crashes.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 920b680d6a6..6bb1b00c0ee 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -220,6 +220,7 @@ The steps below use the `gh` CLI. The checkout may have many remotes (contributo - Avoid `gh run view --log-failed` for whole runs: it downloads the logs of all jobs and is very slow - Logs end with post-step cleanup output; look at roughly the last 100-200 lines of the failing step rather than the very end - Look for keywords like `FAILED`, `error`, `exit code`, `assert`, `exception` to locate the relevant failure + - Logs can be too large to read in one go: fetch them with a bounded tail (e.g. `tail_lines` for `get_job_logs`) or save them to a file, then search them instead of reading them in full 5. The job name contains the target and platform, e.g. `linux-test (macro, x86)` means the macro target on Linux x86 diff --git a/extra/debugging-native-crashes.md b/extra/debugging-native-crashes.md index b677fe2e803..782bf23ee5d 100644 --- a/extra/debugging-native-crashes.md +++ b/extra/debugging-native-crashes.md @@ -11,4 +11,4 @@ Lessons from tracking down a crash that hit about 1 in 3 `mac-test (cpp, arm64)` - **Use Guard Malloc for heap bugs.** `settings set target.env-vars DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib` turns random heap overflows and use-after-frees into a deterministic fault at the first bad access; it is what pinpointed #13106. `MallocScribble=1` fills freed memory with `0x55`, which makes stale reads recognizable. - The `lldb.macosx.heap` `malloc_info --stack-history` command did not work on the macOS 26 runners. - **cppia invariant:** hxcpp's `CppiaFunction::load` casts every class method body to `ScriptCallable *` (a `FUN` expression) without checking. The interpreter only uses it through virtual methods, but the JIT calls non-virtual members on it. The cppia generator must therefore emit a `FUN` for every method body, including abstract methods, or the JIT reads out of bounds. -- **Job logs are often too large to read in one go.** Fetch them with a bounded `tail_lines` (or save them to a file) and search for `stop reason`, `hxSehException` or `Command exited with`, rather than reading them in full. +- **Useful search terms in job logs:** `stop reason` (lldb), `hxSehException` and `Command exited with`.