Used for scoped stack frame switching. using (var switcher = new StackFrameSwitcher(stackFrame)) { // Invoke DbgEng.dll interface function } Use this class for accessing stack frame information from DbgEng.dll interfaces to insure correct stack frame information access. For performance reasons, after using scope, previous stack frame won't be set until it is needed. Always use this class to insure correctness.
Inheritance: IDisposable
        /// <summary>
        /// Gets the stack frame locals.
        /// </summary>
        /// <param name="stackFrame">The stack frame.</param>
        /// <param name="arguments">if set to <c>true</c> only arguments will be returned.</param>
        public VariableCollection GetFrameLocals(StackFrame stackFrame, bool arguments)
        {
            DebugScopeGroup scopeGroup = arguments ? DebugScopeGroup.Arguments : DebugScopeGroup.Locals;

            using (StackFrameSwitcher switcher = new StackFrameSwitcher(DbgEngDll.StateCache, stackFrame))
            {
                IDebugSymbolGroup2 symbolGroup;
                dbgEngDll.Symbols.GetScopeSymbolGroup2((uint)scopeGroup, null, out symbolGroup);
                uint localsCount = symbolGroup.GetNumberSymbols();
                Variable[] variables = new Variable[localsCount];
                for (uint i = 0; i < localsCount; i++)
                {
                    StringBuilder name = new StringBuilder(Constants.MaxSymbolName);
                    uint nameSize;

                    symbolGroup.GetSymbolName(i, name, (uint)name.Capacity, out nameSize);
                    var entry = symbolGroup.GetSymbolEntryInformation(i);
                    var module = stackFrame.Process.ModulesById[entry.ModuleBase];
                    var codeType = module.TypesById[entry.TypeId];
                    var address = entry.Offset;
                    var variableName = name.ToString();

                    variables[i] = Variable.CreateNoCast(codeType, address, variableName, variableName);
                }

                return new VariableCollection(variables);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the stack frame locals.
        /// </summary>
        /// <param name="stackFrame">The stack frame.</param>
        /// <param name="arguments">if set to <c>true</c> only arguments will be returned.</param>
        public VariableCollection GetFrameLocals(StackFrame stackFrame, bool arguments)
        {
            DebugScopeGroup scopeGroup = arguments ? DebugScopeGroup.Arguments : DebugScopeGroup.Locals;

            using (StackFrameSwitcher switcher = new StackFrameSwitcher(DbgEngDll.StateCache, stackFrame))
            {
                IDebugSymbolGroup2 symbolGroup;
                dbgEngDll.Symbols.GetScopeSymbolGroup2((uint)scopeGroup, null, out symbolGroup);
                uint       localsCount = symbolGroup.GetNumberSymbols();
                Variable[] variables   = new Variable[localsCount];
                for (uint i = 0; i < localsCount; i++)
                {
                    StringBuilder name = new StringBuilder(Constants.MaxSymbolName);
                    uint          nameSize;

                    symbolGroup.GetSymbolName(i, name, (uint)name.Capacity, out nameSize);
                    var entry        = symbolGroup.GetSymbolEntryInformation(i);
                    var module       = stackFrame.Process.ModulesById[entry.ModuleBase];
                    var codeType     = module.TypesById[entry.TypeId];
                    var address      = entry.Offset;
                    var variableName = name.ToString();

                    variables[i] = Variable.CreateNoCast(codeType, address, variableName, variableName);
                }

                return(new VariableCollection(variables));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the name of the function for the specified stack frame.
        /// </summary>
        /// <param name="stackFrame">The stack frame.</param>
        /// <param name="functionName">Name of the function.</param>
        /// <param name="displacement">The displacement.</param>
        public void GetStackFrameFunctionName(StackFrame stackFrame, out string functionName, out ulong displacement)
        {
            using (StackFrameSwitcher switcher = new StackFrameSwitcher(DbgEngDll.StateCache, stackFrame))
            {
                uint          functionNameSize;
                StringBuilder sb = new StringBuilder(Constants.MaxSymbolName);

                dbgEngDll.Symbols.GetNameByOffset(stackFrame.InstructionOffset, sb, (uint)sb.Capacity, out functionNameSize, out displacement);
                functionName = sb.ToString();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the source file name and line for the specified stack frame.
        /// </summary>
        /// <param name="stackFrame">The stack frame.</param>
        /// <param name="sourceFileName">Name of the source file.</param>
        /// <param name="sourceFileLine">The source file line.</param>
        /// <param name="displacement">The displacement.</param>
        public void GetStackFrameSourceFileNameAndLine(StackFrame stackFrame, out string sourceFileName, out uint sourceFileLine, out ulong displacement)
        {
            using (StackFrameSwitcher switcher = new StackFrameSwitcher(DbgEngDll.StateCache, stackFrame))
            {
                uint          fileNameLength;
                StringBuilder sb = new StringBuilder(Constants.MaxFileName);

                dbgEngDll.Symbols.GetLineByOffset(stackFrame.InstructionOffset, out sourceFileLine, sb, (uint)sb.Capacity, out fileNameLength, out displacement);
                sourceFileName = sb.ToString();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the stack frame locals.
        /// </summary>
        /// <param name="stackFrame">The stack frame.</param>
        /// <param name="relativeAddress">The relative address.</param>
        /// <param name="arguments">if set to <c>true</c> only arguments will be returned.</param>
        public VariableCollection GetFrameLocals(StackFrame stackFrame, uint relativeAddress, bool arguments)
        {
            DebugScopeGroup scopeGroup = arguments ? DebugScopeGroup.Arguments : DebugScopeGroup.Locals;

            using (StackFrameSwitcher switcher = new StackFrameSwitcher(DbgEngDll.StateCache, stackFrame))
            {
                IDebugSymbolGroup2 symbolGroup;
                DbgEngDll.Symbols.GetScopeSymbolGroup2((uint)scopeGroup, null, out symbolGroup);
                uint       localsCount = symbolGroup.GetNumberSymbols();
                Variable[] variables   = new Variable[localsCount];
                bool       doCleanup   = false;

                for (uint i = 0; i < localsCount; i++)
                {
                    try
                    {
                        StringBuilder name = new StringBuilder(Constants.MaxSymbolName);
                        uint          nameSize;

                        symbolGroup.GetSymbolName(i, name, (uint)name.Capacity, out nameSize);
                        var entry        = symbolGroup.GetSymbolEntryInformation(i);
                        var module       = stackFrame.Process.ModulesById[entry.ModuleBase];
                        var codeType     = module.TypesById[entry.TypeId];
                        var address      = entry.Offset;
                        var variableName = name.ToString();

                        variables[i] = Variable.CreateNoCast(codeType, address, variableName, variableName);
                    }
                    catch
                    {
                        // This variable is not available, don't store it in a collection
                        doCleanup = true;
                    }
                }
                if (doCleanup)
                {
                    variables = variables.Where(v => v != null).ToArray();
                }
                return(new VariableCollection(variables));
            }
        }
        /// <summary>
        /// Gets the stack frame locals.
        /// </summary>
        /// <param name="stackFrame">The stack frame.</param>
        /// <param name="relativeAddress">The relative address.</param>
        /// <param name="arguments">if set to <c>true</c> only arguments will be returned.</param>
        public VariableCollection GetFrameLocals(StackFrame stackFrame, uint relativeAddress, bool arguments)
        {
            DebugScopeGroup scopeGroup = arguments ? DebugScopeGroup.Arguments : DebugScopeGroup.Locals;

            using (StackFrameSwitcher switcher = new StackFrameSwitcher(DbgEngDll.StateCache, stackFrame))
            {
                IDebugSymbolGroup2 symbolGroup;
                DbgEngDll.Symbols.GetScopeSymbolGroup2((uint)scopeGroup, null, out symbolGroup);
                uint       localsCount = symbolGroup.GetNumberSymbols();
                Variable[] variables   = new Variable[localsCount];
                bool       doCleanup   = false;

                for (uint i = 0; i < localsCount; i++)
                {
                    try
                    {
                        StringBuilder name = new StringBuilder(Constants.MaxSymbolName);
                        uint          nameSize;

                        symbolGroup.GetSymbolName(i, name, (uint)name.Capacity, out nameSize);
                        var   entry = symbolGroup.GetSymbolEntryInformation(i);
                        var   module = stackFrame.Process.ModulesById[entry.ModuleBase];
                        var   codeType = module.TypesById[entry.TypeId];
                        var   address = entry.Offset;
                        var   variableName = name.ToString();
                        bool  hasData = false, pointerRead = false;
                        ulong data = 0;

                        if (address == 0 && entry.Size <= 8)
                        {
                            symbolGroup.GetSymbolValueText(i, name, (uint)name.Capacity, out nameSize);
                            string value = name.ToString();
                            if (value.StartsWith("0x"))
                            {
                                if (value.Length > 10 && value[10] == '`')
                                {
                                    value = value.Substring(0, 10) + value.Substring(11, 8);
                                }
                                value = value.Substring(2);
                                if (codeType.IsPointer)
                                {
                                    address     = ulong.Parse(value, System.Globalization.NumberStyles.HexNumber);
                                    pointerRead = true;
                                }
                                else
                                {
                                    hasData = true;
                                    data    = ulong.Parse(value, System.Globalization.NumberStyles.HexNumber);
                                }
                            }
                        }

                        if (pointerRead)
                        {
                            variables[i] = Variable.CreatePointerNoCast(codeType, address, variableName, variableName);
                        }
                        else
                        {
                            variables[i] = Variable.CreateNoCast(codeType, address, variableName, variableName);
                        }
                        if (hasData)
                        {
                            variables[i].Data = data;
                        }
                    }
                    catch
                    {
                        // This variable is not available, don't store it in a collection
                        doCleanup = true;
                    }
                }
                if (doCleanup)
                {
                    variables = variables.Where(v => v != null).ToArray();
                }
                return(new VariableCollection(variables));
            }
        }
        /// <summary>
        /// Gets the source file name and line for the specified stack frame.
        /// </summary>
        /// <param name="stackFrame">The stack frame.</param>
        /// <param name="sourceFileName">Name of the source file.</param>
        /// <param name="sourceFileLine">The source file line.</param>
        /// <param name="displacement">The displacement.</param>
        public void GetStackFrameSourceFileNameAndLine(StackFrame stackFrame, out string sourceFileName, out uint sourceFileLine, out ulong displacement)
        {
            using (StackFrameSwitcher switcher = new StackFrameSwitcher(DbgEngDll.StateCache, stackFrame))
            {
                uint fileNameLength;
                StringBuilder sb = new StringBuilder(Constants.MaxFileName);

                dbgEngDll.Symbols.GetLineByOffset(stackFrame.InstructionOffset, out sourceFileLine, sb, (uint)sb.Capacity, out fileNameLength, out displacement);
                sourceFileName = sb.ToString();
            }
        }
        /// <summary>
        /// Gets the name of the function for the specified stack frame.
        /// </summary>
        /// <param name="stackFrame">The stack frame.</param>
        /// <param name="functionName">Name of the function.</param>
        /// <param name="displacement">The displacement.</param>
        public void GetStackFrameFunctionName(StackFrame stackFrame, out string functionName, out ulong displacement)
        {
            using (StackFrameSwitcher switcher = new StackFrameSwitcher(DbgEngDll.StateCache, stackFrame))
            {
                uint functionNameSize;
                StringBuilder sb = new StringBuilder(Constants.MaxSymbolName);

                dbgEngDll.Symbols.GetNameByOffset(stackFrame.InstructionOffset, sb, (uint)sb.Capacity, out functionNameSize, out displacement);
                functionName = sb.ToString();
            }
        }