コード例 #1
0
ファイル: PrintException.cs プロジェクト: goldshtn/msos
        public void Execute(CommandExecutionContext context)
        {
            if (ExceptionAddress != 0)
            {
                var heap = context.Runtime.GetHeap();
                var type = heap.GetObjectType(ExceptionAddress);
                if (type == null || !type.IsException)
                {
                    context.WriteErrorLine("The specified address is not the address of an Exception-derived object.");
                    return;
                }

                DisplayException(heap.GetExceptionObject(ExceptionAddress), context);
            }
            else
            {
                var thread = context.CurrentThread;
                if (thread == null)
                {
                    context.WriteErrorLine("There is no current managed thread");
                    return;
                }
                if (thread.CurrentException == null)
                {
                    context.WriteLine("There is no current managed exception on this thread");
                    return;
                }
                DisplayException(thread.CurrentException, context);
            }
        }
コード例 #2
0
ファイル: DumpCollection.cs プロジェクト: goldshtn/msos
        public void Execute(CommandExecutionContext context)
        {
            if (!CommandHelpers.VerifyValidObjectAddress(context, ObjectAddress))
                return;

            var type = context.Heap.GetObjectType(ObjectAddress);
            var dynamicObj = context.Heap.GetDynamicObject(ObjectAddress);
            context.WriteLine("Type:   {0}", type.Name);
            if (type.IsArray || dynamicObj.IsList())
            {
                int length = dynamicObj.GetLength();
                context.WriteLine("Length: {0}", length);
                for (int i = 0; i < length; ++i)
                {
                    context.WriteLine("[{0}] {1}", i, dynamicObj[i]);
                }
            }
            else if (dynamicObj.IsDictionary())
            {
                context.WriteLine("Size:   {0}", dynamicObj.GetLength());
                context.WriteLine("{0,-40} {1,-40}", "Key", "Value");
                foreach (var kvp in dynamicObj.GetDictionaryItems())
                {
                    context.WriteLine("{0,-40} {1,-40}", kvp.Item1, kvp.Item2);
                }
            }
            else
            {
                context.WriteErrorLine("The specified object is not an array, list, or dictionary. " +
                    "These are the only collection types that are currently supported. For other " +
                    "collections, try using the !hq command to inspect the object's contents.");
                return;
            }
        }
コード例 #3
0
ファイル: DbgEngCommand.cs プロジェクト: Pavel-Durov/msos
        public void Execute(CommandExecutionContext context)
        {
            context.EnterDbgEngNativeMode();

            // In case the user is going to use sos/sosex, make sure they have
            // the appropriate DAC location configured.
            context.WriteLine("Loading DAC from " + context.DacLocation);
            context.NativeDbgEngTarget.ExecuteDbgEngCommand(
                ".cordll -ve -sd -lp " + Path.GetDirectoryName(context.DacLocation),
                context);

            // SOS hasn't necessarily been loaded at this point; try to load it
            // from the symbol server and then issue the appropriate .load command
            // so that the user can have it immediately available.
            string sosLocation = context.Runtime.TryDownloadSos();
            if (sosLocation == null)
            {
                context.WriteWarning(
                    "Unable to load SOS automatically from symbol server, " +
                    "try to find and .load it manually if needed.");
            }
            else
            {
                context.WriteLine("Loading SOS from " + sosLocation);
                context.NativeDbgEngTarget.ExecuteDbgEngCommand(
                    ".load " + sosLocation,
                    context);
            }
        }
コード例 #4
0
ファイル: GCRoot.cs プロジェクト: goldshtn/msos
        public void Execute(CommandExecutionContext context)
        {
            _context = context;

            if (!CommandHelpers.VerifyValidObjectAddress(context, ObjectAddress))
                return;

            _heap = context.Heap;
            if (!_heap.CanWalkHeap)
            {
                context.WriteErrorLine("The heap is not in a walkable state.");
                return;
            }

            var type = _heap.GetObjectType(ObjectAddress);

            _visitedObjects = new ObjectSet(_heap);
            _targets[ObjectAddress] = new Node(ObjectAddress, type);
            FillRootDictionary();

            foreach (var root in _roots)
            {
                if (_visitedRoots.Contains(root) || _visitedObjects.Contains(root.Object))
                    continue;

                Node path = TryFindPathToTarget(root);
                if (path != null)
                    PrintOnePath(path);
            }
        }
コード例 #5
0
ファイル: ObjSize.cs プロジェクト: goldshtn/msos
        public void Execute(CommandExecutionContext context)
        {
            if (!CommandHelpers.VerifyValidObjectAddress(context, ObjectAddress))
                return;

            IEnumerable<Tuple<ulong, ClrType>> subgraph;
            if (Flat)
            {
                subgraph = context.Heap.FlatSubgraphOf(ObjectAddress);
            }
            else
            {
                subgraph = context.Heap.SubgraphOf(ObjectAddress);
            }

            ulong count = 0, size = 0;
            foreach (var objAndType in subgraph)
            {
                ++count;
                size += objAndType.Item2.GetSize(objAndType.Item1);
            }

            context.WriteLine("{0:x16} graph size is {1} objects, {2} bytes ({3})",
                ObjectAddress, count, size, size.ToMemoryUnits());
        }
コード例 #6
0
ファイル: Paths.cs プロジェクト: goldshtn/msos
        public void Execute(CommandExecutionContext context)
        {
            if (!CommandHelpers.VerifyHasHeapIndex(context))
                return;

            if (!CommandHelpers.VerifyValidObjectAddress(context, ObjectAddress))
                return;

            int pathsDisplayed = 0;
            foreach (var path in context.HeapIndex.FindPaths(ObjectAddress, MaxResults, MaxLocalRoots, MaxDepth, RunInParallel))
            {
                context.WriteLine("{0:x16} -> {1:x16} {2}", path.Root.Address, path.Root.Object, path.Root.DisplayText);
                foreach (var obj in path.Chain)
                {
                    string objHex = String.Format("{0:x16}", obj);
                    context.Write("        -> ");
                    context.WriteLink(objHex, "!do " + objHex);
                    context.WriteLine(" {0}", context.Heap.GetObjectType(obj).Name);
                }
                context.WriteLine();
                ++pathsDisplayed;
            }
            context.WriteLine("Total paths displayed: {0}", pathsDisplayed);
            if (pathsDisplayed == 0)
            {
                context.WriteLine("Number of paths may be affected by maximum depth setting. " +
                    "If you are not seeing enough results, consider increasing --maxDepth.");
            }
        }
コード例 #7
0
ファイル: HeapIndex.cs プロジェクト: goldshtn/msos
        public void Execute(CommandExecutionContext context)
        {
            if (!InMemoryOnly)
            {
                if (context.TargetType == TargetType.LiveProcess)
                {
                    context.WriteErrorLine(
                        "Generating a persistent heap index for a live process is not recommended. " +
                        "Use the --nofile switch to generate an in-memory index instead.");
                    return;
                }
                if (String.IsNullOrEmpty(HeapIndexFileName))
                {
                    HeapIndexFileName = Path.ChangeExtension(context.DumpFile, ".heapindex");
                    context.WriteLine("Using an automatically generated heap index filename: '{0}'", HeapIndexFileName);
                }
            }

            if (InMemoryOnly && !String.IsNullOrEmpty(HeapIndexFileName))
            {
                context.WriteErrorLine("The --nofile and -f options are incompatible.");
                return;
            }

            // If the index fails to build, clear it so that other commands know we don't have an index.
            context.HeapIndex = new HeapIndex(context);
            if (!context.HeapIndex.Build(ChunkSize, InMemoryOnly ? null : HeapIndexFileName, !EnumerateRootsFast))
                context.HeapIndex = null;
        }
コード例 #8
0
ファイル: DumpArray.cs プロジェクト: Pavel-Durov/msos
        public void Execute(CommandExecutionContext context)
        {
            if (!CommandHelpers.VerifyValidObjectAddress(context, ObjectAddress))
                return;

            var type = context.Heap.GetObjectType(ObjectAddress);
            if (!type.IsArray)
            {
                context.WriteError("The object at the specified address is not an array.");
                return;
            }

            var size = type.GetSize(ObjectAddress);
            var length = type.GetArrayLength(ObjectAddress);
            context.WriteLine("Name:  {0}", type.Name);
            context.WriteLine("Size:  {0}(0x{1:x}) bytes", size, size);
            context.WriteLine("Array: Number of elements {0}, Type {1} {2}",
                length, type.ComponentType.Name,
                type.ComponentType.IsValueClass ? "(value type)" : "(reference type)");

            for (int i = 0; i < length; ++i)
            {
                context.Write("[{0}] ", i);

                object value;
                if (type.ComponentType.IsValueClass)
                {
                    value = type.GetArrayElementAddress(ObjectAddress, i);
                    if (value != null)
                    {
                        context.WriteLink(
                            String.Format("{0:x16}", value),
                            String.Format("!do {0:x16} --type {1}", value, type.ComponentType.Name)
                            );
                    }
                    else
                    {
                        context.Write("<null>");
                    }
                }
                else
                {
                    value = type.GetArrayElementValue(ObjectAddress, i);
                    ulong elementAddr = type.GetArrayElementAddress(ObjectAddress, i);
                    ulong elementRef;
                    if (context.Runtime.ReadPointer(elementAddr, out elementRef))
                    {
                        context.WriteLink(
                            String.Format("{0:x16}", value ?? "<null>"),
                            String.Format("!do {0:x16}", elementRef)
                            ); 
                    }
                    else
                    {
                        context.Write("{0:x16}", value ?? "<null>");
                    }
                }
                context.WriteLine();
            }
        }
コード例 #9
0
ファイル: DataTargetExtensions.cs プロジェクト: goldshtn/msos
 public static void ExecuteDbgEngCommand(this DataTarget target, string command, CommandExecutionContext context)
 {
     IDebugControl6 control = (IDebugControl6)target.DebuggerInterface;
     int hr = control.ExecuteWide(
         DEBUG_OUTCTL.THIS_CLIENT, command, DEBUG_EXECUTE.DEFAULT);
     if (HR.Failed(hr))
         context.WriteErrorLine("Command execution failed with hr = {0:x8}", hr);
 }
コード例 #10
0
ファイル: Alias.cs プロジェクト: Pavel-Durov/msos
 public void Execute(CommandExecutionContext context)
 {
     if (!context.Aliases.Remove(AliasName))
     {
         context.WriteError("Unknown alias '{0}'", AliasName);
         return;
     }
 }
コード例 #11
0
ファイル: Decompile.cs プロジェクト: goldshtn/msos
        public void Execute(CommandExecutionContext context)
        {
            _context = context;
            _output = new PlainTextOutput();

            if (!String.IsNullOrEmpty(AssemblyName))
            {
                ClrModule module = context.Runtime.Modules.SingleOrDefault(
                    m => Path.GetFileNameWithoutExtension(m.FileName).Equals(
                        Path.GetFileNameWithoutExtension(AssemblyName),
                        StringComparison.InvariantCultureIgnoreCase
                        )
                    );
                if (module == null)
                {
                    context.WriteErrorLine("Could not find the assembly '{0}'.", AssemblyName);
                    return;
                }
                if (!String.IsNullOrEmpty(TypeName))
                {
                    DecompileTypeFromModule(TypeName, module.FileName);
                }
                else
                {
                    DecompileModule(module);
                }
            }
            else if (!String.IsNullOrEmpty(TypeName))
            {
                ClrType type = context.Heap.GetTypeByName(TypeName);
                if (type == null)
                {
                    context.WriteErrorLine(
                        "Could not find the type '{0}' on the heap. Try specifying the assembly name.",
                        TypeName);
                    return;
                }
                if (!String.IsNullOrEmpty(MethodName))
                {
                    var methods = type.Methods.Where(m => m.Name == MethodName).ToArray();
                    if (methods.Length == 0)
                    {
                        context.WriteErrorLine("Could not find the method '{0}'.", MethodName);
                        return;
                    }
                    DecompileMethods(methods);
                }
                else
                {
                    DecompileType(type);
                }
            }
            else
            {
                context.WriteErrorLine("At least one of --assembly or --type must be specified.");
            }
        }
コード例 #12
0
ファイル: Alias.cs プロジェクト: goldshtn/msos
 public void Execute(CommandExecutionContext context)
 {
     if (context.Aliases.ContainsKey(AliasName))
     {
         context.WriteErrorLine("The specified alias already exists. Clear it first with .rmalias.");
         return;
     }
     context.Aliases.Add(AliasName, AliasCommand);
 }
コード例 #13
0
ファイル: Dump.cs プロジェクト: goldshtn/msos
 public void Execute(CommandExecutionContext context)
 {
     var writer = new DumpWriter.DumpWriter(
         Verbose ? new PrinterTextWriter(context.Printer) : null
         );
     // TODO Try to make the string shared between here and the DumpNative class in CLRMD
     writer.Dump(context.ProcessId, DumpType, FileName, "DumpWriter dump: has heap");
     context.WriteLine("Resulting dump size: {0:N0} bytes", new FileInfo(FileName).Length);
 }
コード例 #14
0
ファイル: CommandHelpers.cs プロジェクト: goldshtn/msos
 public static bool VerifyHasHeapIndex(CommandExecutionContext context)
 {
     if (context.HeapIndex == null)
     {
         context.WriteErrorLine("This command requires a heap index. Build one with !bhi or load one with !lhi.");
         return false;
     }
     return true;
 }
コード例 #15
0
ファイル: AnalysisTarget.cs プロジェクト: Pavel-Durov/msos
        public AnalysisTarget(int pid, CommandExecutionContext context, int clrVersionIndex = 0)
        {
            _context = context;
            _clrVersionIndex = clrVersionIndex;

            _processId = pid;
            AttachToProcess();

            SharedInit();
        }
コード例 #16
0
ファイル: ThreadPool.cs プロジェクト: goldshtn/msos
 public void Execute(CommandExecutionContext context)
 {
     var threadPool = context.Runtime.GetThreadPool();
     context.WriteLine("Total threads:   {0}", threadPool.TotalThreads);
     context.WriteLine("Running threads: {0}", threadPool.RunningThreads);
     context.WriteLine("Idle threads:    {0}", threadPool.IdleThreads);
     context.WriteLine("Max threads:     {0}", threadPool.MaxThreads);
     context.WriteLine("Min threads:     {0}", threadPool.MinThreads);
     context.WriteLine("CPU utilization: {0}% (estimated)", threadPool.CpuUtilization);
 }
コード例 #17
0
ファイル: Triage.cs プロジェクト: Pavel-Durov/msos
 public TriageInformation GetTriageInformation(CommandExecutionContext context)
 {
     using (_dbgEngTarget = context.CreateTemporaryDbgEngTarget())
     {
         FillModuleInformation();
         FillMemoryUsageInformation(context);
         FillFaultingThreadAndModuleInformation(context);
     }
     return _triageInformation;
 }
コード例 #18
0
ファイル: AnalysisTarget.cs プロジェクト: Pavel-Durov/msos
        public AnalysisTarget(string dumpFile, CommandExecutionContext context, int clrVersionIndex = 0)
        {
            _context = context;
            _clrVersionIndex = clrVersionIndex;

            _dumpFile = dumpFile;
            OpenDumpFile();
            
            SharedInit();
        }
コード例 #19
0
ファイル: SwitchThread.cs プロジェクト: Pavel-Durov/msos
 public void Execute(CommandExecutionContext context)
 {
     if (context.Runtime.Threads.Any(t => t.ManagedThreadId == ManagedThreadId))
     {
         context.CurrentManagedThreadId = ManagedThreadId;
     }
     else
     {
         context.WriteError("No thread has the managed thread id {0}", ManagedThreadId);
     }
 }
コード例 #20
0
ファイル: Alias.cs プロジェクト: Pavel-Durov/msos
 public void Execute(CommandExecutionContext context)
 {
     if (TemporaryOnly)
     {
         context.RemoveTemporaryAliases();
     }
     else
     {
         context.Aliases.Clear();
     }
 }
コード例 #21
0
ファイル: Define.cs プロジェクト: goldshtn/msos
 public void Execute(CommandExecutionContext context)
 {
     if (HelperIndex < 0 || HelperIndex >= context.Defines.Count)
     {
         context.WriteErrorLine(
             "There is no helper method at index {0} defined. Use .listdefines to get the indexes.",
             HelperIndex);
         return;
     }
     context.Defines.RemoveAt(HelperIndex);
 }
コード例 #22
0
ファイル: SessionSettings.cs プロジェクト: goldshtn/msos
 public void Execute(CommandExecutionContext context)
 {
     if (Enable)
     {
         context.HyperlinkOutput = true;
     }
     if (Disable)
     {
         context.HyperlinkOutput = false;
     }
 }
コード例 #23
0
ファイル: Quit.cs プロジェクト: goldshtn/msos
 public void Execute(CommandExecutionContext context)
 {
     if (context.IsInDbgEngNativeMode)
     {
         context.ExitDbgEngNativeMode();
         context.WriteLine("Exited DbgEng mode; you are now back in msos.");
     }
     else
     {
         context.ShouldQuit = true;
     }
 }
コード例 #24
0
ファイル: Define.cs プロジェクト: goldshtn/msos
 public void Execute(CommandExecutionContext context)
 {
     if (context.Defines.Count == 0)
     {
         context.WriteLine("You do not have any helper methods defined. Use .define to define some.");
         return;
     }
     context.WriteLine("{0,-6} {1}", "#", "Body");
     for (int i = 0; i < context.Defines.Count; ++i)
     {
         context.WriteLine("{0,-6} {1}", i, context.Defines[i]);
     }
 }
コード例 #25
0
ファイル: CLRStack.cs プロジェクト: goldshtn/msos
        public void Execute(CommandExecutionContext context)
        {
            _context = context;

            var thread = context.CurrentThread;
            if (thread == null)
            {
                context.WriteErrorLine("There is no current managed thread");
                return;
            }

            thread.WriteCurrentStackTraceToContext(context, DisplayArgumentsAndLocals);
        }
コード例 #26
0
ファイル: DbgEngCommand.cs プロジェクト: Pavel-Durov/msos
 public void Execute(CommandExecutionContext context)
 {
     if (context.IsInDbgEngNativeMode)
     {
         context.NativeDbgEngTarget.ExecuteDbgEngCommand(Command, context);
     }
     else
     {
         using (var target = context.CreateTemporaryDbgEngTarget())
         {
             target.ExecuteDbgEngCommand(Command, context);
         }
     }
 }
コード例 #27
0
ファイル: Alias.cs プロジェクト: goldshtn/msos
 public void Execute(CommandExecutionContext context)
 {
     string aliasCommand;
     if (!context.Aliases.TryGetValue(AliasName, out aliasCommand))
     {
         context.WriteErrorLine("Unknown alias '{0}'", AliasName);
         return;
     }
     int index = 1;
     foreach (var paramValue in AliasParameters.Split(' '))
     {
         aliasCommand = aliasCommand.Replace("$" + index, paramValue);
     }
     context.WriteInfoLine("Alias '{0}' expanded to '{1}'", AliasName, aliasCommand);
     context.ExecuteCommand(aliasCommand);
 }
コード例 #28
0
ファイル: SessionSettings.cs プロジェクト: goldshtn/msos
        public void Execute(CommandExecutionContext context)
        {
            if (Disable)
            {
                context.Printer.RowsPerPage = 0;
                return;
            }

            if (RowsPerPage == 0)
            {
                context.WriteErrorLine("Can't have 0 rows per page. Use --disable to disable paging altogether.");
                return;
            }

            context.Printer.RowsPerPage = RowsPerPage;
        }
コード例 #29
0
ファイル: DumpStackObjects.cs プロジェクト: goldshtn/msos
        public void Execute(CommandExecutionContext context)
        {
            context.WriteLine("{0,-20} {1,-20} {2}", "Address", "Object", "Type");
            foreach (var localRoot in context.CurrentThread.EnumerateStackObjects())
            {
                var type = context.Heap.GetObjectType(localRoot.Object);

                context.Write("{0,-20:x16} {1,-20:x16} {2} ", localRoot.Address, localRoot.Object,
                    type == null ? "" : type.Name);
                if (type != null && !type.IsFree)
                {
                    context.WriteLink("", String.Format("!do {0:x16}", localRoot.Object));
                }
                context.WriteLine();
            }
        }
コード例 #30
0
ファイル: MixedStack.cs プロジェクト: goldshtn/msos
        public void Execute(CommandExecutionContext context)
        {
            if (OSThreadId == 0)
            {
                OSThreadId = context.CurrentThread.OSThreadId;
            }

            context.WriteLine("{0,-10} {1,-20} {2}", "Type", "IP", "Function");
            using (var target = context.CreateTemporaryDbgEngTarget())
            {
                var stackTracer = new UnifiedStackTraces(target.DebuggerInterface, context);
                stackTracer.PrintStackTrace(context, (from thr in stackTracer.Threads
                                                      where thr.OSThreadId == OSThreadId
                                                      select thr.Index).Single());
            }
        }
コード例 #31
0
        public void Execute(CommandExecutionContext context)
        {
            if (!String.IsNullOrEmpty(TypeRegex))
            {
                try
                {
                    new Regex(TypeRegex);
                }
                catch (ArgumentException)
                {
                    context.WriteError("The regular expression specified for --type is not valid; did you forget to escape regex characters?");
                    return;
                }
            }

            _heap = context.Runtime.GetHeap();
            if (!_heap.CanWalkHeap)
            {
                context.WriteError("The heap is not in a walkable state.");
                return;
            }

            var  typeInfos        = new Dictionary <ulong, TypeInfo>(); // MT to TypeInfo
            long totalObjectCount = 0;

            if (!StatisticsOnly)
            {
                context.WriteLine("{0,-20} {1,-20} {2}", "MT", "Address", "Size");
            }
            foreach (var obj in _heap.EnumerateObjects())
            {
                ulong mt = 0;
                context.Runtime.ReadPointer(obj, out mt);

                if (!FilterObject(obj, mt))
                {
                    continue;
                }

                var type = _heap.GetObjectType(obj);
                if (type == null || String.IsNullOrEmpty(type.Name))
                {
                    continue;
                }

                var size = type.GetSize(obj);

                if (!StatisticsOnly)
                {
                    context.WriteLine("{0,-20:x16} {1,-20:x16} {2,-10}", mt, obj, size);
                }
                if (typeInfos.ContainsKey(mt))
                {
                    var current = typeInfos[mt];
                    current.Count += 1;
                    current.Size  += size;
                    typeInfos[mt]  = current;
                }
                else
                {
                    var objType     = _heap.GetObjectType(obj);
                    var objTypeName = objType != null ? objType.Name : "<no name>";
                    typeInfos.Add(mt, new TypeInfo {
                        Size = size, Count = 1, TypeName = objTypeName
                    });
                }
                ++totalObjectCount;
            }

            context.WriteLine("Statistics:");
            context.WriteLine("{0,-20} {1,-10} {2,-10} {3}", "MT", "Count", "TotalSize", "Class Name");
            foreach (var kvp in (from e in typeInfos orderby e.Value.Size ascending select e))
            {
                context.WriteLine("{0,-20:x16} {1,-10} {2,-10} {3}",
                                  kvp.Key, kvp.Value.Count, kvp.Value.Size, kvp.Value.TypeName);
            }
            context.WriteLine("Total {0} objects", totalObjectCount);
        }
コード例 #32
0
ファイル: FReachableQueue.cs プロジェクト: tiandian/msos
        public void Execute(CommandExecutionContext context)
        {
            var   heap = context.Runtime.GetHeap();
            var   readyForFinalization = context.Runtime.EnumerateFinalizerQueueObjectAddresses().ToList();
            ulong totalCount           = 0;

            if (StatisticsOnly)
            {
                context.WriteLine("{0,-10} {1,-10} {2}", "Count", "Size", "Class Name");
                var query = from obj in readyForFinalization
                            let type = heap.GetObjectType(obj)
                                       where type != null && !String.IsNullOrEmpty(type.Name)
                                       let size = (long)type.GetSize(obj)
                                                  group size by type.Name into g
                                                  let totalSize                         = g.Sum()
                                                                              let count = g.Count()
                                                                                          orderby totalSize descending
                                                                                          select new { Count = count, Size = totalSize, ClassName = g.Key };
                foreach (var row in query)
                {
                    context.WriteLine("{0,-10} {1,-10} {2}", row.Count, row.Size, row.ClassName);
                    totalCount += (ulong)row.Count;
                }
            }
            else
            {
                context.WriteLine("{0,-20} {1,-10} {2}", "Address", "Size", "Class Name");
                foreach (var objPtr in readyForFinalization)
                {
                    var type = heap.GetObjectType(objPtr);
                    if (type == null || String.IsNullOrEmpty(type.Name))
                    {
                        return;
                    }

                    context.WriteLink(
                        String.Format("{0,-20:x16} {1,-10} {2}", objPtr, type.GetSize(objPtr), type.Name),
                        String.Format("!do {0:x16}", objPtr)
                        );
                    context.WriteLine();
                    ++totalCount;
                }
            }
            context.WriteLine("# of objects ready for finalization: {0}", totalCount);
            context.WriteLine("Memory reachable from these objects: {0}",
                              heap.SizeReachableFromObjectSet(readyForFinalization).ToMemoryUnits());

            var finalizerThread = context.Runtime.Threads.SingleOrDefault(t => t.IsFinalizer);

            if (finalizerThread != null && finalizerThread.BlockingObjects.Count > 0)
            {
                context.WriteLine();
                context.WriteLine("The finalizer thread is blocked! Blocking objects:");
                foreach (var blockingObject in finalizerThread.BlockingObjects)
                {
                    context.Write("\t{0} ", blockingObject.Reason);
                    string objHex = String.Format("{0:x16}", blockingObject.Object);
                    context.WriteLink(objHex, "!do " + objHex);
                    context.WriteLine();
                }
                context.WriteLine("Blocked at:");
                foreach (var frame in finalizerThread.StackTrace.Take(3))
                {
                    context.WriteLine("\t" + frame.DisplayString);
                }
                context.WriteLink(
                    "\t... view full stack",
                    String.Format("~ {0}; !clrstack", finalizerThread.ManagedThreadId));
                context.WriteLine();
            }
        }
コード例 #33
0
        public static void ExecuteDbgEngCommand(this DataTarget target, string command, CommandExecutionContext context)
        {
            IDebugControl6 control = (IDebugControl6)target.DebuggerInterface;
            int            hr      = control.ExecuteWide(
                DEBUG_OUTCTL.THIS_CLIENT, command, DEBUG_EXECUTE.DEFAULT);

            if (HR.Failed(hr))
            {
                context.WriteError("Command execution failed with hr = {0:x8}", hr);
            }
        }
コード例 #34
0
        public void PrintStackTrace(CommandExecutionContext context, uint index)
        {
            var stackTrace = GetStackTrace(index);

            PrintStackTrace(context, stackTrace);
        }