-
Notifications
You must be signed in to change notification settings - Fork 87
/
Get-SymbolFiles.ps1
66 lines (61 loc) · 1.95 KB
/
Get-SymbolFiles.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<#
.SYNOPSIS
Collect the list of PDBs built in this repo.
.PARAMETER Path
The directory to recursively search for PDBs.
.PARAMETER Tests
A switch indicating to find PDBs only for test binaries instead of only for shipping shipping binaries.
#>
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[string]$Path,
[switch]$Tests
)
$ActivityName = "Collecting symbols from $Path"
Write-Progress -Activity $ActivityName -CurrentOperation "Discovery PDB files"
$PDBs = Get-ChildItem -rec "$Path/*.pdb"
# Filter PDBs to product OR test related.
$testregex = "unittest|tests|\.test\."
Write-Progress -Activity $ActivityName -CurrentOperation "De-duplicating symbols"
$PDBsByHash = @{}
$i = 0
$PDBs |% {
Write-Progress -Activity $ActivityName -CurrentOperation "De-duplicating symbols" -PercentComplete (100 * $i / $PDBs.Length)
$hash = Get-FileHash $_
$i++
Add-Member -InputObject $_ -MemberType NoteProperty -Name Hash -Value $hash.Hash
Write-Output $_
} | Sort-Object CreationTime |% {
# De-dupe based on hash. Prefer the first match so we take the first built copy.
if (-not $PDBsByHash.ContainsKey($_.Hash)) {
$PDBsByHash.Add($_.Hash, $_.FullName)
Write-Output $_
}
} |? {
if ($Tests) {
$_.FullName -match $testregex
} else {
$_.FullName -notmatch $testregex
}
} |% {
# Collect the DLLs/EXEs as well.
$rootName = "$($_.Directory)/$($_.BaseName)"
if ($rootName.EndsWith('.ni')) {
$rootName = $rootName.Substring(0, $rootName.Length - 3)
}
$dllPath = "$rootName.dll"
$exePath = "$rootName.exe"
if (Test-Path $dllPath) {
$BinaryImagePath = $dllPath
} elseif (Test-Path $exePath) {
$BinaryImagePath = $exePath
} else {
Write-Warning "`"$_`" found with no matching binary file."
$BinaryImagePath = $null
}
if ($BinaryImagePath) {
Write-Output $BinaryImagePath
Write-Output $_.FullName
}
}