private SimpleOutputHandler(DebugUtilities executionUtilities, DebugUtilities passthroughUtilities, OUTPUT_FILTER outputFilter, bool passThrough, bool passThroughOnly) { ExecutionUtilities = executionUtilities; PassthroughUtilities = passthroughUtilities; passthroughUtilities.OutputMaskSave(); Installed = false; PreviousCallbacks = IntPtr.Zero; if (passThroughOnly == false) { DataBuffer = new DbgStringBuilder(executionUtilities, 1024); } LineBuffer = new DbgStringBuilder(executionUtilities, 1024); OutputFilter = outputFilter; PassThrough = passThrough; PassThroughOnly = passThroughOnly; executionUtilities.DebugClient.GetOutputCallbacksWide(out PreviousCallbacks); /* We will need to release this */ ThisIDebugOutputCallbacksPtr = Marshal.GetComInterfaceForObject(this, typeof(IDebugOutputCallbacksWide)); InstallationHRESULT = executionUtilities.DebugClient.SetOutputCallbacksWide(ThisIDebugOutputCallbacksPtr); if (SUCCEEDED(InstallationHRESULT)) { Installed = true; InstalledThreadId = Thread.CurrentThread.ManagedThreadId; BufferedOutput = new List <BufferLine>(1024); } else { Dispose(); } }
public CallbackData Copy(DebugUtilities d) { var sb = new DbgStringBuilder(d, Data.Length); sb.Append(Data); return(new CallbackData(Mask, sb, IsDML, DMLFlags)); }
public CallbackData(DEBUG_OUTPUT Mask, DbgStringBuilder Data, bool isDML = true, DEBUG_OUTCBF dmlFlags = 0) { this.Mask = Mask; this.Data = Data; IsDML = isDML; DMLFlags = dmlFlags; }
/// <summary> /// Gets a copy of all stored output if PassThroughOnly is not active. /// </summary> /// <returns>Any stored output.</returns> public string GetText() { lock (this) { if (PassThroughOnly) { return("PassThroughOnly specified. No local recording of data performed"); } var sb = new DbgStringBuilder(ExecutionUtilities, 2048); sb.Append(DataBuffer); foreach (var LineBuffer in LineBuffers) { if (LineBuffer.Value.Length != 0) { sb.Append(FilterLine(LineBuffer.Key, LineBuffer.Value.ToString(), PreviousTextWasDml, PreviousDmlFlags)); } } return(sb.ToString()); } }
public static DebugUtilities.DML ToDML(this DbgStringBuilder sb, string command, DebugUtilities.DML.Colors color) { return(new DebugUtilities.DML { Text = sb.ToString(), Command = command, Color = color }); }
/// <summary> /// Implements IDebugOutputCallbacks2::Output2 /// </summary> public int Output2(DEBUG_OUTCB Which, DEBUG_OUTCBF Flags, UInt64 Arg, string Text) { var mask = (DEBUG_OUTPUT)Arg; if (Which == DEBUG_OUTCB.EXPLICIT_FLUSH) { //Flush(); return(S_OK); } if (string.IsNullOrEmpty(Text)) { return(S_OK); } bool textIsDml = (Which == DEBUG_OUTCB.DML); if (OutputActive) { lock (this) { OutputActive = false; PreviousTextWasDml = textIsDml; PreviousDmlFlags = Flags; DbgStringBuilder LineBuffer; LineBuffers.TryGetValue(mask, out LineBuffer); int LineInputPos = 0; LineInputPositions.TryGetValue(mask, out LineInputPos); bool waitForClosingDML = false; if (LineBuffer == null) { LineBuffer = new DbgStringBuilder(ExecutionUtilities, 1024); LineBuffers[mask] = LineBuffer; } for (int i = 0; i < Text.Length; ++i) { char c = Text[i]; if (c == '<') { waitForClosingDML = true; } if (waitForClosingDML) { if (c == '>') { waitForClosingDML = false; } } if (c == '\n' && waitForClosingDML == false) { LineBuffer.AppendLine(); ProcessLine(mask, LineBuffer.ToString(), textIsDml, Flags); LineBuffer.Clear(); LineInputPos = 0; } else if (c == '\r') { LineInputPos = 0; } else { if (LineInputPos >= LineBuffer.Length) { LineBuffer.Append(c); } else { LineBuffer[LineInputPos] = c; } ++LineInputPos; } } LineInputPositions[mask] = LineInputPos; OutputActive = true; } } return(S_OK); }
/// <summary> /// Implements IDebugOutputCallbacks2::Output2 /// </summary> public int Output2(DEBUG_OUTCB Which, DEBUG_OUTCBF Flags, ulong Arg, string Text) { var mask = (DEBUG_OUTPUT)Arg; if (string.IsNullOrEmpty(Text)) { return(S_OK); } _executionUtilities.OutputMaskRestore(); var textIsDml = Which == DEBUG_OUTCB.DML; if (_outputActive) { lock (this) { _outputActive = false; var sb = new DbgStringBuilder(_passthroughUtilities, Text.Length); sb.Append(Text); var callbackData = new CallbackData(mask, sb, textIsDml, Flags); // The advanced filter gets 1st crack at the data before it goes to the line by line filter. callbackData = _outputFilter.AdvancedFilterText(callbackData); if (callbackData == null) { _outputActive = true; return(S_OK); } // It can force data to be output now, skipping the line-by-line filtering. if (callbackData.ForceOutputNow) { PassThroughLine(callbackData); _outputActive = true; return(S_OK); } Text = callbackData.Data.ToString(); // Was there a partial line for this mask? if so, lets finish it and send it to the filter! CallbackData lineBuffer; _lineBuffers.TryGetValue(callbackData.Mask, out lineBuffer); if (lineBuffer == null) { lineBuffer = new CallbackData(callbackData.Mask, new DbgStringBuilder(_passthroughUtilities, Text.Length), callbackData.IsDML, callbackData.DMLFlags); _lineBuffers[mask] = lineBuffer; } for (var i = 0; i < Text.Length; ++i) { var c = Text[i]; if (c == '\n') { lineBuffer.Data.Append(c); ProcessLine(lineBuffer.Copy(_passthroughUtilities)); lineBuffer.Clear(); } else if (c == '\r') { if ((i + 1) < Text.Length && Text[i + 1] != '\n') { lineBuffer.Clear(); } } else { lineBuffer.Data.Append(c); } } //if (Which == DEBUG_OUTCB.EXPLICIT_FLUSH) //{ // _passthroughUtilities.DebugClient.FlushCallbacks(); //} _outputActive = true; } } return(S_OK); }