forked from dotnet/roslyn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reference new debugger bits (dotnet#58051)
- Loading branch information
1 parent
09c4975
commit 9af4b1e
Showing
5 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/VisualStudio/Core/Def/PdbSourceDocument/SourceLinkService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Composition; | ||
using System.IO; | ||
using System.Reflection.PortableExecutable; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
using Microsoft.CodeAnalysis.PdbSourceDocument; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
using Microsoft.VisualStudio.Debugger.Contracts.SourceLink; | ||
using Microsoft.VisualStudio.Debugger.Contracts.SymbolLocator; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServices.PdbSourceDocument | ||
{ | ||
[Export(typeof(ISourceLinkService)), Shared] | ||
internal class SourceLinkService : ISourceLinkService | ||
{ | ||
private readonly IDebuggerSymbolLocatorService _debuggerSymbolLocatorService; | ||
private readonly IDebuggerSourceLinkService _debuggerSourceLinkService; | ||
|
||
[ImportingConstructor] | ||
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
public SourceLinkService(IDebuggerSymbolLocatorService debuggerSymbolLocatorService, IDebuggerSourceLinkService debuggerSourceLinkService) | ||
{ | ||
_debuggerSymbolLocatorService = debuggerSymbolLocatorService; | ||
_debuggerSourceLinkService = debuggerSourceLinkService; | ||
} | ||
|
||
public async Task<PdbFilePathResult?> GetPdbFilePathAsync(string dllPath, PEReader peReader, IPdbSourceDocumentLogger? logger, CancellationToken cancellationToken) | ||
{ | ||
var hasCodeViewEntry = false; | ||
uint timeStamp = 0; | ||
CodeViewDebugDirectoryData codeViewEntry = default; | ||
using var _ = ArrayBuilder<PdbChecksum>.GetInstance(out var checksums); | ||
foreach (var entry in peReader.ReadDebugDirectory()) | ||
{ | ||
if (entry.Type == DebugDirectoryEntryType.PdbChecksum) | ||
{ | ||
var checksum = peReader.ReadPdbChecksumDebugDirectoryData(entry); | ||
checksums.Add(new PdbChecksum(checksum.AlgorithmName, checksum.Checksum)); | ||
} | ||
else if (entry.Type == DebugDirectoryEntryType.CodeView && entry.IsPortableCodeView) | ||
{ | ||
hasCodeViewEntry = true; | ||
timeStamp = entry.Stamp; | ||
codeViewEntry = peReader.ReadCodeViewDebugDirectoryData(entry); | ||
} | ||
} | ||
|
||
if (!hasCodeViewEntry) | ||
return null; | ||
|
||
var pdbInfo = new SymbolLocatorPdbInfo( | ||
Path.GetFileName(codeViewEntry.Path), | ||
codeViewEntry.Guid, | ||
(uint)codeViewEntry.Age, | ||
timeStamp, | ||
checksums.ToImmutable(), | ||
dllPath, | ||
codeViewEntry.Path); | ||
|
||
var flags = SymbolLocatorSearchFlags.None; // TODO: Add option to specify ForceMsftSymbolServer and ForceNuGetSymbolServer: https://github.com/dotnet/roslyn/issues/55834 | ||
var result = await _debuggerSymbolLocatorService.LocateSymbolFileAsync(pdbInfo, flags, progress: null, cancellationToken).ConfigureAwait(false); | ||
|
||
// TODO: Logging: https://github.com/dotnet/roslyn/issues/57352 | ||
if (result.Found && result.SymbolFilePath is not null) | ||
{ | ||
return new PdbFilePathResult( | ||
result.SymbolFilePath, | ||
result.Status, | ||
result.Log, | ||
result.IsPortablePdb); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public async Task<SourceFilePathResult?> GetSourceFilePathAsync(string url, string relativePath, IPdbSourceDocumentLogger? logger, CancellationToken cancellationToken) | ||
{ | ||
var result = await _debuggerSourceLinkService.GetSourceLinkAsync(url, relativePath, allowInteractiveLogin: false, cancellationToken).ConfigureAwait(false); | ||
|
||
// TODO: Logging: https://github.com/dotnet/roslyn/issues/57352 | ||
if (result.Status == SourceLinkResultStatus.Succeeded && result.Path is not null) | ||
{ | ||
return new SourceFilePathResult( | ||
result.Path, | ||
result.Log); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |