Files
TransPyC/_repro_gdb.py
T
2026-08-22 02:35:30 +08:00

33 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""用 gdb 循环运行 FuncTest 编译,捕获崩溃时的 backtrace"""
import subprocess
import sys
GDB = r'D:\msys64\mingw64\bin\gdb.exe'
EXE = r'd:\Users\TermiNexus\Desktop\TransPyC\TransPyV\output\TransPyV.exe'
PROJ = r'd:\Users\TermiNexus\Desktop\TransPyC\Test\FuncTest\project.json'
CWD = r'd:\Users\TermiNexus\Desktop\TransPyC\Test\FuncTest'
OUT_LOG = r'd:\Users\TermiNexus\Desktop\TransPyC\_gdb_crash.log'
for i in range(1, 13):
print(f"[gdb run {i}] ...", flush=True)
try:
r = subprocess.run([GDB, '-batch', '-ex', 'set pagination off',
'-ex', f'run --project {PROJ} --clean',
'-ex', 'bt 30', '--args', EXE],
cwd=CWD, capture_output=True, text=True,
encoding='utf-8', errors='replace', timeout=600)
except subprocess.TimeoutExpired:
print(f"[gdb run {i}] 超时", flush=True)
continue
out = (r.stdout or '') + '\n' + (r.stderr or '')
if 'Program received signal' in out or 'SIGSEGV' in out or 'SIGABRT' in out or 'SIGILL' in out:
with open(OUT_LOG, 'w', encoding='utf-8', errors='replace') as f:
f.write(out)
print(f"=== gdb 捕获信号于 run {i},已存 {OUT_LOG} ===", flush=True)
sys.exit(0)
print(f"[gdb run {i}] 正常结束,未崩溃", flush=True)
print("12 次 gdb 均未崩溃", flush=True)
sys.exit(1)