mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
77 lines
2.3 KiB
C#
77 lines
2.3 KiB
C#
using Microsoft.Iris.Debug.Symbols;
|
|
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace Microsoft.Iris.DebugAdapter;
|
|
|
|
public class DebugSymbolResolver(string symbolDir, string? sourceDir)
|
|
{
|
|
private readonly DirectoryInfo _symbolDir = new(symbolDir);
|
|
private readonly DirectoryInfo? _sourceDir = sourceDir is not null ? new(sourceDir) : null;
|
|
|
|
public ApplicationDebugSymbols? GetForApplication(string? application)
|
|
{
|
|
if (application is null)
|
|
return null;
|
|
|
|
var fileName = $"{application}.asym.json";
|
|
var asymFile = FindFile(fileName, _symbolDir);
|
|
|
|
if (asymFile is null)
|
|
return null;
|
|
|
|
using var stream = asymFile.OpenRead();
|
|
using var reader = new StreamReader(stream);
|
|
return DebugSymbolsJsonParser.ParseForApplication(reader.ReadToEnd());
|
|
}
|
|
|
|
public FileDebugSymbols? GetForFile(string? file, string? application = null)
|
|
{
|
|
if (file is null)
|
|
return null;
|
|
|
|
var fileName = $"{file}.fsym.json";
|
|
var fsymFile = FindFile(fileName, _symbolDir);
|
|
|
|
if (fsymFile is not null)
|
|
{
|
|
using var stream = fsymFile.OpenRead();
|
|
using var reader = new StreamReader(stream);
|
|
var fsym = DebugSymbolsJsonParser.ParseForFile(reader.ReadToEnd());
|
|
|
|
var sourceFile = FindFile(file, _sourceDir);
|
|
if (sourceFile is not null)
|
|
{
|
|
using var sourceStream = sourceFile.OpenRead();
|
|
using var sourceReader = new StreamReader(sourceStream);
|
|
fsym.SetSourceCode(sourceReader.ReadToEnd());
|
|
}
|
|
|
|
return fsym;
|
|
}
|
|
|
|
if (application is null)
|
|
return null;
|
|
|
|
var asym = GetForApplication(application);
|
|
if (asym is null)
|
|
return null;
|
|
|
|
return asym.GetForFile(fileName);
|
|
}
|
|
|
|
private static FileInfo? FindFile(string fileName, DirectoryInfo? dir)
|
|
{
|
|
return dir?
|
|
.EnumerateFiles()
|
|
.FirstOrDefault(f => AreEquivalentFileNames(f.Name, fileName));
|
|
}
|
|
|
|
private static bool AreEquivalentFileNames(string fileName1, string fileName2)
|
|
{
|
|
// NOTE: Assumes Windows. Should be trivial to support other filesystems later.
|
|
return fileName1.Equals(fileName2, StringComparison.InvariantCultureIgnoreCase);
|
|
}
|
|
}
|