Fix interpreter crash when debugger is not attached

This commit is contained in:
Yoshi Askharoun
2023-10-08 23:54:26 -05:00
parent a442d66213
commit be78b55a30
+21 -17
View File
@@ -72,26 +72,30 @@ namespace Microsoft.Iris.Markup
while (!errorsDetected) while (!errorsDetected)
{ {
OpCode opCode = (OpCode)reader.ReadByte(); OpCode opCode = (OpCode)reader.ReadByte();
InterpreterEntry entry = new(opCode, reader.CurrentOffset, loadResult.Uri); InterpreterEntry entry = new(new(opCode, reader.CurrentOffset, loadResult.Uri));
// Fetch line and column numbers from the table if (debugging)
if (debugging && context.LoadResult.LineNumberTable.TryLookup(reader.CurrentOffset, out int line, out int column))
{ {
bool ShouldBreak(Breakpoint b) // Fetch line and column numbers from the table
=> b.Enabled && b.Equals(loadResult.Uri, line, column, reader.CurrentOffset); if (context.LoadResult.LineNumberTable.TryLookup(reader.CurrentOffset, out int line, out int column))
// Check if a breakpoint has been set at this location
bool shouldBreakHere = Application.DebugSettings.Breakpoints.Any(ShouldBreak);
if (shouldBreakHere)
{ {
Application.Debugger.DebuggerCommand = InterpreterCommand.Break; bool ShouldBreak(Breakpoint b)
//System.Diagnostics.Debugger.Break(); => b.Enabled && b.Equals(loadResult.Uri, line, column, reader.CurrentOffset);
}
}
while (Application.Debugger.DebuggerCommand == InterpreterCommand.Break) ; // Check if a breakpoint has been set at this location
if (Application.Debugger.DebuggerCommand == InterpreterCommand.Step) bool shouldBreakHere = Application.DebugSettings.Breakpoints.Any(ShouldBreak);
Application.Debugger.DebuggerCommand = InterpreterCommand.Break; if (shouldBreakHere)
Application.Debugger.DebuggerCommand = InterpreterCommand.Break;
}
// Stop exeuction while the debugger is in break mode
while (Application.Debugger.DebuggerCommand == InterpreterCommand.Break) ;
// If the debugger requested a single step, immediately set the debugger
// to break again for the next instruction
if (Application.Debugger.DebuggerCommand == InterpreterCommand.Step)
Application.Debugger.DebuggerCommand = InterpreterCommand.Break;
}
switch (opCode) switch (opCode)
{ {
@@ -103,7 +107,7 @@ namespace Microsoft.Iris.Markup
typeSchema, InstructionObjectSource.TypeImports, typeIndex)); typeSchema, InstructionObjectSource.TypeImports, typeIndex));
object newObj = typeSchema.ConstructDefault(); object newObj = typeSchema.ConstructDefault();
ReportErrorOnNull(newObj, "Construction", typeSchema.Name); ReportErrorOnNull(newObj, "Construction", typeSchema.Name);
if (!ErrorsDetected(watermark, ref result, ref errorsDetected)) if (!ErrorsDetected(watermark, ref result, ref errorsDetected))
{ {