public ObjectValue Run(string name, ObjectValueFlags flags, ObjectEvaluatorDelegate evaluator) { string id; int tid; lock (asyncCallbacks) { tid = asyncCounter++; id = tid.ToString(); } ObjectValue val = null; bool done = runner.Run(delegate { if (tid >= cancelTimestamp) { val = evaluator(); } }, delegate { if (tid >= cancelTimestamp) { OnEvaluationDone(id, val); } }); if (done) { // 'val' may be null if the timed evaluator is disposed while evaluating return(val ?? ObjectValue.CreateUnknown(name)); } return(ObjectValue.CreateEvaluating(this, new ObjectPath(id, name), flags)); }
public ObjectValue GetExpressionValue(EvaluationContext ctx, string exp) { try { ValueReference var = ctx.Evaluator.Evaluate(ctx, exp); if (var != null) { return(var.CreateObjectValue(ctx.Options)); } else { return(ObjectValue.CreateUnknown(exp)); } } catch (ImplicitEvaluationDisabledException) { return(ObjectValue.CreateImplicitNotSupported(ctx.ExpressionValueSource, new ObjectPath(exp), "", ObjectValueFlags.None)); } catch (NotSupportedExpressionException ex) { return(ObjectValue.CreateNotSupported(ctx.ExpressionValueSource, new ObjectPath(exp), ex.Message, "", ObjectValueFlags.None)); } catch (EvaluatorException ex) { return(ObjectValue.CreateError(ctx.ExpressionValueSource, new ObjectPath(exp), "", ex.Message, ObjectValueFlags.None)); } catch (Exception ex) { ctx.WriteDebuggerError(ex); return(ObjectValue.CreateUnknown(exp)); } }
private ObjectValue CreateVarObject(string exp) { try { session.SelectThread(threadId); exp = exp.Replace("\"", "\\\""); GdbCommandResult res = session.RunCommand("-var-create", "-", "*", "\"" + exp + "\""); if (res.Status == CommandStatus.Done) { string vname = res.GetValue("name"); var result = CreateObjectValue(exp, res); session.RegisterTempVariableObject(vname, result); return(result); } else { return(ObjectValue.CreateUnknown(exp)); } } catch { return(ObjectValue.CreateUnknown(exp)); } }
void OnEvaluationDone(string id, ObjectValue val) { if (val == null) { val = ObjectValue.CreateUnknown(null); } UpdateCallback cb = null; lock (asyncCallbacks) { if (asyncCallbacks.TryGetValue(id, out cb)) { try { cb.UpdateValue(val); } catch {} asyncCallbacks.Remove(id); } else { asyncResults [id] = val; } } }
ObjectValue GetStackTrace(EvaluationOptions options) { ValueReference st = exception.GetChild("StackTrace", options); if (st == null) { return(ObjectValue.CreateUnknown("StackTrace")); } string trace = st.ObjectValue as string; if (trace == null) { return(ObjectValue.CreateUnknown("StackTrace")); } List <ObjectValue> frames = new List <ObjectValue> (); foreach (string sframe in trace.Split('\n')) { string txt = sframe.Trim(' ', '\r', '\n'); string file = ""; int line = 0; int col = 0; ObjectValue fileVal = ObjectValue.CreatePrimitive(null, new ObjectPath("File"), "", new EvaluationResult(file), ObjectValueFlags.None); ObjectValue lineVal = ObjectValue.CreatePrimitive(null, new ObjectPath("Line"), "", new EvaluationResult(line.ToString()), ObjectValueFlags.None); ObjectValue colVal = ObjectValue.CreatePrimitive(null, new ObjectPath("Col"), "", new EvaluationResult(col.ToString()), ObjectValueFlags.None); ObjectValue[] children = new ObjectValue[] { fileVal, lineVal, colVal }; ObjectValue frame = ObjectValue.CreateObject(null, new ObjectPath(), "", new EvaluationResult(txt), ObjectValueFlags.None, children); frames.Add(frame); } return(ObjectValue.CreateArray(null, new ObjectPath("StackTrace"), "", frames.Count, ObjectValueFlags.None, frames.ToArray())); }
ObjectValue CreateVarObject(string exp) { try { session.SelectThread(threadId); foreach (var symbol in symbols) { if (symbol.Name.ToLower() == exp.ToLower()) { return(CreateObjectValue(symbol)); } } DebugScopedSymbol evaluatedSymbol = this.session.SymbolResolver.Evaluate(exp, threadId); if (evaluatedSymbol != null) { session.RegisterTempVariableObject(exp); return(CreateObjectValue(evaluatedSymbol)); } return(ObjectValue.CreateUnknown(exp)); } catch (Exception ex) { return(ObjectValue.CreateFatalError(exp, ex.Message, ObjectValueFlags.Error)); } }
public static ObjectValue GetStackTrace(string trace) { if (trace == null) { return(ObjectValue.CreateUnknown("StackTrace")); } var regex = new Regex("at (?<MethodName>.*) in (?<FileName>.*):(?<LineNumber>\\d+)(,(?<Column>\\d+))?"); var regexLine = new Regex("at (?<MethodName>.*) in (?<FileName>.*):line (?<LineNumber>\\d+)(,(?<Column>\\d+))?"); var frames = new List <ObjectValue> (); foreach (var sframe in trace.Split('\n')) { string text = sframe.Trim(' ', '\r', '\t', '"'); string file = ""; int column = 0; int line = 0; if (text.Length == 0) { continue; } //Ignore entries like "--- End of stack trace from previous location where exception was thrown ---" if (text.StartsWith("---", StringComparison.Ordinal)) { continue; } var match = regex.Match(text); if (match.Success) { text = match.Groups ["MethodName"].ToString(); file = match.Groups ["FileName"].ToString(); int.TryParse(match.Groups ["LineNumber"].ToString(), out line); int.TryParse(match.Groups ["Column"].ToString(), out column); } else { match = regexLine.Match(text); if (match.Success) { text = match.Groups ["MethodName"].ToString(); file = match.Groups ["FileName"].ToString(); int.TryParse(match.Groups ["LineNumber"].ToString(), out line); int.TryParse(match.Groups ["Column"].ToString(), out column); } } var fileVal = ObjectValue.CreatePrimitive(null, new ObjectPath("File"), "", new EvaluationResult(file), ObjectValueFlags.None); var lineVal = ObjectValue.CreatePrimitive(null, new ObjectPath("Line"), "", new EvaluationResult(line.ToString()), ObjectValueFlags.None); var colVal = ObjectValue.CreatePrimitive(null, new ObjectPath("Column"), "", new EvaluationResult(column.ToString()), ObjectValueFlags.None); var children = new ObjectValue [] { fileVal, lineVal, colVal }; var frame = ObjectValue.CreateObject(null, new ObjectPath(), "", new EvaluationResult(text), ObjectValueFlags.None, children); frames.Add(frame); } return(ObjectValue.CreateArray(null, new ObjectPath("StackTrace"), "", frames.Count, ObjectValueFlags.None, frames.ToArray())); }
public ObjectValue CreateElementValue(ArrayElementGroup grp, ObjectPath path, int[] indices) { if (array != null) { CorValRef elem = (CorValRef)GetElement(indices); return(ctx.Adapter.CreateObjectValue(ctx, grp, path, elem, ObjectValueFlags.ArrayElement)); } else { return(ObjectValue.CreateUnknown("?")); } }
ObjectValue CreateVarObject(string exp) { try { session.SelectThread(threadId); exp = exp.Replace("\"", "\\\""); GdbCommandResult res = session.RunCommand("-var-create", "-", "*", "\"" + exp + "\""); string vname = res.GetValue("name"); session.RegisterTempVariableObject(vname); return(CreateObjectValue(exp, res)); } catch { return(ObjectValue.CreateUnknown(exp)); } }
ObjectValue GetStackTrace(EvaluationOptions options) { var stackTrace = Exception.GetChild("StackTrace", options); if (stackTrace == null) { return(ObjectValue.CreateUnknown("StackTrace")); } string trace = stackTrace.ObjectValue as string; if (trace == null) { return(ObjectValue.CreateUnknown("StackTrace")); } var regex = new Regex("at (?<MethodName>.*) in (?<FileName>.*):(?<LineNumber>\\d+)(,(?<Column>\\d+))?"); var frames = new List <ObjectValue> (); foreach (var sframe in trace.Split('\n')) { string text = sframe.Trim(' ', '\r', '\t'); string file = ""; int column = 0; int line = 0; if (text.Length == 0) { continue; } var match = regex.Match(text); if (match.Success) { text = match.Groups["MethodName"].ToString(); file = match.Groups["FileName"].ToString(); int.TryParse(match.Groups["LineNumber"].ToString(), out line); int.TryParse(match.Groups["Column"].ToString(), out column); } var fileVal = ObjectValue.CreatePrimitive(null, new ObjectPath("File"), "", new EvaluationResult(file), ObjectValueFlags.None); var lineVal = ObjectValue.CreatePrimitive(null, new ObjectPath("Line"), "", new EvaluationResult(line.ToString()), ObjectValueFlags.None); var colVal = ObjectValue.CreatePrimitive(null, new ObjectPath("Column"), "", new EvaluationResult(column.ToString()), ObjectValueFlags.None); var children = new ObjectValue[] { fileVal, lineVal, colVal }; var frame = ObjectValue.CreateObject(null, new ObjectPath(), "", new EvaluationResult(text), ObjectValueFlags.None, children); frames.Add(frame); } return(ObjectValue.CreateArray(null, new ObjectPath("StackTrace"), "", frames.Count, ObjectValueFlags.None, frames.ToArray())); }
public ObjectValueNode[] EvaluateExpressions(IList <string> expressions) { var values = new ObjectValue[expressions.Count]; var unknown = new List <string> (); for (int i = 0; i < expressions.Count; i++) { if (!cachedValues.TryGetValue(expressions[i], out var value)) { unknown.Add(expressions[i]); } else { values[i] = value; } } ObjectValue[] qvalues; if (StackFrame != null) { using (var timer = StackFrame.DebuggerSession.WatchExpressionStats.StartTimer()) { qvalues = StackFrame.GetExpressionValues(unknown.ToArray(), true); timer.Success = true; } } else { qvalues = new ObjectValue[unknown.Count]; for (int i = 0; i < qvalues.Length; i++) { qvalues[i] = ObjectValue.CreateUnknown(unknown[i]); } } for (int i = 0, v = 0; i < values.Length; i++) { if (values[i] == null) { var value = qvalues[v++]; cachedValues[expressions[i]] = value; values[i] = value; } } return(values.Select(v => new DebuggerObjectValueNode(v)).ToArray()); }
public ObjectValue Run(string name, ObjectValueFlags flags, ObjectEvaluatorDelegate evaluator) { string id; int tid; lock (asyncCallbacks) { tid = asyncCounter++; id = tid.ToString(); } ObjectValue val = null; bool done = runner.Run(delegate { if (tid >= cancelTimestamp) { var session = Session; if (session == null || (flags == ObjectValueFlags.EvaluatingGroup)) { // Cannot report timing if session is null. If a group is being // evaluated then individual timings are not possible and must // be done elsewhere. val = evaluator(); } else { using (var timer = session.EvaluationStats.StartTimer(name)) { val = evaluator(); timer.Stop(val); } } } }, delegate { if (tid >= cancelTimestamp) { OnEvaluationDone(id, val); } }); if (done) { // 'val' may be null if the timed evaluator is disposed while evaluating return(val ?? ObjectValue.CreateUnknown(name)); } return(ObjectValue.CreateEvaluating(this, new ObjectPath(id, name), flags)); }
ObjectValue[] GetValues(string[] names) { ObjectValue[] values = new ObjectValue [names.Length]; List <string> list = new List <string> (); for (int n = 0; n < names.Length; n++) { ObjectValue val; if (cachedValues.TryGetValue(names [n], out val)) { values [n] = val; } else { list.Add(names[n]); } } ObjectValue[] qvalues; if (frame != null) { qvalues = frame.GetExpressionValues(list.ToArray(), true); } else { qvalues = new ObjectValue [list.Count]; for (int n = 0; n < qvalues.Length; n++) { qvalues [n] = ObjectValue.CreateUnknown(list [n]); } } int kv = 0; for (int n = 0; n < values.Length; n++) { if (values [n] == null) { values [n] = qvalues [kv++]; cachedValues [names[n]] = values [n]; } } return(values); }
public ObjectValueNode EvaluateExpression(string expression) { if (cachedValues.TryGetValue(expression, out var value)) { return(new DebuggerObjectValueNode(value)); } if (StackFrame != null) { value = StackFrame.GetExpressionValue(expression, true); } else { value = ObjectValue.CreateUnknown(expression); } cachedValues[expression] = value; return(new DebuggerObjectValueNode(value)); }
ObjectValue CreateVarObject(string exp) { try { session.SelectThread(threadId); DebugEngineWrapper.DebugSymbolData[] datasymbols = Engine.Symbols.GetSymbols(exp); for (uint i = 0; i < Engine.Symbols.ScopeLocalSymbols.Count; i++) { if (exp == Engine.Symbols.ScopeLocalSymbols.Symbols[i].Name) { session.RegisterTempVariableObject(exp); return(CreateObjectValue(exp, Engine.Symbols.ScopeLocalSymbols.Symbols[i])); } } return(ObjectValue.CreateUnknown(exp)); } catch { return(ObjectValue.CreateUnknown(exp)); } }
ObjectValue CreateVarObject(string exp) { try { session.SelectThread(threadId); //DebugEngineWrapper.DebugSymbolData[] datasymbols = Engine.Symbols.GetSymbols("*"); var rootSymbols = Array.FindAll <DEW.DebugScopedSymbol>(Engine.Symbols.ScopeLocalSymbols.Symbols, (a) => (a.Parent == null)); DEW.DebugScopedSymbol foundSymbol = FindScopedSymbol(exp, rootSymbols); if (foundSymbol != null) { session.RegisterTempVariableObject(exp); return(CreateObjectValue(exp, foundSymbol)); } return(ObjectValue.CreateUnknown(exp)); } catch { return(ObjectValue.CreateUnknown(exp)); } }
public ObjectValue CreateObjectValue(bool withTimeout, EvaluationOptions options) { options = options.Clone(); options.EllipsizeStrings = false; string type = ctx.Adapter.GetValueTypeName(ctx, Exception.ObjectValue); var excInstance = Exception.CreateObjectValue(withTimeout, options); excInstance.Name = "Instance"; ObjectValue messageValue = null; // Get the message if (withTimeout) { messageValue = ctx.Adapter.CreateObjectValueAsync("Message", ObjectValueFlags.None, delegate { var mref = Exception.GetChild("Message", options); if (mref != null) { string val = (string)mref.ObjectValue; return(ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal)); } return(ObjectValue.CreateUnknown("Message")); }); } else { var mref = Exception.GetChild("Message", options); if (mref != null) { string val = (string)mref.ObjectValue; messageValue = ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal); } } if (messageValue == null) { messageValue = ObjectValue.CreateUnknown("Message"); } messageValue.Name = "Message"; // Inner exception ObjectValue childExceptionValue = null; if (withTimeout) { childExceptionValue = ctx.Adapter.CreateObjectValueAsync("InnerException", ObjectValueFlags.None, delegate { var inner = Exception.GetChild("InnerException", options); if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value)) { //Console.WriteLine ("pp got child:" + type); var innerSource = new ExceptionInfoSource(ctx, inner); var res = innerSource.CreateObjectValue(false, options); return(res); } return(ObjectValue.CreateUnknown("InnerException")); }); } else { var inner = Exception.GetChild("InnerException", options); if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value)) { //Console.WriteLine ("pp got child:" + type); var innerSource = new ExceptionInfoSource(ctx, inner); childExceptionValue = innerSource.CreateObjectValue(false, options); childExceptionValue.Name = "InnerException"; } } if (childExceptionValue == null) { childExceptionValue = ObjectValue.CreateUnknown("InnerException"); } // Inner exceptions in case of AgregatedException ObjectValue childExceptionsValue = null; ObjectEvaluatorDelegate getInnerExceptionsDelegate = delegate { var inner = Exception.GetChild("InnerExceptions", options); if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value)) { var obj = inner.GetValue(ctx); var objType = ctx.Adapter.GetValueType(ctx, obj); var enumerator = ctx.Adapter.RuntimeInvoke(ctx, objType, obj, "GetEnumerator", new object[0], new object[0]); var enumeratorType = ctx.Adapter.GetImplementedInterfaces(ctx, ctx.Adapter.GetValueType(ctx, enumerator)).First(f => ctx.Adapter.GetTypeName(ctx, f) == "System.Collections.IEnumerator"); var childrenList = new List <ObjectValue> (); while ((bool)ctx.Adapter.TargetObjectToObject(ctx, ctx.Adapter.RuntimeInvoke(ctx, enumeratorType, enumerator, "MoveNext", new object[0], new object[0]))) { var valCurrent = ctx.Adapter.GetMember(ctx, null, enumeratorType, enumerator, "Current"); childrenList.Add(new ExceptionInfoSource(ctx, valCurrent).CreateObjectValue(withTimeout, ctx.Options)); } return(ObjectValue.CreateObject(null, new ObjectPath("InnerExceptions"), "", "", ObjectValueFlags.None, childrenList.ToArray())); } return(ObjectValue.CreateUnknown("InnerExceptions")); }; if (withTimeout) { childExceptionsValue = ctx.Adapter.CreateObjectValueAsync("InnerExceptions", ObjectValueFlags.None, getInnerExceptionsDelegate); } else { childExceptionsValue = getInnerExceptionsDelegate(); } if (childExceptionsValue == null) { childExceptionsValue = ObjectValue.CreateUnknown("InnerExceptions"); } // Stack trace ObjectValue stackTraceValue; if (withTimeout) { stackTraceValue = ctx.Adapter.CreateObjectValueAsync("StackTrace", ObjectValueFlags.None, delegate { return(GetStackTrace(options)); }); } else { stackTraceValue = GetStackTrace(options); } var children = new ObjectValue [] { excInstance, messageValue, stackTraceValue, childExceptionValue, childExceptionsValue }; return(ObjectValue.CreateObject(null, new ObjectPath("InnerException"), type, "", ObjectValueFlags.None, children)); }
public ObjectValue CreateObjectValue(bool withTimeout, EvaluationOptions options) { options = options.Clone(); options.EllipsizeStrings = false; options.AllowTargetInvoke = true; ctx = ctx.WithOptions(options); string type = ctx.Adapter.GetValueTypeName(ctx, Exception.ObjectValue); var excInstance = Exception.CreateObjectValue(withTimeout, options); excInstance.Name = "Instance"; ObjectValue messageValue = null; ObjectValue helpLinkValue = null; var exceptionType = ctx.Adapter.GetValueType(ctx, Exception.Value); // Get the message if (withTimeout) { messageValue = ctx.Adapter.CreateObjectValueAsync("Message", ObjectValueFlags.None, delegate { var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "Message"); if (mref != null) { string val = (string)mref.ObjectValue; return(ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal)); } return(ObjectValue.CreateUnknown("Message")); }); } else { var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "Message"); if (mref != null) { string val = (string)mref.ObjectValue; messageValue = ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal); } } if (messageValue == null) { messageValue = ObjectValue.CreateUnknown("Message"); } messageValue.Name = "Message"; // Get the help link if (withTimeout) { helpLinkValue = ctx.Adapter.CreateObjectValueAsync("HelpLink", ObjectValueFlags.None, delegate { var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "HelpLink"); if (mref != null) { string val = (string)mref.ObjectValue; return(ObjectValue.CreatePrimitive(null, new ObjectPath("HelpLink"), "string", new EvaluationResult(val), ObjectValueFlags.Literal)); } return(ObjectValue.CreateUnknown("HelpLink")); }); } else { var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "HelpLink"); if (mref != null) { string val = (string)mref.ObjectValue; helpLinkValue = ObjectValue.CreatePrimitive(null, new ObjectPath("HelpLink"), "string", new EvaluationResult(val), ObjectValueFlags.Literal); } } if (helpLinkValue == null) { helpLinkValue = ObjectValue.CreateUnknown("HelpLink"); } helpLinkValue.Name = "HelpLink"; // Inner exception ObjectValue childExceptionValue = null; if (withTimeout) { childExceptionValue = ctx.Adapter.CreateObjectValueAsync("InnerException", ObjectValueFlags.None, delegate { var inner = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "InnerException"); if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value)) { //Console.WriteLine ("pp got child:" + type); var innerSource = new ExceptionInfoSource(ctx, inner); var res = innerSource.CreateObjectValue(false, options); return(res); } return(ObjectValue.CreateUnknown("InnerException")); }); } else { var inner = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "InnerException"); if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value)) { //Console.WriteLine ("pp got child:" + type); var innerSource = new ExceptionInfoSource(ctx, inner); childExceptionValue = innerSource.CreateObjectValue(false, options); childExceptionValue.Name = "InnerException"; } } if (childExceptionValue == null) { childExceptionValue = ObjectValue.CreateUnknown("InnerException"); } // Inner exceptions in case of AgregatedException ObjectValue childExceptionsValue = null; ObjectEvaluatorDelegate getInnerExceptionsDelegate = delegate { var inner = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "InnerExceptions"); if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value)) { var obj = inner.GetValue(ctx); var objType = ctx.Adapter.GetValueType(ctx, obj); var count = (int)ctx.Adapter.GetMember(ctx, null, obj, "Count").ObjectValue; var childrenList = new List <ObjectValue>(); for (int i = 0; i < count; i++) { childrenList.Add(new ExceptionInfoSource(ctx, ctx.Adapter.GetIndexerReference(ctx, obj, objType, new object[] { ctx.Adapter.CreateValue(ctx, i) })).CreateObjectValue(withTimeout, ctx.Options)); } return(ObjectValue.CreateObject(null, new ObjectPath("InnerExceptions"), "", "", ObjectValueFlags.None, childrenList.ToArray())); } return(ObjectValue.CreateUnknown("InnerExceptions")); }; if (withTimeout) { childExceptionsValue = ctx.Adapter.CreateObjectValueAsync("InnerExceptions", ObjectValueFlags.None, getInnerExceptionsDelegate); } else { childExceptionsValue = getInnerExceptionsDelegate(); } if (childExceptionsValue == null) { childExceptionsValue = ObjectValue.CreateUnknown("InnerExceptions"); } // Stack trace ObjectValue stackTraceValue; if (withTimeout) { stackTraceValue = ctx.Adapter.CreateObjectValueAsync("StackTrace", ObjectValueFlags.None, delegate { var stackTrace = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "StackTrace"); if (stackTrace == null) { return(ObjectValue.CreateUnknown("StackTrace")); } return(GetStackTrace(stackTrace.ObjectValue as string)); }); } else { var stackTrace = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "StackTrace"); if (stackTrace == null) { return(ObjectValue.CreateUnknown("StackTrace")); } stackTraceValue = GetStackTrace(stackTrace.ObjectValue as string); } var children = new ObjectValue [] { excInstance, messageValue, helpLinkValue, stackTraceValue, childExceptionValue, childExceptionsValue }; return(ObjectValue.CreateObject(null, new ObjectPath("InnerException"), type, "", ObjectValueFlags.None, children)); }
public ObjectValue[] GetChildren(ObjectPath path, int firstItemIndex, int count, EvaluationOptions options) { EvaluationContext cctx = ctx.WithOptions(options); if (path.Length > 1) { // Looking for children of an array element int[] idx = StringToIndices(path [1]); object obj = array.GetElement(idx); return(cctx.Adapter.GetObjectValueChildren(cctx, new ArrayObjectSource(array, path[1]), obj, firstItemIndex, count)); } int lowerBound; int upperBound; bool isLastDimension; if (dimensions.Length > 1) { int rank = baseIndices.Length; lowerBound = array.GetLowerBounds() [rank]; upperBound = lowerBound + dimensions [rank] - 1; isLastDimension = rank == dimensions.Length - 1; } else { lowerBound = array.GetLowerBounds() [0]; upperBound = lowerBound + dimensions [0] - 1; isLastDimension = true; } int len; int initalIndex; if (!IsRange) { initalIndex = lowerBound; len = upperBound + 1 - lowerBound; } else { initalIndex = firstIndex; len = lastIndex - firstIndex + 1; } if (firstItemIndex == -1) { firstItemIndex = 0; count = len; } // Make sure the group doesn't have too many elements. If so, divide int div = 1; while (len / div > MaxChildCount) { div *= 10; } if (div == 1 && isLastDimension) { // Return array elements ObjectValue[] values = new ObjectValue [count]; ObjectPath newPath = new ObjectPath("this"); int[] curIndex = new int [baseIndices.Length + 1]; Array.Copy(baseIndices, curIndex, baseIndices.Length); string curIndexStr = IndicesToString(baseIndices); if (baseIndices.Length > 0) { curIndexStr += ","; } curIndex [curIndex.Length - 1] = initalIndex + firstItemIndex; var elems = array.GetElements(curIndex, System.Math.Min(values.Length, upperBound - lowerBound + 1)); for (int n = 0; n < values.Length; n++) { int index = n + initalIndex + firstItemIndex; string sidx = curIndexStr + index; ObjectValue val; string ename = "[" + sidx.Replace(",", ", ") + "]"; if (index > upperBound) { val = ObjectValue.CreateUnknown(sidx); } else { curIndex [curIndex.Length - 1] = index; val = cctx.Adapter.CreateObjectValue(cctx, this, newPath.Append(sidx), elems.GetValue(n), ObjectValueFlags.ArrayElement); if (elems.GetValue(n) != null && !cctx.Adapter.IsNull(cctx, elems.GetValue(n))) { TypeDisplayData tdata = cctx.Adapter.GetTypeDisplayData(cctx, cctx.Adapter.GetValueType(cctx, elems.GetValue(n))); if (!string.IsNullOrEmpty(tdata.NameDisplayString)) { try { ename = cctx.Adapter.EvaluateDisplayString(cctx, elems.GetValue(n), tdata.NameDisplayString); } catch (MissingMemberException) { // missing property or otherwise malformed DebuggerDisplay string } } } } val.Name = ename; values [n] = val; } return(values); } if (!isLastDimension && div == 1) { // Return an array element group for each index var list = new List <ObjectValue> (); for (int i = 0; i < count; i++) { int index = i + initalIndex + firstItemIndex; ObjectValue val; // This array must be created at every call to avoid sharing // changes with all array groups int[] curIndex = new int [baseIndices.Length + 1]; Array.Copy(baseIndices, curIndex, baseIndices.Length); curIndex [curIndex.Length - 1] = index; if (index > upperBound) { val = ObjectValue.CreateUnknown(""); } else { ArrayElementGroup grp = new ArrayElementGroup(cctx, array, curIndex); val = grp.CreateObjectValue(); } list.Add(val); } return(list.ToArray()); } else { // Too many elements. Split the array. // Don't make divisions of 10 elements, min is 100 if (div == 10) { div = 100; } // Create the child groups int i = initalIndex + firstItemIndex; len += i; var list = new List <ObjectValue> (); while (i < len) { int end = i + div - 1; if (end >= len) { end = len - 1; } ArrayElementGroup grp = new ArrayElementGroup(cctx, array, baseIndices, i, end); list.Add(grp.CreateObjectValue()); i += div; } return(list.ToArray()); } }
public ObjectValue CreateObjectValue(bool withTimeout, EvaluationOptions options) { string type = ctx.Adapter.GetTypeName(ctx, exception.Type); ObjectValue excInstance = exception.CreateObjectValue(withTimeout, options); excInstance.Name = "Instance"; ObjectValue messageValue = null; // Get the message if (withTimeout) { messageValue = ctx.Adapter.CreateObjectValueAsync("Message", ObjectValueFlags.None, delegate { ValueReference mref = exception.GetChild("Message", options); if (mref != null) { string val = (string)mref.ObjectValue; return(ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "System.String", new EvaluationResult(val), ObjectValueFlags.Literal)); } else { return(ObjectValue.CreateUnknown("Message")); } }); } else { ValueReference mref = exception.GetChild("Message", options); if (mref != null) { string val = (string)mref.ObjectValue; messageValue = ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "System.String", new EvaluationResult(val), ObjectValueFlags.Literal); } } if (messageValue == null) { messageValue = ObjectValue.CreateUnknown("Message"); } messageValue.Name = "Message"; // Inner exception ObjectValue childExceptionValue = null; if (withTimeout) { childExceptionValue = ctx.Adapter.CreateObjectValueAsync("InnerException", ObjectValueFlags.None, delegate { ValueReference inner = exception.GetChild("InnerException", options); if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value)) { Console.WriteLine("pp got child:" + type); ExceptionInfoSource innerSource = new ExceptionInfoSource(ctx, inner); ObjectValue res = innerSource.CreateObjectValue(false, options); return(res); } else { return(ObjectValue.CreateUnknown("InnerException")); } }); } else { ValueReference inner = exception.GetChild("InnerException", options); if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value)) { Console.WriteLine("pp got child:" + type); ExceptionInfoSource innerSource = new ExceptionInfoSource(ctx, inner); childExceptionValue = innerSource.CreateObjectValue(false, options); childExceptionValue.Name = "InnerException"; } } if (childExceptionValue == null) { childExceptionValue = ObjectValue.CreateUnknown("InnerException"); } // Stack trace ObjectValue stackTraceValue; if (withTimeout) { stackTraceValue = ctx.Adapter.CreateObjectValueAsync("StackTrace", ObjectValueFlags.None, delegate { return(GetStackTrace(options)); }); } else { stackTraceValue = GetStackTrace(options); } ObjectValue[] children = new ObjectValue [] { excInstance, messageValue, stackTraceValue, childExceptionValue }; return(ObjectValue.CreateObject(null, new ObjectPath("InnerException"), type, "", ObjectValueFlags.None, children)); }