Skip to content

Commit 5875d54

Browse files
authored
Open pdb files with FileShare.Read and FileShare.Delete (dotnet/corefx#38214)
* Added test to verify PDB isn't locked Commit migrated from dotnet/corefx@a194082
1 parent 6dc6866 commit 5875d54

4 files changed

Lines changed: 38 additions & 10 deletions

File tree

src/libraries/System.Diagnostics.StackTrace/System.Diagnostics.StackTrace.sln

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio 15
3-
VisualStudioVersion = 15.0.27213.1
2+
# Visual Studio Version 16
3+
VisualStudioVersion = 16.0.28803.202
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Diagnostics.StackTrace.Tests", "tests\System.Diagnostics.StackTrace.Tests.csproj", "{297A9116-1005-499D-A895-2063D03E4C94}"
66
ProjectSection(ProjectDependencies) = postProject
@@ -26,10 +26,10 @@ Global
2626
Release|Any CPU = Release|Any CPU
2727
EndGlobalSection
2828
GlobalSection(ProjectConfigurationPlatforms) = postSolution
29-
{297A9116-1005-499D-A895-2063D03E4C94}.Debug|Any CPU.ActiveCfg = netstandard-Debug|Any CPU
30-
{297A9116-1005-499D-A895-2063D03E4C94}.Debug|Any CPU.Build.0 = netstandard-Debug|Any CPU
31-
{297A9116-1005-499D-A895-2063D03E4C94}.Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
32-
{297A9116-1005-499D-A895-2063D03E4C94}.Release|Any CPU.Build.0 = netstandard-Release|Any CPU
29+
{297A9116-1005-499D-A895-2063D03E4C94}.Debug|Any CPU.ActiveCfg = uap-Debug|Any CPU
30+
{297A9116-1005-499D-A895-2063D03E4C94}.Debug|Any CPU.Build.0 = uap-Debug|Any CPU
31+
{297A9116-1005-499D-A895-2063D03E4C94}.Release|Any CPU.ActiveCfg = uap-Release|Any CPU
32+
{297A9116-1005-499D-A895-2063D03E4C94}.Release|Any CPU.Build.0 = uap-Release|Any CPU
3333
{02304469-722E-4723-92A1-820B9A37D275}.Debug|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU
3434
{02304469-722E-4723-92A1-820B9A37D275}.Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
3535
{02304469-722E-4723-92A1-820B9A37D275}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU

src/libraries/System.Diagnostics.StackTrace/src/System/Diagnostics/StackTraceSymbols.CoreCLR.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ void IDisposable.Dispose()
5252
/// <param name="sourceFile">source file return</param>
5353
/// <param name="sourceLine">line number return</param>
5454
/// <param name="sourceColumn">column return</param>
55-
internal void GetSourceLineInfo(Assembly assembly, string assemblyPath, IntPtr loadedPeAddress, int loadedPeSize,
56-
IntPtr inMemoryPdbAddress, int inMemoryPdbSize, int methodToken, int ilOffset,
55+
internal void GetSourceLineInfo(Assembly assembly, string assemblyPath, IntPtr loadedPeAddress, int loadedPeSize,
56+
IntPtr inMemoryPdbAddress, int inMemoryPdbSize, int methodToken, int ilOffset,
5757
out string? sourceFile, out int sourceLine, out int sourceColumn)
5858
{
5959
sourceFile = null;
@@ -212,7 +212,8 @@ internal void GetSourceLineInfo(Assembly assembly, string assemblyPath, IntPtr l
212212

213213
try
214214
{
215-
return File.OpenRead(path);
215+
// Open the file with read and delete FileShare flags. This matches what dll loading does
216+
return new FileStream(path!, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete);
216217
}
217218
catch
218219
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.IO;
7+
using Xunit;
8+
9+
namespace System.Diagnostics.SymbolStore.Tests
10+
{
11+
public class StackTraceSymbolsTests
12+
{
13+
[Fact]
14+
public void StackTraceSymbolsDoNotLockFile()
15+
{
16+
var asmPath = typeof(StackTraceSymbolsTests).Assembly.Location;
17+
var pdbPath = Path.ChangeExtension(asmPath, ".pdb");
18+
19+
Assert.True(File.Exists(pdbPath));
20+
new StackTrace(true).GetFrames();
21+
File.Move(pdbPath, pdbPath);
22+
}
23+
}
24+
}

src/libraries/System.Diagnostics.StackTrace/tests/System.Diagnostics.StackTrace.Tests.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<ProjectGuid>{297A9116-1005-499D-A895-2063D03E4C94}</ProjectGuid>
44
<Configurations>netcoreapp-Debug;netcoreapp-Release;uap-Debug;uap-Release</Configurations>
@@ -13,4 +13,7 @@
1313
<Compile Include="StackFrameTests.cs" />
1414
<Compile Include="StackFrameExtensionsTests.cs" />
1515
</ItemGroup>
16+
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
17+
<Compile Include="StackTraceSymbolsTests.cs" />
18+
</ItemGroup>
1619
</Project>

0 commit comments

Comments
 (0)