private XElement ComposeXmlMessage(TraceMessageSourceEntry message, TraceStreamOptions options) { XElement element = new XElement(XName.Get(Names.TraceEntry)); var symbolExpression = message.Expression; if (symbolExpression.IsValidValue) { var symbolElement = new XElement(XName.Get(Names.LocalVariableEntry)); symbolElement.SetAttributeValue(XName.Get(Names.LocalVariableEntryAttributeName), symbolExpression.Name); symbolElement.SetAttributeValue(XName.Get(Names.LocalVariableEntryAttributeValue), symbolExpression.Value); element.Add(symbolElement); } if (options.IncludeDateTime) { element.Add(new XElement(XName.Get(Names.TimeStamp)), DateTime.Now.ToString()); } if (options.IncludeColumnNumber) { var colNumber = new XElement(XName.Get(Names.FileColumn), message.Breakpoint.FileColumn); element.Add(colNumber); } if (options.IncludeFileName) { var fileName = new XElement(XName.Get(Names.FileName), message.Breakpoint.File); element.Add(fileName); } if (options.IncludeFunctionName) { var functionName = new XElement(XName.Get(Names.FunctionName), message.Breakpoint.FunctionName); element.Add(functionName); } if (options.IncludeLineNumber) { var lineNumber = new XElement(XName.Get(Names.FileLine), message.Breakpoint.FileLine); element.Add(lineNumber); } if (options.IncludeLocalVariables) { var localElement = new XElement(XName.Get(Names.Locals)); element.Add(localElement); foreach (Expression variable in message.StackFrame.Locals) { var localVariable = new XElement(XName.Get(Names.LocalVariableEntry)); localVariable.SetAttributeValue(XName.Get(Names.LocalVariableEntryAttributeName), variable.Name); localVariable.SetAttributeValue(XName.Get(Names.LocalVariableEntryAttributeValue), variable.Value); localElement.Add(localVariable); } } return(element); }
private IEnumerable <TraceMessageSourceEntry> GetAllMessagesFromQueue() { List <TraceMessageSourceEntry> messageList = new List <TraceMessageSourceEntry>(); TraceMessageSourceEntry message = null; lock (messages) { while (messages.Any()) { message = messages.Dequeue(); messageList.Add(message); } } return(messageList.AsEnumerable()); }
void DebuggerEvents_OnEnterBreakMode(EnvDTE.dbgEventReason Reason, ref EnvDTE.dbgExecutionAction ExecutionAction) { try { traceSessionInProgress = true; Debugger debugger; lock (dte) { //Don't lock too much, just what is required. debugger = dte.Debugger; } if (Reason == dbgEventReason.dbgEventReasonBreakpoint) { string[] symbols; lock (this.symbols) { //Clone the list to be used locally. symbols = new string[this.symbols.Count]; this.symbols.CopyTo(symbols); } foreach (var symbol in symbols) { if (!string.IsNullOrEmpty(symbol)) { try { var expression = debugger.GetExpression(symbol); if (expression.IsValidValue) { var breakpoint = debugger.BreakpointLastHit; var stackFrame = debugger.CurrentStackFrame; var traceMessageSource = new TraceMessageSourceEntry() { Expression = expression, Breakpoint = breakpoint, StackFrame = stackFrame }; lock (messages) { messages.Enqueue(traceMessageSource); } } else { string breakpointContext; var bp = dte.Debugger.BreakpointLastHit; breakpointContext = string.Format(Resources.MsgBreakpointContextFormat, expression.Name, bp.FunctionName, bp.FileLine); StatusReporter.Report(string.Format(Resources.ErrTraceSymbolInvalid, breakpointContext), Status.WARNING); } } catch (Exception ex) { StatusReporter.Report(string.Format(Resources.ErrorEvaulatingSymbol, symbol + ex.ToString()), Status.WARNING); } } } } } finally { //This step makes sure that the execution continues after tracing this value; ExecutionAction = dbgExecutionAction.dbgExecutionActionGo; } }
private XElement ComposeXmlMessage(TraceMessageSourceEntry message, TraceStreamOptions options) { XElement element = new XElement(XName.Get(Names.TraceEntry)); var symbolExpression = message.Expression; if (symbolExpression.IsValidValue) { var symbolElement = new XElement(XName.Get(Names.LocalVariableEntry)); symbolElement.SetAttributeValue(XName.Get(Names.LocalVariableEntryAttributeName), symbolExpression.Name); symbolElement.SetAttributeValue(XName.Get(Names.LocalVariableEntryAttributeValue), symbolExpression.Value); element.Add(symbolElement); } if (options.IncludeDateTime) { element.Add(new XElement(XName.Get(Names.TimeStamp)), DateTime.Now.ToString()); } if (options.IncludeColumnNumber) { var colNumber = new XElement(XName.Get(Names.FileColumn), message.Breakpoint.FileColumn); element.Add(colNumber); } if (options.IncludeFileName) { var fileName = new XElement(XName.Get(Names.FileName), message.Breakpoint.File); element.Add(fileName); } if (options.IncludeFunctionName) { var functionName = new XElement(XName.Get(Names.FunctionName), message.Breakpoint.FunctionName); element.Add(functionName); } if (options.IncludeLineNumber) { var lineNumber = new XElement(XName.Get(Names.FileLine), message.Breakpoint.FileLine); element.Add(lineNumber); } if (options.IncludeLocalVariables) { var localElement = new XElement(XName.Get(Names.Locals)); element.Add(localElement); foreach (Expression variable in message.StackFrame.Locals) { var localVariable = new XElement(XName.Get(Names.LocalVariableEntry)); localVariable.SetAttributeValue(XName.Get(Names.LocalVariableEntryAttributeName), variable.Name); localVariable.SetAttributeValue(XName.Get(Names.LocalVariableEntryAttributeValue), variable.Value); localElement.Add(localVariable); } } return element; }