|
| 1 | +#!/bin/bash |
| 2 | +# Native crash capture for the UI smoke launchers. A GUI segfault is the |
| 3 | +# failure these tests most need to explain, and it lands in C/C++ (Qt, |
| 4 | +# dbus, GL) where PYTHONFAULTHANDLER stops at the event-loop frame. Arm a |
| 5 | +# core dump before launch; after the run, if the GUI left a core, print a |
| 6 | +# native backtrace into the log so CI shows the faulting frame directly. |
| 7 | +# Source with LIB_DIR set; runs only on the failure path, so green runs |
| 8 | +# pay nothing. |
| 9 | + |
| 10 | +crashdump_arm() { |
| 11 | + CORE_DIR="$(mktemp -d -t ui-smoke-cores.XXXXXX)" |
| 12 | + export CORE_DIR |
| 13 | + ulimit -c unlimited 2>/dev/null || true |
| 14 | + # core_pattern is global and needs root; best-effort (CI has sudo). |
| 15 | + # If it does not take, crashdump_report still finds a cwd "core". |
| 16 | + sudo sysctl -w "kernel.core_pattern=$CORE_DIR/core.%e.%p" >/dev/null 2>&1 || true |
| 17 | +} |
| 18 | + |
| 19 | +crashdump_report() { |
| 20 | + [ -n "${CORE_DIR:-}" ] || return 0 |
| 21 | + local core |
| 22 | + # shellcheck disable=SC2012 # mktemp dir, no odd filenames |
| 23 | + core=$(ls -t "$CORE_DIR"/core* ./core* /tmp/core* 2>/dev/null | head -1) |
| 24 | + if [ -n "$core" ]; then |
| 25 | + echo "=== crash: native backtrace ($core) ===" |
| 26 | + # gdb is not on the CI runner by default; pull it in to read the core. |
| 27 | + command -v gdb >/dev/null 2>&1 || sudo apt-get install -y -q gdb >/dev/null 2>&1 || true |
| 28 | + if command -v gdb >/dev/null 2>&1; then |
| 29 | + # "bt" first: gdb auto-selects the faulting thread on a SIGSEGV |
| 30 | + # core. "thread apply all bt" after gives the rest. |
| 31 | + gdb -batch -nx \ |
| 32 | + -ex "bt" \ |
| 33 | + -ex "echo \n=== all threads ===\n" \ |
| 34 | + -ex "thread apply all bt" \ |
| 35 | + "$(command -v python3)" "$core" 2>&1 | head -400 |
| 36 | + else |
| 37 | + echo "(gdb unavailable; core left at $core)" |
| 38 | + fi |
| 39 | + fi |
| 40 | + rm -rf "$CORE_DIR" |
| 41 | +} |
0 commit comments