Files

67 lines
2.2 KiB
C#
Raw Permalink Normal View History

2025-11-28 18:06:42 -06:00
using Microsoft.Iris.Debug.Symbols;
namespace UIXC;
2025-11-29 01:32:09 -06:00
public class DebugSymbolResolver(string symbolDir, string? sourceDir)
2025-11-28 18:06:42 -06:00
{
private readonly DirectoryInfo _symbolDir = new(symbolDir);
2025-11-29 01:32:09 -06:00
private readonly DirectoryInfo? _sourceDir = sourceDir is not null ? new(sourceDir) : null;
2025-11-28 18:06:42 -06:00
public ApplicationDebugSymbols? GetForApplication(string application)
{
var fileName = $"{application}.asym.json";
2025-11-29 01:32:09 -06:00
var asymFile = FindFile(fileName, _symbolDir);
2025-11-28 18:06:42 -06:00
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)
{
var fileName = $"{file}.fsym.json";
2025-11-29 01:32:09 -06:00
var fsymFile = FindFile(fileName, _symbolDir);
2025-11-28 18:06:42 -06:00
if (fsymFile is not null)
{
using var stream = fsymFile.OpenRead();
using var reader = new StreamReader(stream);
2025-11-29 01:32:09 -06:00
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;
2025-11-28 18:06:42 -06:00
}
if (application is null)
return null;
var asym = GetForApplication(application);
if (asym is null)
return null;
return asym.Files.FirstOrDefault(f => f.CompiledFileName == file || f.SourceFileName == file);
}
2025-11-29 01:32:09 -06:00
private static FileInfo? FindFile(string fileName, DirectoryInfo? dir)
2025-11-28 18:06:42 -06:00
{
2025-11-29 01:32:09 -06:00
return dir?
2025-11-28 18:06:42 -06:00
.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);
}
}