diff --git a/source2/Debug/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Process.cs b/source2/Debug/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Process.cs index e32fcd9db..b29670ef8 100644 --- a/source2/Debug/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Process.cs +++ b/source2/Debug/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Process.cs @@ -617,53 +617,8 @@ namespace Cosmos.Debug.VSDebugEngine { xLabels.Add(xLabel + ":"); } } - - // Extract out the relevant lines from the .asm file. - var xCode = new StringBuilder(); - using (var xSR = new StreamReader(Path.ChangeExtension(mISO, ".asm"))) { - // Find line in ASM that starts the code block. - string xLine; - while (true) { - xLine = xSR.ReadLine(); - if (xLine == null) { - break; - } - var xParts = xLine.Trim().Split(' '); - if (xParts.Length > 0 && xParts[0].EndsWith(":")) { - if (xLabels.Contains(xParts[0])) { - // Found the first match, break. - break; - } - } - } - - while (xLine != null) { - // Extract the pertinent lines - var xParts = xLine.Trim().Split(' '); - if (xParts.Length > 0 && xParts[0].EndsWith(":")) { - // Its a label, lets check it - if (xParts.Length == 1) { - // Found an normal label. - xCode.AppendLine(xLine); - } else if (xParts[1] == ";Asm") { - // Found an ASM label. - xCode.AppendLine(xLine); - } else if (xParts[1] == ";IL" && xLabels.Contains(xParts[0])) { - // Found an exact match. Our label is in the label list - xCode.AppendLine(xLine); - } else { - // Its a label with an unrecognized comment, or its an IL label that doesn't match. - // We are done. - break; - } - } else { - // Not a label, just output it - xCode.AppendLine(xLine); - } - xLine = xSR.ReadLine(); - } - } + var xCode = AsmSource.GetSourceForLabels(Path.ChangeExtension(mISO, ".asm"), xLabels); // Send source code to the tool window mDebugDownPipe.SendCommand(VsipUi.AssemblySource, Encoding.UTF8.GetBytes(xCode.ToString())); diff --git a/source2/Debug/Cosmos.Debug.VSDebugEngine/AsmSource.cs b/source2/Debug/Cosmos.Debug.VSDebugEngine/AsmSource.cs new file mode 100644 index 000000000..585323ba9 --- /dev/null +++ b/source2/Debug/Cosmos.Debug.VSDebugEngine/AsmSource.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.IO; +using System.Text; + +namespace Cosmos.Debug.VSDebugEngine { + public static class AsmSource { + // Extract out the relevant lines from the .asm file. + public static StringBuilder GetSourceForLabels(string aAsmFile, List aLabels) { + var xCode = new StringBuilder(); + + // Find line in ASM that starts the code block. + using (var xSR = new StreamReader(aAsmFile)) { + string xLine; + while (true) { + xLine = xSR.ReadLine(); + if (xLine == null) { + break; + } + + var xParts = xLine.Trim().Split(' '); + if (xParts.Length > 0 && xParts[0].EndsWith(":")) { + if (aLabels.Contains(xParts[0])) { + // Found the first match, break. + break; + } + } + } + + // Extract the pertinent lines + while (xLine != null) { + var xParts = xLine.Trim().Split(' '); + if (xParts.Length > 0 && xParts[0].EndsWith(":")) { + // Its a label, lets check it + if (xParts.Length == 1) { // Normal label + xCode.AppendLine(xLine); + } else if (xParts[1] == ";Asm") { // ASM label + xCode.AppendLine(xLine); + } else if (xParts[1] == ";IL" && aLabels.Contains(xParts[0])) { // Exact match to label in our list + xCode.AppendLine(xLine); + } else { + // Label with unrecognized comment, or IL label that doesn't match. + // We are done. + break; + } + } else { // Not a label, just output it + xCode.AppendLine(xLine); + } + xLine = xSR.ReadLine(); + } + } + return xCode; + } + } +} diff --git a/source2/Debug/Cosmos.Debug.VSDebugEngine/Cosmos.Debug.VSDebugEngine.csproj b/source2/Debug/Cosmos.Debug.VSDebugEngine/Cosmos.Debug.VSDebugEngine.csproj index 434687f38..36f01f852 100644 --- a/source2/Debug/Cosmos.Debug.VSDebugEngine/Cosmos.Debug.VSDebugEngine.csproj +++ b/source2/Debug/Cosmos.Debug.VSDebugEngine/Cosmos.Debug.VSDebugEngine.csproj @@ -119,6 +119,7 @@ +