If you work with node native modules at all, you'll find it very handy to be able to look at proper callstacks in the node.js codebase.
But with so many node versions you might run into, it can be a bit of a pain to download symbols by hand, if you can even remember where to go.
Enter this little PowerShell script that basically runs node --version
, then downloads the symbols and unzips them for you.
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$node = (get-command node -ErrorAction SilentlyContinue).Path
if ($node) {
write-host Using $node
} else {
throw "Unable to find node on path"
}
$nodeVersion = & $node --version
Write-Host "The version is $nodeVersion"
# consider doing something smart with this if desired
if (-not ($nodeVersion -match 'v\d+\.\d+\.\d+')) {
throw "Cannot parse version"
}
$targetDirPath = [IO.Path]::Combine($env:temp, 'nodejs-symbols', $nodeVersion)
$zipFilePath = [IO.Path]::Combine($targetDirPath, 'node_pdb.zip')
$pdbFilePath = [IO.Path]::Combine($targetDirPath, 'node.pdb')
$sourceUrl = "https://nodejs.org/download/release/$nodeVersion/win-x64/node_pdb.zip"
Write-Host "Downloading $sourceUrl to $targetDirPath"
if (-not (Test-Path $targetDirPath)) {
$i = New-Item $targetDirPath -ItemType Directory
}
if (-not (Test-Path $zipFilePath)) {
Invoke-WebRequest -Uri $sourceUrl -OutFile $zipFilePath
}
Expand-Archive -Path $zipFilePath -DestinationPath $targetDirPath
Write-Host "PDB available at $pdbFilePath"
Happy node debugging!
Tags: cpp powershell