Add sosreset/sosflush commands/aliases (#3650)
authorMike McLaughlin <mikem@microsoft.com>
Tue, 21 Feb 2023 17:38:45 +0000 (09:38 -0800)
committerGitHub <noreply@github.com>
Tue, 21 Feb 2023 17:38:45 +0000 (09:38 -0800)
* Add sosreset/sosflush commands/aliases

* Code review feedback: remove sosreset

* Add export

src/Microsoft.Diagnostics.ExtensionCommands/Host/StatusCommand.cs
src/SOS/Strike/platform/targetimpl.cpp
src/SOS/Strike/sos_unixexports.src
src/SOS/Strike/sosdocs.txt
src/SOS/Strike/sosdocsunix.txt
src/SOS/Strike/strike.cpp
src/SOS/lldbplugin/soscommand.cpp

index eaef61634a015b54066662230fc824a35635f674..e7e44bd88520b54c133ffa82e609b91f669496f5 100644 (file)
@@ -7,7 +7,8 @@ using System;
 
 namespace Microsoft.Diagnostics.ExtensionCommands
 {
-    [Command(Name = "sosstatus", Help = "Displays internal status or resets the internal cached state.")]
+    [Command(Name = "sosstatus", Help = "Displays internal status.")]
+    [Command(Name = "sosflush", DefaultOptions = "--reset", Help = "Resets the internal cached state.")]
     public class StatusCommand : CommandBase
     {
         [ServiceImport]
@@ -16,7 +17,7 @@ namespace Microsoft.Diagnostics.ExtensionCommands
         [ServiceImport]
         public ISymbolService SymbolService { get; set; }
 
-        [Option(Name = "-reset", Help = "Reset all the cached internal state.")]
+        [Option(Name = "--reset", Aliases = new[] { "-reset" }, Help = "Resets the internal cached state.")]
         public bool Reset { get; set; }
 
         public override void Invoke()
index 20f365809c54d2bcc5fdfdb380e10091712beac1..e4ef3b63b211cb20ef43c445d2bc3569997ef197 100644 (file)
@@ -284,7 +284,9 @@ void Target::Flush()
     if (m_netcore != nullptr) {
         m_netcore->Flush();
     }
-#ifndef FEATURE_PAL
+#ifdef FEATURE_PAL
+    FlushMetadataRegions();
+#else
     if (m_desktop != nullptr) {
         m_desktop->Flush();
     }
index ab7ecd7e4d193ba36793d67d2731c5692245496f..aa8eaf23d3901726ac65d2e775287e2a20ed680c 100644 (file)
@@ -55,8 +55,8 @@ PathTo
 runtimes
 StopOnCatch
 SetClrPath
-SOSFlush
 SOSStatus
+SOSFlush
 runtimes
 SuppressJitOptimization
 SyncBlk
index 96a3a0ada40098cce53f8b8fac7defab521b7abe..ceb9967f950bc2273ba0bc2d84e3417acc596263 100644 (file)
@@ -63,7 +63,7 @@ Examining the GC history           Other
 HistInit                           SetHostRuntime (sethostruntime)
 HistRoot                           SetSymbolServer (setsymbolserver)
 HistObj                            SetClrPath (setclrpath)
-HistObjFind                        SOSFlush
+HistObjFind                        SOSFlush (sosflush)
 HistClear                          SOSStatus (sosstatus)
                                    FAQ
                                    Help (soshelp)
@@ -2663,8 +2663,7 @@ COMMAND: sosstatus.
 
 -reset - reset all the cached internal SOS state.
 
-Display internal SOS status, reset the internal cached state, or change between the desktop .NET framework
-or .NET Core runtimes when both are loaded in the process or dump.
+Displays internal SOS status or resets the internal cached state.
 
     0:000> !sosstatus
     Target platform: 8664 Context size 04d0
@@ -2675,6 +2674,12 @@ or .NET Core runtimes when both are loaded in the process or dump.
     Server: http://msdl.microsoft.com/download/symbols/
 \\
 
+COMMAND: sosflush.
+!sosflush
+
+Resets the internal cached state.
+\\
+
 COMMAND: setclrpath.
 !setclrpath <path-to-runtime>
 
index e61e5b8715274198d4493bf8d4ef0fe0ae4996c1..0a4b955bc68124533657c94e2ddce30f4321e0f6 100644 (file)
@@ -2324,7 +2324,13 @@ SOSStatus [-reset]
 
 -reset - reset all the cached internal SOS state.
 
-Display internal SOS status or reset the internal cached state.
+Displays internal SOS status or resets the internal cached state.
+\\
+
+COMMAND: sosflush.
+sosflush
+
+Resets the internal cached state.
 \\
 
 COMMAND: setclrpath.
index 9725b2e9b4f4daebc4f16809ff4fdf297aae0dfa..14462f05caf73967ae724eab76c675145cfa0d60 100644 (file)
@@ -10417,8 +10417,12 @@ DECLARE_API(SOSStatus)
         }
         if (bReset)
         {
-            ReleaseTarget();
-            ExtOut("SOS state reset\n");
+            ITarget* target = GetTarget();
+            if (target != nullptr)
+            {
+                target->Flush();
+            }
+            ExtOut("Internal cached state reset\n");
             return S_OK;
         }
         Target::DisplayStatus();
@@ -14292,11 +14296,22 @@ DECLARE_API( VMMap )
 
 DECLARE_API(SOSFlush)
 {
-    INIT_API_EXT();
-    ITarget* target = GetTarget();
-    if (target != nullptr)
+    INIT_API_NOEE();
+
+    IHostServices* hostServices = GetHostServices();
+    if (hostServices != nullptr)
     {
-        target->Flush();
+        Status = hostServices->DispatchCommand("sosflush", args);
+    }
+    else
+    {
+        ITarget* target = GetTarget();
+        if (target != nullptr)
+        {
+            target->Flush();
+        }
+        ExtOut("Internal cached state reset\n");
+        return S_OK;
     }
     return Status;
 }
index cb320c19eaa7126e031c93b2349e4305bd78b7c7..c7e5ad4beb9fcc69c8dee5db7c7000c370d96f76 100644 (file)
@@ -218,7 +218,7 @@ sosCommandInitialize(lldb::SBDebugger debugger)
     g_services->AddManagedCommand("setsymbolserver", "Enables the symbol server support ");
     g_services->AddCommand("soshelp", new sosCommand("Help"), "Displays all available commands when no parameter is specified, or displays detailed help information about the specified command: 'soshelp <command>'.");
     g_services->AddCommand("sosstatus", new sosCommand("SOSStatus"), "Displays the global SOS status.");
-    g_services->AddCommand("sosflush", new sosCommand("SOSFlush"), "Flushes the DAC caches.");
+    g_services->AddCommand("sosflush", new sosCommand("SOSFlush"), "Resets the internal cached state.");
     g_services->AddCommand("syncblk", new sosCommand("SyncBlk"), "Displays the SyncBlock holder info.");
     g_services->AddCommand("threadpool", new sosCommand("ThreadPool"), "Displays info about the runtime thread pool.");
     g_services->AddCommand("threadstate", new sosCommand("ThreadState"), "Pretty prints the meaning of a threads state.");