Exemple #1
0
        public void Load(Stream memoryBytes)
        {
            Memory = new MachineMemory(memoryBytes);
            PC     = Memory.StartingProgramCounter;

            ObjectTable.Initialize();
            StackFrames.Initialize();
        }
Exemple #2
0
        string ConvertCallStackEntryToModule(AutomationElement selectedRow,
                                             AutomationElement callStackWindowView)
        {
            _taskContext.ThrowIfNotOnMainThread();

            string rowText = selectedRow.Current.Name;

            // Call stack window may display the module name in a format module_name!fun_info.
            if (rowText.Contains("!"))
            {
                string moduleName = rowText.Substring(0, rowText.IndexOf('!'));
                if (ModuleExists(moduleName))
                {
                    return(moduleName);
                }
            }

            // When the call stack window doesn't show the module name, we will try to match
            // the selected row index with the i-th frame returned by DTE service.
            AutomationElementCollection framesRows =
                GetAllDescendants(callStackWindowView, _treeGridItem);

            int selectedFrameIndex = 0;

            foreach (AutomationElement frameRow in framesRows)
            {
                selectedFrameIndex++;
                if (frameRow == selectedRow)
                {
                    break;
                }
            }

            // First index is 1 for frames.
            StackFrames frames = GetDte().Debugger.CurrentThread.StackFrames;

            if (selectedFrameIndex <= 0 || selectedFrameIndex > frames.Count)
            {
                throw new InvalidOperationException(
                          "Cannot match selected row with a stack frame from DTE.");
            }

            StackFrame frame = frames.Item(selectedFrameIndex);

            if (!rowText.Contains(frame.FunctionName))
            {
                throw new InvalidOperationException(
                          "The function name of the selected call stack frame doesn't match the " +
                          "entry in DTE.");
            }

            return(frame.Module);
        }
        private void SetStacktraceInformation(StackFrame[] frames, bool generatedByException = false)
        {
            if (frames == null)
            {
                return;
            }
            int startingIndex = 0;
            //get calling assembly information
            bool needCallingAssembly = CallingAssembly == null;
            //determine stack frames generated by Backtrace library
            //if we get stack frame from Backtrace we ignore them and reset stack frame stack
            var executedAssemblyName = Assembly.GetExecutingAssembly().GetName().Name;

            foreach (var frame in frames)
            {
                var backtraceFrame = new BacktraceStackFrame(frame, generatedByException, _reflectionMethodName);
                //ignore frames generated by Backtrace library
                string assemblyName = backtraceFrame?.Library ?? string.Empty;
                if (assemblyName.Equals(executedAssemblyName) || string.IsNullOrEmpty(assemblyName))
                {
                    continue;
                }
                if (needCallingAssembly && !SystemHelper.SystemAssembly(assemblyName))
                {
                    //we already found calling assembly
                    needCallingAssembly = false;
                    CallingAssembly     = backtraceFrame.FrameAssembly;
                }
                if (needCallingAssembly == true)
                {
                    continue;
                }
                StackFrames.Insert(startingIndex, backtraceFrame);
                startingIndex++;
            }
        }
Exemple #4
0
        void SynchronizeStackFrames()
        {
            var size = WamMachine.StackIndex + 1;

            // Remove obsolete entries from stack.
            //
            while (StackFrames.Count > size)
            {
                StackFrames.Pop();
            }

            // Purge stack frames that do not match their WAM machine counterparts.
            //
            for (var index = 0; index < Math.Min(size, StackFrames.Count); ++index)
            {
                if (StackFrames[index].InstructionStream.WamInstructionStream == WamMachine.GetInstructionPointer(index).InstructionStream)
                {
                    StackFrames[index].Synchronize();
                }
                else
                {
                    while (StackFrames.Count >= (index + 1))
                    {
                        StackFrames.Pop();
                    }
                    break;
                }
            }

            // Add new entries to stack.
            //
            while (StackFrames.Count < size)
            {
                StackFrames.Push().Synchronize();
            }
        }