Example #1
0
            //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
                                }
                            }
                        }
                    }
                }
            }
Example #2
0
            //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
                                }
                            }
                        }
                    }
                }
            }