Change the dotnet-dump setthread command to take the thread index (#275)
authorMike McLaughlin <mikem@microsoft.com>
Tue, 21 May 2019 03:03:45 +0000 (20:03 -0700)
committerGitHub <noreply@github.com>
Tue, 21 May 2019 03:03:45 +0000 (20:03 -0700)
src/Tools/dotnet-dump/Commands/HelpCommand.cs
src/Tools/dotnet-dump/Commands/SOSCommand.cs
src/Tools/dotnet-dump/Commands/SetThreadCommand.cs

index 37b2b3c79fdad2270ec021b088ca1e1ab8d61043..32e0a54b4899e81fb7b3783f13f57fb0d7bbd882 100644 (file)
@@ -1,6 +1,5 @@
 using Microsoft.Diagnostic.Repl;
 using System.CommandLine;
-using System.Threading.Tasks;
 
 namespace Microsoft.Diagnostic.Tools.Dump
 {
index f9bfecee2d381c59740faa5ea12ee49d2a646788..e05aa01f1dfd38f94e9a46151f415be79fd56965 100644 (file)
@@ -1,12 +1,8 @@
 using Microsoft.Diagnostic.Repl;
-using SOS;
 using System;
 using System.CommandLine;
 using System.IO;
 using System.Linq;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Threading.Tasks;
 
 namespace Microsoft.Diagnostic.Tools.Dump
 {
index 032bacbf54fbec9dd6dbc76fc154f95c8482849a..b9e12dce65729e1786d2f57acc7385b88385cfd1 100644 (file)
@@ -1,24 +1,30 @@
 
 using Microsoft.Diagnostic.Repl;
+using System;
+using System.Collections.Generic;
 using System.CommandLine;
-using System.Threading.Tasks;
+using System.Linq;
 
 namespace Microsoft.Diagnostic.Tools.Dump
 {
-    [Command(Name = "setthread", Help = "Sets or displays the current thread id for the SOS commands.")]
+    [Command(Name = "setthread", Help = "Sets or displays the current thread for the SOS commands.")]
     [CommandAlias(Name = "threads")]
     public class SetThreadCommand : CommandBase
     {
-        [Argument(Help = "The thread id to set, otherwise displays the current id.")]
-        public int? ThreadId { get; set; } = null;
+        [Argument(Help = "The thread index to set, otherwise displays the list of threads.")]
+        public int? ThreadIndex { get; set; } = null;
 
         public AnalyzeContext AnalyzeContext { get; set; }
 
         public override void Invoke()
         {
-            if (ThreadId.HasValue)
+            if (ThreadIndex.HasValue)
             {
-                AnalyzeContext.CurrentThreadId = ThreadId.Value;
+                IEnumerable<uint> threads = AnalyzeContext.Target.DataReader.EnumerateAllThreads();
+                if (ThreadIndex.Value >= threads.Count()) {
+                    throw new InvalidOperationException($"Invalid thread index {ThreadIndex.Value}");
+                }
+                AnalyzeContext.CurrentThreadId = unchecked((int)threads.ElementAt(ThreadIndex.Value));
             }
             else
             {