Skip to content

Commit d4ca3f9

Browse files
sprendermsftjohnterickson
authored andcommitted
Provide opt-in to latest lkg symbol binaries
1 parent 7635cd4 commit d4ca3f9

25 files changed

+380
-154
lines changed

Tasks/PublishSymbols/IndexHelpers/DbghelpFunctions.ps1

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,16 @@ function Add-DbghelpLibrary {
44

55
Trace-VstsEnteringInvocation $MyInvocation
66

7-
$dbgAssembly = "$(Get-VstsTaskVariable -Name Agent.HomeDirectory -Require)\externals\symstore\dbghelp.dll"
8-
$legacyDbgAssembly = "$(Get-VstsTaskVariable -Name Agent.HomeDirectory -Require)\Agent\Worker\Tools\Symstore\dbghelp.dll"
9-
if (!([System.IO.File]::Exists($dbgAssembly)) -and
10-
([System.IO.File]::Exists($legacyDbgAssembly)))
11-
{
12-
$dbgAssembly = $legacyDbgAssembly
13-
}
7+
$dbghelpPath = Get-DbghelpPath
148

15-
[string]$filePath = Assert-VstsPath -LiteralPath $dbgAssembly -PathType Leaf -PassThru
169
[bool]$isLoaded = $false
1710
foreach ($module in (Get-CurrentProcess).Modules) {
1811
if ($module.ModuleName -eq 'dbghelp.dll') {
1912
$isLoaded = $true
20-
if ($module.FileName -eq $filePath) {
21-
Write-Verbose "Module dbghelp.dll is already loaded from the expected file path."
13+
if ($module.FileName -eq $dbghelpPath) {
14+
Write-Verbose "Module dbghelp.dll is already loaded from the expected file path: $dbghelpPath"
2215
} else {
23-
Write-Warning (Get-VstsLocString -Key UnexpectedDbghelpdllExpected0Actual1 -ArgumentList $filePath, $module.FileName)
16+
Write-Warning (Get-VstsLocString -Key UnexpectedDbghelpdllExpected0Actual1 -ArgumentList $dbghelpPath, $module.FileName)
2417
}
2518

2619
# Don't short-circuit the loop. The module could be loaded more
@@ -29,10 +22,10 @@ function Add-DbghelpLibrary {
2922
}
3023

3124
if (!$isLoaded) {
32-
$hModule = Invoke-LoadLibrary -LiteralPath $filePath
25+
$hModule = Invoke-LoadLibrary -LiteralPath $dbghelpPath
3326
if ($hModule -eq [System.IntPtr]::Zero) {
3427
$errorCode = Get-LastWin32Error
35-
Write-Warning (Get-VstsLocString -Key "FailedToLoadDbghelpDllFrom0ErrorCode1" -ArgumentList $filePath, $errorCode)
28+
Write-Warning (Get-VstsLocString -Key "FailedToLoadDbghelpDllFrom0ErrorCode1" -ArgumentList $dbghelpPath, $errorCode)
3629
return
3730
}
3831

Tasks/PublishSymbols/IndexHelpers/IndexFunctions.ps1

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,7 @@ function Invoke-IndexSources {
1313
return
1414
}
1515

16-
# Resolve location of pdbstr.exe.
17-
$pdbstrPath = "$(Get-VstsTaskVariable -Name Agent.HomeDirectory -Require)\externals\pdbstr\pdbstr.exe"
18-
$legacyPdbstrPath = "$(Get-VstsTaskVariable -Name Agent.HomeDirectory -Require)\Agent\Worker\Tools\Pdbstr\pdbstr.exe"
19-
if (!([System.IO.File]::Exists($pdbstrPath)) -and
20-
([System.IO.File]::Exists($legacyPdbstrPath)))
21-
{
22-
$pdbstrPath = $legacyPdbstrPath
23-
}
24-
25-
$pdbstrPath = Assert-VstsPath -LiteralPath $pdbstrPath -PathType Leaf -PassThru
16+
$pdbstrPath = Get-PdbstrPath
2617

2718
# Warn if spaces in the temp path.
2819
if ("$env:TMP".Contains(' ')) {

Tasks/PublishSymbols/IndexHelpers/IndexHelpers.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#requires -Module SymbolsCommon,VstsTaskSdk
2+
13
[CmdletBinding()]
24
param()
35

Tasks/PublishSymbols/PublishHelpers/CommonFunctions.ps1

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
########################################
22
# Private functions.
33
########################################
4-
function Get-SymStorePath {
5-
$symstorePath = "$(Get-VstsTaskVariable -Name Agent.HomeDirectory -Require)\externals\symstore\symstore.exe"
6-
$legacySymstorePath = "$(Get-VstsTaskVariable -Name Agent.HomeDirectory -Require)\Agent\Worker\Tools\Symstore\symstore.exe"
7-
if (!([System.IO.File]::Exists($symstorePath)) -and
8-
([System.IO.File]::Exists($legacySymstorePath)))
9-
{
10-
$symstorePath = $legacySymstorePath
11-
}
12-
13-
Assert-VstsPath -LiteralPath $symstorePath -PathType Leaf -PassThru
14-
}
15-
164
function Get-ValidValue {
175
[CmdletBinding()]
186
param(

Tasks/PublishSymbols/PublishHelpers/PublishHelpers.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#requires -Module SymbolsCommon,VstsTaskSdk
2+
13
[CmdletBinding()]
24
param()
35

Tasks/PublishSymbols/PublishSymbols.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
[CmdletBinding()]
22
param()
33

4+
# # Ad-hoc test procedure
5+
# node make.js build --task PublishSymbols
6+
# $env:System_Culture = "en-US"
7+
# Import-Module .\_build\Tasks\PublishSymbols\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1
8+
# $env:Agent_HomeDirectory = "D:\Downloads\vsts-agent-win7-x64-2.117.1"
9+
# $env:PublishSymbols_Debug = "true"
10+
# $env:PublishSymbols_UseDbgLkg = "true"
11+
# .\_build\Tasks\PublishSymbols\PublishSymbols.ps1
12+
413
Trace-VstsEnteringInvocation $MyInvocation
514
try {
615
# Import the localized strings.
@@ -10,6 +19,19 @@ try {
1019
[int]$SymbolsMaximumWaitTime = Get-VstsInput -Name 'SymbolsMaximumWaitTime' -Default '0' -AsInt
1120
[timespan]$SymbolsMaximumWaitTime = if ($SymbolsMaximumWaitTime -gt 0) { [timespan]::FromMinutes($SymbolsMaximumWaitTime) } else { [timespan]::FromHours(2) }
1221

22+
# Output dependency paths
23+
Import-Module $PSScriptRoot\SymbolsCommon.psm1
24+
$debug = [System.Convert]::ToBoolean($env:PublishSymbols_Debug)
25+
if ($debug)
26+
{
27+
$pdbstrPath = Get-PdbstrPath
28+
Write-Host "Get-PdbstrPath: $pdbstrPath"
29+
$dbghelpPath = Get-DbghelpPath
30+
Write-Host "Get-DbghelpPath: $dbghelpPath"
31+
$symstorePath = Get-SymStorePath
32+
Write-Host "Get-SymStorePath: $symstorePath"
33+
}
34+
1335
# Unpublish symbols.
1436
if ([bool]$Delete = Get-VstsInput -Name 'Delete' -AsBool) {
1537
# Construct the semaphore message.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#requires -Module VstsTaskSdk
2+
3+
# VstsTaskSdk is required above for Assert-VstsPath and Get-VstsTaskVariable
4+
# defined in ToolFunctions.ps1 and prefixed by VstsTaskSdk.psd1 which specifies DefaultCommandPrefix = 'Vsts'
5+
6+
# Existing symbol binary layout
7+
# V1 agent
8+
# ...\agent\Worker\Tools\Pdbstr\pdbstr.exe
9+
# ...\agent\Worker\Tools\Symstore\dbghelp.dll
10+
# ...\agent\Worker\Tools\Symstore\srcsrv.dll
11+
# ...\agent\Worker\Tools\Symstore\symsrv.dll
12+
# ...\agent\Worker\Tools\Symstore\symstore.exe
13+
# V2 agent
14+
# ...\agent\externals\pdbstr\pdbstr.exe
15+
# ...\agent\externals\symstore\dbghelp.dll
16+
# ...\agent\externals\symstore\srcsrv.dll
17+
# ...\agent\externals\symstore\symsrv.dll
18+
# ...\agent\externals\symstore\symstore.exe
19+
# New symbol binary layout
20+
# V1 & V2 agent
21+
# ...\tasks\PublishSymbols\{Version}\*.dll
22+
# ...\tasks\PublishSymbols\{Version}\*.exe
23+
24+
# # Ad-hoc test initialization
25+
# node make.js build --task PublishSymbols
26+
# $env:System_Culture = "en-US"
27+
# Import-Module .\_build\Tasks\PublishSymbols\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1
28+
# Import-Module .\_build\Tasks\PublishSymbols\SymbolsCommon.psm1
29+
# Get-Command -Module SymbolsCommon
30+
#
31+
# # Ad-hoc test cleanup
32+
# Remove-Module SymbolsCommon
33+
# Remove-Module VstsTaskSdk
34+
# $env:Agent_HomeDirectory = $null
35+
# $env:PublishSymbols_Debug = $null
36+
# $env:PublishSymbols_UseDbgLkg = $null
37+
# $env:System_Culture = $null
38+
#
39+
# # Ad-hoc test cases
40+
#
41+
# # V2 agent, UseDbgLkg true
42+
# $env:Agent_HomeDirectory = "D:\Downloads\vsts-agent-win7-x64-2.117.1"
43+
# $env:PublishSymbols_Debug = "true"
44+
# $env:PublishSymbols_UseDbgLkg = "true"
45+
# Get-DbghelpPath
46+
# Get-PdbstrPath
47+
# Get-SymStorePath
48+
#
49+
# # V2 agent, UseDbgLkg false
50+
# $env:Agent_HomeDirectory = "D:\Downloads\vsts-agent-win7-x64-2.117.1"
51+
# $env:PublishSymbols_Debug = "true"
52+
# $env:PublishSymbols_UseDbgLkg = $null
53+
# Get-DbghelpPath
54+
# Get-PdbstrPath
55+
# Get-SymStorePath
56+
#
57+
# # V1 agent, UseDbgLkg true
58+
# $env:Agent_HomeDirectory = "\\artifactagent1\C$\B"
59+
# $env:PublishSymbols_Debug = "true"
60+
# $env:PublishSymbols_UseDbgLkg = "true"
61+
# Get-DbghelpPath
62+
# Get-PdbstrPath
63+
# Get-SymStorePath
64+
#
65+
# # V1 agent, UseDbgLkg false
66+
# $env:Agent_HomeDirectory = "\\artifactagent1\C$\B"
67+
# $env:PublishSymbols_Debug = "true"
68+
# $env:PublishSymbols_UseDbgLkg = $null
69+
# Get-DbghelpPath
70+
# Get-PdbstrPath
71+
# Get-SymStorePath
72+
73+
function Get-SymbolBinaryPath
74+
{
75+
[CmdletBinding()]
76+
param(
77+
# Path relative to task script
78+
[Parameter(Mandatory = $true)]
79+
[string]$DbgLkgPath,
80+
# Path relative to Agent.HomeDirectory
81+
[Parameter(Mandatory = $true)]
82+
[string]$V2AgentPath,
83+
# Path relative to Agent.HomeDirectory
84+
[Parameter(Mandatory = $true)]
85+
[string]$V1AgentPath
86+
)
87+
88+
$useDbgLkg = [System.Convert]::ToBoolean($env:PublishSymbols_UseDbgLkg)
89+
if($useDbgLkg)
90+
{
91+
# Use the latest symbol binaries as specified by variable "PublishSymbols_UseDbgLkg" in the build definition
92+
$path = [System.IO.Path]::GetFullPath("$PSScriptRoot\$DbgLkgPath")
93+
}
94+
else
95+
{
96+
# Use existing binaries shipped with the agent
97+
$agentRoot = Get-VstsTaskVariable -Name Agent.HomeDirectory -Require
98+
$path = "$agentRoot\$V2AgentPath"
99+
if (-not [System.IO.File]::Exists($path))
100+
{
101+
$path = "$agentRoot\$V1AgentPath"
102+
}
103+
}
104+
105+
$debug = [System.Convert]::ToBoolean($env:PublishSymbols_Debug)
106+
if ($debug)
107+
{
108+
Write-Host "Get-SymbolBinaryPath: $path"
109+
}
110+
111+
Assert-VstsPath -LiteralPath $path -PathType Leaf
112+
return $path
113+
}
114+
115+
function Get-PdbstrPath {
116+
[CmdletBinding()]
117+
param()
118+
return Get-SymbolBinaryPath `
119+
-DbgLkgPath "pdbstr.exe" `
120+
-V2AgentPath "externals\pdbstr\pdbstr.exe" `
121+
-V1AgentPath "Agent\Worker\Tools\Pdbstr\pdbstr.exe"
122+
}
123+
124+
function Get-DbghelpPath
125+
{
126+
[CmdletBinding()]
127+
param()
128+
return Get-SymbolBinaryPath `
129+
-DbgLkgPath "dbghelp.dll" `
130+
-V2AgentPath "externals\symstore\dbghelp.dll" `
131+
-V1AgentPath "Agent\Worker\Tools\Symstore\dbghelp.dll"
132+
}
133+
134+
function Get-SymStorePath {
135+
[CmdletBinding()]
136+
param()
137+
return Get-SymbolBinaryPath `
138+
-DbgLkgPath "symstore.exe" `
139+
-V2AgentPath "externals\symstore\symstore.exe" `
140+
-V1AgentPath "Agent\Worker\Tools\Symstore\symstore.exe"
141+
}
142+
143+
Export-ModuleMember -Function @("Get-PdbstrPath", "Get-DbghelpPath", "Get-SymStorePath")

Tasks/PublishSymbols/Tests/Add-DbghelpLibrary.LoadsIfNotLoaded.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ param()
44
# Arrange.
55
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
66
. $PSScriptRoot\..\IndexHelpers\DbghelpFunctions.ps1
7-
Register-Mock Get-VstsTaskVariable { 'SomeDrive:\AgentHome' } -- -Name Agent.HomeDirectory -Require
8-
Register-Mock Assert-VstsPath { "SomeDrive:\AgentHome\Externals\Symstore\dbghelp.dll" }
7+
Register-Mock Get-DbghelpPath { "SomeDrive:\AgentHome\...\dbghelp.dll" }
98
Register-Mock Get-CurrentProcess {
109
New-Object psobject -Property @{
1110
Id = $PID
@@ -24,5 +23,5 @@ Register-Mock Write-Warning
2423
Add-DbghelpLibrary
2524

2625
# Assert.
27-
Assert-WasCalled Invoke-LoadLibrary -- -LiteralPath "SomeDrive:\AgentHome\Externals\Symstore\dbghelp.dll"
26+
Assert-WasCalled Invoke-LoadLibrary -- -LiteralPath "SomeDrive:\AgentHome\...\dbghelp.dll"
2827
Assert-WasCalled Write-Warning -Times 0

Tasks/PublishSymbols/Tests/Add-DbghelpLibrary.SkipsIfAlreadyLoaded.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ param()
44
# Arrange.
55
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
66
. $PSScriptRoot\..\IndexHelpers\DbghelpFunctions.ps1
7-
Register-Mock Get-VstsTaskVariable { 'SomeDrive:\AgentHome' } -- -Name Agent.HomeDirectory -Require
8-
Register-Mock Assert-VstsPath { "SomeDrive:\AgentHome\Externals\Symstore\dbghelp.dll" }
7+
Register-Mock Get-DbghelpPath { "SomeDrive:\AgentHome\...\dbghelp.dll" }
98
Register-Mock Get-CurrentProcess {
109
New-Object psobject -Property @{
1110
Id = $PID

Tasks/PublishSymbols/Tests/Add-DbghelpLibrary.ThrowsIfDllNotFound.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ param()
44
# Arrange.
55
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
66
. $PSScriptRoot\..\IndexHelpers\DbghelpFunctions.ps1
7-
Register-Mock Get-VstsTaskVariable { 'SomeDrive:\AgentHome' } -- -Name Agent.HomeDirectory -Require
8-
Register-Mock Assert-VstsPath { throw "This error should be thrown." } -- -LiteralPath "SomeDrive:\AgentHome\Externals\Symstore\dbghelp.dll" -PathType Leaf -PassThru
7+
Register-Mock Get-DbghelpPath { throw "This error should be thrown." }
98
Register-Mock Get-CurrentProcess
109
Register-Mock Invoke-LoadLibrary
1110

0 commit comments

Comments
 (0)