mirror of
https://github.com/ZuneDev/MicrosoftIris.git
synced 2026-07-27 13:13:29 -07:00
More debug symbol work
This commit is contained in:
@@ -25,27 +25,6 @@ public class FileDebugSymbols
|
|||||||
|
|
||||||
public SourceMap SourceMap { get; } = new();
|
public SourceMap SourceMap { get; } = new();
|
||||||
|
|
||||||
public (uint Offset, SourceSpan Span) GetLocationFromPosition(SourcePosition pos)
|
|
||||||
{
|
|
||||||
var foundLocation = SourceMap.Xml.FirstOrDefault(kvp =>
|
|
||||||
{
|
|
||||||
var offset = kvp.Key;
|
|
||||||
var span = kvp.Value;
|
|
||||||
return span.Contains(pos);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (foundLocation.Equals(default(KeyValuePair<uint, SourceSpan>)))
|
|
||||||
throw new KeyNotFoundException($"No offset was assigned to line {pos.Line}, column {pos.Column}");
|
|
||||||
|
|
||||||
return (foundLocation.Key, foundLocation.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public uint OffsetByLineAndColumn(int line, int col) => OffsetByLineAndColumn(new(line, col));
|
|
||||||
|
|
||||||
public SourceSpan GetContainingSpan(SourcePosition pos) => GetLocationFromPosition(pos).Span;
|
|
||||||
|
|
||||||
public uint OffsetByLineAndColumn(SourcePosition pos) => GetLocationFromPosition(pos).Offset;
|
|
||||||
|
|
||||||
public string GetSourceSubstring(SourceSpan span)
|
public string GetSourceSubstring(SourceSpan span)
|
||||||
{
|
{
|
||||||
if (!HasSourceCode())
|
if (!HasSourceCode())
|
||||||
@@ -56,8 +35,7 @@ public class FileDebugSymbols
|
|||||||
|
|
||||||
StringBuilder sb = new();
|
StringBuilder sb = new();
|
||||||
|
|
||||||
int currentLineIndex = startLine;
|
for (int currentLineIndex = startLine; currentLineIndex <= endLine; ++currentLineIndex)
|
||||||
while (currentLineIndex <= endLine)
|
|
||||||
{
|
{
|
||||||
var line = _sourceCodeLines[currentLineIndex];
|
var line = _sourceCodeLines[currentLineIndex];
|
||||||
|
|
||||||
@@ -69,7 +47,12 @@ public class FileDebugSymbols
|
|||||||
? endColumn
|
? endColumn
|
||||||
: ^1;
|
: ^1;
|
||||||
|
|
||||||
sb.AppendLine(line[lineStartIndex..lineEndIndex]);
|
var start = lineStartIndex.GetOffset(line.Length);
|
||||||
|
var end = lineEndIndex.GetOffset(line.Length);
|
||||||
|
var length = end - start;
|
||||||
|
|
||||||
|
if (length > 0)
|
||||||
|
sb.AppendLine(line.Substring(start, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
@@ -90,6 +73,27 @@ public class SourceMap
|
|||||||
{
|
{
|
||||||
public Dictionary<uint, SourceSpan> Xml { get; } = [];
|
public Dictionary<uint, SourceSpan> Xml { get; } = [];
|
||||||
public Dictionary<uint, Tuple<int, int>> Script { get; } = [];
|
public Dictionary<uint, Tuple<int, int>> Script { get; } = [];
|
||||||
|
|
||||||
|
public (uint Offset, SourceSpan Span)? GetLocationFromPosition(SourcePosition pos)
|
||||||
|
{
|
||||||
|
var foundLocation = Xml.FirstOrDefault(kvp =>
|
||||||
|
{
|
||||||
|
var offset = kvp.Key;
|
||||||
|
var span = kvp.Value;
|
||||||
|
return span.Contains(pos);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (foundLocation.Equals(default(KeyValuePair<uint, SourceSpan>)))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return (foundLocation.Key, foundLocation.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint? OffsetByLineAndColumn(int line, int col) => OffsetByLineAndColumn(new(line, col));
|
||||||
|
|
||||||
|
public SourceSpan GetContainingSpan(SourcePosition pos) => GetLocationFromPosition(pos)?.Span;
|
||||||
|
|
||||||
|
public uint? OffsetByLineAndColumn(SourcePosition pos) => GetLocationFromPosition(pos)?.Offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DebuggerDisplay("L{Line}C{Column}")]
|
[DebuggerDisplay("L{Line}C{Column}")]
|
||||||
@@ -168,6 +172,6 @@ public class SourceSpan
|
|||||||
|
|
||||||
public SourcePosition End { get; }
|
public SourcePosition End { get; }
|
||||||
|
|
||||||
public bool Contains(SourcePosition pos) => Start >= pos && pos < End;
|
public bool Contains(SourcePosition pos) => Start <= pos && pos < End;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user