Skip to content

Commit

Permalink
feat: show backtraces on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
XuehaiPan committed Nov 10, 2024
1 parent 3988e78 commit 0dd7da2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/tests-with-pydebug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,12 @@ jobs:
$DebuggersDir = "$WindowsKitsDir\Debuggers\x64"
Get-ChildItem -Path $DebuggersDir
$Env:PATH = "$DebuggersDir;$Env:PATH"
$PYTEST = 'cdb -hd -gG -o -c ".sympath" -c ".srcpath" ${{ env.PYTHON }} -X dev -m pytest'
$PYTEST = 'cdb -gG -o -c ".dump /ma /u core.dmp; !py; g; q" ${{ env.PYTHON }} -X dev -m pytest'
Write-Output "_NT_SOURCE_PATH=$Env:_NT_SOURCE_PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "_NT_SYMBOL_PATH=$Env:_NT_SYMBOL_PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "PATH=$Env:PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "PYTEST=$PYTEST" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
$regKey="HKLM:\Software\Microsoft\Windows\Windows Error Reporting\LocalDumps"
New-Item -Path $regKey -Force | Out-Null
Set-ItemProperty -Path $regKey -Name 'DumpFolder' -Value $pwd
Set-ItemProperty -Path $regKey -Name 'DumpCount' -Value 10
Set-ItemProperty -Path $regKey -Name 'DumpType' -Value 2
Get-ItemProperty -Path $regKey
cdb -version
- name: Install OpTree
Expand Down Expand Up @@ -317,9 +310,9 @@ jobs:
if: ${{ !cancelled() }}
shell: bash
run: |
if [[ -n "$(find . -iname "core.*.[1-9]*")" ]]; then
if [[ -n "$(find . -iname "core.*.[1-9]*" -o -iname "core_*.dmp")" ]]; then
echo "Found core dumps:"
ls -alh $(find . -iname "core.*.[1-9]*")
ls -alh $(find . -iname "core.*.[1-9]*" -o -iname "core_*.dmp")
BACKTRACE_COMMAND=""
if [[ "${{ runner.os }}" == 'Linux' ]]; then
echo "::group::Install GDB"
Expand All @@ -334,6 +327,8 @@ jobs:
brew install llvm --quiet
echo "::endgroup::"
BACKTRACE_COMMAND="lldb --file ${{ env.PYTHON }} --core '{}' -o 'bt' -o 'q'"
elif [[ "${{ runner.os }}" == 'Windows' ]]; then
BACKTRACE_COMMAND="cdb -z '{}' -c \"!py; !analyze -v; .ecxr; k; q\""
fi
if [[ -n "${BACKTRACE_COMMAND}" ]]; then
echo "Collecting backtraces:"
Expand All @@ -342,6 +337,11 @@ jobs:
${BACKTRACE_COMMAND};
echo '::endgroup::';
" ';'
find . -iname "core_*.dmp" -exec bash -xc "
echo '::group::backtrace from: {}';
${BACKTRACE_COMMAND};
echo '::endgroup::';
" ';'
fi
fi
Expand All @@ -361,5 +361,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: coredump-${{ env.PYTHON_TAG }}-${{ runner.os }}
path: tests/core.*
path: |
tests/core.*
tests/core_*.dmp
if-no-files-found: ignore
24 changes: 13 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,12 @@ jobs:
$DebuggersDir = "$WindowsKitsDir\Debuggers\x64"
Get-ChildItem -Path $DebuggersDir
$Env:PATH = "$DebuggersDir;$Env:PATH"
$PYTEST = 'cdb -hd -gG -o -c ".sympath" -c ".srcpath" ${{ env.PYTHON }} -X dev -m pytest'
$PYTEST = 'cdb -gG -o -c ".dump /ma /u core.dmp; !py; g; q" ${{ env.PYTHON }} -X dev -m pytest'
Write-Output "_NT_SOURCE_PATH=$Env:_NT_SOURCE_PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "_NT_SYMBOL_PATH=$Env:_NT_SYMBOL_PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "PATH=$Env:PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "PYTEST=$PYTEST" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
$regKey="HKLM:\Software\Microsoft\Windows\Windows Error Reporting\LocalDumps"
New-Item -Path $regKey -Force | Out-Null
Set-ItemProperty -Path $regKey -Name 'DumpFolder' -Value $pwd
Set-ItemProperty -Path $regKey -Name 'DumpCount' -Value 10
Set-ItemProperty -Path $regKey -Name 'DumpType' -Value 2
Get-ItemProperty -Path $regKey
cdb -version
- name: Install test dependencies
Expand Down Expand Up @@ -184,9 +177,9 @@ jobs:
if: ${{ !cancelled() }}
shell: bash
run: |
if [[ -n "$(find . -iname "core.*.[1-9]*")" ]]; then
if [[ -n "$(find . -iname "core.*.[1-9]*" -o -iname "core_*.dmp")" ]]; then
echo "Found core dumps:"
ls -alh $(find . -iname "core.*.[1-9]*")
ls -alh $(find . -iname "core.*.[1-9]*" -o -iname "core_*.dmp")
BACKTRACE_COMMAND=""
if [[ "${{ runner.os }}" == 'Linux' ]]; then
echo "::group::Install GDB"
Expand All @@ -201,6 +194,8 @@ jobs:
brew install llvm --quiet
echo "::endgroup::"
BACKTRACE_COMMAND="lldb --file ${{ env.PYTHON }} --core '{}' -o 'bt' -o 'q'"
elif [[ "${{ runner.os }}" == 'Windows' ]]; then
BACKTRACE_COMMAND="cdb -z '{}' -c \"!py; !analyze -v; .ecxr; k; q\""
fi
if [[ -n "${BACKTRACE_COMMAND}" ]]; then
echo "Collecting backtraces:"
Expand All @@ -209,6 +204,11 @@ jobs:
${BACKTRACE_COMMAND};
echo '::endgroup::';
" ';'
find . -iname "core_*.dmp" -exec bash -xc "
echo '::group::backtrace from: {}';
${BACKTRACE_COMMAND};
echo '::endgroup::';
" ';'
fi
fi
Expand All @@ -231,7 +231,9 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: coredump-${{ env.PYTHON_TAG }}-${{ runner.os }}
path: tests/core.*
path: |
tests/core.*
tests/core_*.dmp
if-no-files-found: ignore

upload-coverage:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ __pycache__/
# Core dump files
core.[1-9]*
core.*.[1-9]*
core.dmp
core_*.dmp

# Distribution / packaging
.Python
Expand Down

0 comments on commit 0dd7da2

Please sign in to comment.