private ObjectValueFlags CreateObjectValueFlags(DebugScopedSymbol symbol) { switch (symbol.TypeName.ToLower()) { case "bit": case "char": case "byte": case "ubyte": case "short": case "ushort": case "wchar": case "int": case "uint": case "long": case "ulong": case "float": case "double": case "real": case "ireal": case "creal": case "void*": return(ObjectValueFlags.Primitive); } return(ObjectValueFlags.Object); }
private ObjectValue CreateObjectValue(DebugScopedSymbol symbol) { ObjectValueFlags flags = CreateObjectValueFlags(symbol); ObjectValue val = ObjectValue.CreatePrimitive(this, new ObjectPath(symbol.FullName.Split(".".ToCharArray())), symbol.TypeName, new EvaluationResult(symbol.TextValue), flags); return(val); }
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 ObjectValue[] GetChildren(ObjectPath path, int index, int count, EvaluationOptions options) { List <ObjectValue> children = new List <ObjectValue>(); session.SelectThread(threadId); string expression = path.Join("."); if (expression.Trim().Length == 0) { return(children.ToArray()); } List <DebugScopedSymbol> childSymbols = this.session.SymbolResolver.GetChildSymbols(expression, threadId); if (childSymbols.Count == 0) { return(children.ToArray()); } for (int i = 0; i < childSymbols.Count; i++) { DebugScopedSymbol child = childSymbols[i]; ObjectValue ov = CreateObjectValue(child); children.Add(ov); } return(children.ToArray()); }
public DebugSymbolWrapper(DebugScopedSymbol Symbol) { this.Symbol = Symbol; }
//INode typeNode; //IEnumerable<IAbstractSyntaxTree> moduleCache; public DDebugSymbolWrapper(DebugScopedSymbol sym, DDebugSupport support) : base(sym) { this.supp = support; try { /*var ci=CoreManager.DebugManagement.Engine.Symbols.GetPointerTarget(sym.Offset); object mo = null; IntPtr moPtr = new IntPtr(); var raw = CoreManager.DebugManagement.Engine.Memory.ReadVirtual(ci, 4); Marshal.StructureToPtr(raw, moPtr, false); mo = Marshal.PtrToStructure(moPtr, typeof(DObject));*/ } catch { } // Search currently scoped module string file = ""; uint line = 0; CoreManager.DebugManagement.Engine.Symbols.GetLineByOffset(CoreManager.DebugManagement.Engine.CurrentInstructionOffset,out file,out line); codeLine = (int)line; if (string.IsNullOrWhiteSpace(file)) return; // If file name found, get syntax tree, as far as possible DProject ownerPrj=null; module = DLanguageBinding.GetFileSyntaxTree(file,out ownerPrj); // If syntax tree built, search the variable location if (module != null) { IStatement stmt = null; var block = DResolver.SearchBlockAt(module, new CodeLocation(0, codeLine),out stmt); var ctxt=ResolutionContext.Create(null, null, block); var res = TypeDeclarationResolver.ResolveIdentifier(Symbol.Name,ctxt, null); if (res!=null && res.Length > 0 && res[0] is DSymbol) { variableNode = ((DSymbol)res[0]).Definition; //moduleCache = DCodeCompletionSupport.Instance.EnumAvailableModules(ownerPrj); } } // Set type string _typeString= base.TypeString; if (variableNode != null) { var t = variableNode.Type; if (t != null) _typeString= t.ToString(); } // Set value string if (_typeString.StartsWith("class ")) { _valueString = base.ValueString; //CodeInjection.WriteObjectVariable(supp.hProcess, supp.varAddr, (uint)sym.Offset); //_valueString = CodeInjection.EvaluateObjectString(supp.hProcess, supp.toStringFunc, supp.varAddr, (uint)sym.Offset); /* var th = CodeInjection.BeginExecuteMethod(supp.hProcess, supp.toStringFunc); CoreManager.DebugManagement.Engine.Execute("~2 g"); CoreManager.DebugManagement.Engine.WaitForEvent(); CodeInjection.WaitForExecutionEnd(th); */ //_valueString = CodeInjection.ReadDString(supp.hProcess, supp.varAddr); } else { _valueString=base.ValueString; if (variableNode != null) { ITypeDeclaration curValueType = variableNode.Type; if (curValueType != null) { if (!IsBasicType(curValueType)) { if (TypeString == "string") //TODO: Replace this by searching the alias definition in the cache curValueType = new ArrayDecl() { InnerDeclaration = new DTokenDeclaration(DTokens.Char) }; else if (TypeString == "wstring") curValueType = new ArrayDecl() { InnerDeclaration = new DTokenDeclaration(DTokens.Wchar) }; else if (TypeString == "dstring") curValueType = new ArrayDecl() { InnerDeclaration = new DTokenDeclaration(DTokens.Dchar) }; if (IsArray(curValueType)) { var clampDecl = curValueType as ArrayDecl; var valueType = clampDecl.InnerDeclaration; if (valueType is DTokenDeclaration) { bool IsString = false; uint elsz = 0; var realType = DetermineArrayType((valueType as DTokenDeclaration).Token, out elsz, out IsString); var arr = CoreManager.DebugManagement.Engine.Symbols.ReadArray(sym.Offset, realType, elsz); if (arr != null) _valueString = BuildArrayContentString(arr, IsString); } } else { //TODO: call an object's toString method somehow to obtain its representing string manually } } } } } }
private ObjectValueFlags CreateObjectValueFlags(DebugScopedSymbol symbol) { switch (symbol.TypeName.ToLower()) { case "bit": case "char": case "byte": case "ubyte": case "short": case "ushort": case "wchar": case "int": case "uint": case "long": case "ulong": case "float": case "double": case "real": case "ireal": case "creal": case "void*": return ObjectValueFlags.Primitive; } return ObjectValueFlags.Object; }
private ObjectValue CreateObjectValue(DebugScopedSymbol symbol) { ObjectValueFlags flags = CreateObjectValueFlags(symbol); ObjectValue val = ObjectValue.CreatePrimitive(this, new ObjectPath(symbol.FullName.Split(".".ToCharArray())), symbol.TypeName, new EvaluationResult(symbol.TextValue), flags); return val; }
//INode typeNode; //IEnumerable<IAbstractSyntaxTree> moduleCache; public DDebugSymbolWrapper(DebugScopedSymbol sym, DDebugSupport support) : base(sym) { this.supp = support; try { /*var ci=CoreManager.DebugManagement.Engine.Symbols.GetPointerTarget(sym.Offset); * object mo = null; * IntPtr moPtr = new IntPtr(); * var raw = CoreManager.DebugManagement.Engine.Memory.ReadVirtual(ci, 4); * Marshal.StructureToPtr(raw, moPtr, false); * mo = Marshal.PtrToStructure(moPtr, typeof(DObject));*/ } catch { } // Search currently scoped module string file = ""; uint line = 0; CoreManager.DebugManagement.Engine.Symbols.GetLineByOffset(CoreManager.DebugManagement.Engine.CurrentInstructionOffset, out file, out line); codeLine = (int)line; if (string.IsNullOrWhiteSpace(file)) { return; } // If file name found, get syntax tree, as far as possible DProject ownerPrj = null; module = DLanguageBinding.GetFileSyntaxTree(file, out ownerPrj); // If syntax tree built, search the variable location if (module != null) { IStatement stmt = null; var block = DResolver.SearchBlockAt(module, new CodeLocation(0, codeLine), out stmt); var ctxt = ResolutionContext.Create(null, null, block); var res = TypeDeclarationResolver.ResolveIdentifier(Symbol.Name, ctxt, null); if (res != null && res.Length > 0 && res[0] is DSymbol) { variableNode = ((DSymbol)res[0]).Definition; //moduleCache = DCodeCompletionSupport.Instance.EnumAvailableModules(ownerPrj); } } // Set type string _typeString = base.TypeString; if (variableNode != null) { var t = variableNode.Type; if (t != null) { _typeString = t.ToString(); } } // Set value string if (_typeString.StartsWith("class ")) { _valueString = base.ValueString; //CodeInjection.WriteObjectVariable(supp.hProcess, supp.varAddr, (uint)sym.Offset); //_valueString = CodeInjection.EvaluateObjectString(supp.hProcess, supp.toStringFunc, supp.varAddr, (uint)sym.Offset); /* * var th = CodeInjection.BeginExecuteMethod(supp.hProcess, supp.toStringFunc); * * CoreManager.DebugManagement.Engine.Execute("~2 g"); * CoreManager.DebugManagement.Engine.WaitForEvent(); * * CodeInjection.WaitForExecutionEnd(th); */ //_valueString = CodeInjection.ReadDString(supp.hProcess, supp.varAddr); } else { _valueString = base.ValueString; if (variableNode != null) { ITypeDeclaration curValueType = variableNode.Type; if (curValueType != null) { if (!IsBasicType(curValueType)) { if (TypeString == "string") //TODO: Replace this by searching the alias definition in the cache { curValueType = new ArrayDecl() { InnerDeclaration = new DTokenDeclaration(DTokens.Char) } } ; else if (TypeString == "wstring") { curValueType = new ArrayDecl() { InnerDeclaration = new DTokenDeclaration(DTokens.Wchar) } } ; else if (TypeString == "dstring") { curValueType = new ArrayDecl() { InnerDeclaration = new DTokenDeclaration(DTokens.Dchar) } } ; if (IsArray(curValueType)) { var clampDecl = curValueType as ArrayDecl; var valueType = clampDecl.InnerDeclaration; if (valueType is DTokenDeclaration) { bool IsString = false; uint elsz = 0; var realType = DetermineArrayType((valueType as DTokenDeclaration).Token, out elsz, out IsString); var arr = CoreManager.DebugManagement.Engine.Symbols.ReadArray(sym.Offset, realType, elsz); if (arr != null) { _valueString = BuildArrayContentString(arr, IsString); } } } else { //TODO: call an object's toString method somehow to obtain its representing string manually } } } } } }