Misc SOS fixes (#758)
authorMike McLaughlin <mikem@microsoft.com>
Tue, 21 Jan 2020 22:40:27 +0000 (14:40 -0800)
committerGitHub <noreply@github.com>
Tue, 21 Jan 2020 22:40:27 +0000 (14:40 -0800)
Misc SOS fixes

Change "dbgout" command not to require EE or DAC (use INIT_API_EXT).

Fix case where the DAC is already in the temp directory because of a
loadsymbols command when symlink'ing it on Linux.

Allow just setsymbolserver -log without any other options.

src/SOS/SOS.UnitTests/Scripts/OtherCommands.script
src/SOS/Strike/runtime.cpp
src/SOS/Strike/strike.cpp
src/SOS/Strike/util.cpp

index 7c264db535e287984987863de2eea2209b54ccb4..f3f5a29e6e0d6b4f0b092f9bf81ed19c6c8efa91 100644 (file)
@@ -95,7 +95,7 @@ SOSCOMMAND:DumpAssembly <POUT>\s*Assembly:\s+(<HEXVAL>)\s+\[.*<POUT>
 VERIFY:\s*Parent Domain:\s+<HEXVAL>\s+
 VERIFY:\s*Name:\s+.*(System\.Private\.CoreLib(\.ni)?\.dll|mscorlib.dll)\s+
 
-SOSCOMMAND:DumpModule <POUT>\s+Module Name\s+(<HEXVAL>)\s+.*<POUT>
+SOSCOMMAND:DumpModule <POUT>\s+Module\s+(<HEXVAL>)\s+.*<POUT>
 VERIFY:\s*PEFile:\s+<HEXVAL>\s+
 VERIFY:\s*ModuleId:\s+<HEXVAL>\s+
 VERIFY:\s*LoaderHeap:\s+<HEXVAL>\s+
index 04d48bfa0974ad016ff117092ee5dd15b7116dea..76505769bcfa38a0deb0877fb8f8db53e966a621 100644 (file)
@@ -307,14 +307,23 @@ LPCSTR Runtime::GetDacFilePath()
                     std::string dacSymLink(tmpPath);
                     dacSymLink.append(NETCORE_DAC_DLL_NAME_A);
 
-                    int error = symlink(dacModulePath.c_str(), dacSymLink.c_str());
-                    if (error == 0)
+                    // Check if the DAC file already exists in the temp directory because
+                    // of a "loadsymbols" command which downloads everything.
+                    if (access(dacSymLink.c_str(), F_OK) == 0)
                     {
                         dacModulePath.assign(dacSymLink);
                     }
                     else
                     {
-                        ExtErr("symlink(%s, %s) FAILED %s\n", dacModulePath.c_str(), dacSymLink.c_str(), strerror(errno));
+                        int error = symlink(dacModulePath.c_str(), dacSymLink.c_str());
+                        if (error == 0)
+                        {
+                            dacModulePath.assign(dacSymLink);
+                        }
+                        else
+                        {
+                            ExtErr("symlink(%s, %s) FAILED %s\n", dacModulePath.c_str(), dacSymLink.c_str(), strerror(errno));
+                        }
                     }
                 }
 #endif
index 4efa101bbc1d50bc6deb8dd310d037481eaa36a4..94f857b2212da7a49fbe87d16afd8e0950eaf6ff 100644 (file)
@@ -14553,7 +14553,7 @@ end:
 
 DECLARE_API(dbgout)
 {
-    INIT_API();
+    INIT_API_EXT();
 
     BOOL bOff = FALSE;
 
@@ -16018,7 +16018,7 @@ DECLARE_API(SetSymbolServer)
         DisableSymbolStore();
     }
 
-    if (msdl || symweb || symbolServer.data != nullptr || symbolCache.data != nullptr || searchDirectory.data != nullptr || windowsSymbolPath.data != nullptr)
+    if (logging || msdl || symweb || symbolServer.data != nullptr || symbolCache.data != nullptr || searchDirectory.data != nullptr || windowsSymbolPath.data != nullptr)
     {
         Status = InitializeSymbolStore(logging, msdl, symweb, symbolServer.data, (int)timeoutInMinutes, symbolCache.data, searchDirectory.data, windowsSymbolPath.data);
         if (FAILED(Status))
index 6cdae98c5134703345b53c929cd2f614a3de3395..0c6be1383a618f2fc3bf3d9456e9e27f4300aefe 100644 (file)
@@ -1497,7 +1497,7 @@ void AssemblyInfo(DacpAssemblyData *pAssembly)
     ExtOut("ClassLoader:        %p\n", SOS_PTR(pAssembly->ClassLoader));
     if ((ULONG64)pAssembly->AssemblySecDesc != NULL)
         ExtOut("SecurityDescriptor: %p\n", SOS_PTR(pAssembly->AssemblySecDesc));
-    ExtOut("  Module Name\n");
+    ExtOut("  Module\n");
     
     ArrayHolder<CLRDATA_ADDRESS> Modules = new CLRDATA_ADDRESS[pAssembly->ModuleCount];
     if (Modules == NULL 
@@ -1507,17 +1507,16 @@ void AssemblyInfo(DacpAssemblyData *pAssembly)
        return;
     }
     
-    for (UINT n=0;n<pAssembly->ModuleCount;n++)
+    for (UINT n = 0; n < pAssembly->ModuleCount; n++)
     {
         if (IsInterrupt())
         {
             return;
         }
-
         CLRDATA_ADDRESS ModuleAddr = Modules[n];
-        DMLOut("%s    " WIN86_8SPACES, DMLModule(ModuleAddr));
+        DMLOut("  %s    " WIN86_8SPACES, DMLModule(ModuleAddr));
         DacpModuleData moduleData;
-        if (moduleData.Request(g_sos,ModuleAddr)==S_OK)
+        if (moduleData.Request(g_sos, ModuleAddr) == S_OK)
         {
             WCHAR fileName[MAX_LONGPATH];
             FileNameForModule (&moduleData, fileName);
@@ -1530,6 +1529,10 @@ void AssemblyInfo(DacpAssemblyData *pAssembly)
                 ExtOut("%S\n", (moduleData.bIsReflection) ? W("Dynamic Module") : W("Unknown Module"));
             }
         }        
+        else
+        {
+            ExtOut("Request module data FAILED\n");
+        }
     }
 }
 
@@ -2131,7 +2134,7 @@ DWORD_PTR *ModuleFromName(__in_opt LPSTR mName, int *numModule)
     *numModule = 0;
 
     DacpAppDomainStoreData adsData;
-    if (adsData.Request(g_sos)!=S_OK)
+    if (adsData.Request(g_sos) != S_OK)
         return NULL;
 
     ArrayHolder<CLRDATA_ADDRESS> pAssemblyArray = NULL;
@@ -2144,8 +2147,7 @@ DWORD_PTR *ModuleFromName(__in_opt LPSTR mName, int *numModule)
         return NULL;
     }
     ArrayHolder<CLRDATA_ADDRESS> pArray = new CLRDATA_ADDRESS[arrayLength];
-
-    if (pArray==NULL)
+    if (pArray == NULL)
     {
         ReportOOM();
         return NULL;
@@ -2156,7 +2158,7 @@ DWORD_PTR *ModuleFromName(__in_opt LPSTR mName, int *numModule)
     {
         pArray[1] = adsData.sharedDomain;
     }
-    if (g_sos->GetAppDomainList(adsData.DomainCount, pArray.GetPtr()+numSpecialDomains, NULL)!=S_OK)
+    if (g_sos->GetAppDomainList(adsData.DomainCount, pArray.GetPtr() + numSpecialDomains, NULL) != S_OK)
     {
         ExtOut("Unable to get array of AppDomains\n");
         return NULL;
@@ -2167,7 +2169,7 @@ DWORD_PTR *ModuleFromName(__in_opt LPSTR mName, int *numModule)
     int maxList = arrayLength; // account for system and shared domains
     if (maxList <= 0 || !ClrSafeInt<size_t>::multiply(maxList, sizeof(PVOID), AllocSize))
     {
-        ExtOut("Integer overflow error.\n");
+        ExtOut("<integer overflow>\n");
         return NULL;
     }
     
@@ -2190,7 +2192,7 @@ DWORD_PTR *ModuleFromName(__in_opt LPSTR mName, int *numModule)
         }
         
         DacpAppDomainData appDomain;
-        if (FAILED(appDomain.Request(g_sos,pArray[n])))
+        if (FAILED(appDomain.Request(g_sos, pArray[n])))
         {
             // Don't print a failure message here, there is a very normal case when checking
             // for modules after clr is loaded but before any AppDomains or assemblies are created
@@ -2216,7 +2218,7 @@ DWORD_PTR *ModuleFromName(__in_opt LPSTR mName, int *numModule)
 
             if (FAILED(g_sos->GetAssemblyList(appDomain.AppDomainPtr, appDomain.AssemblyCount, pAssemblyArray, NULL)))
             {
-                ExtOut("Unable to get array of Assemblies for the given AppDomain..\n");
+                ExtOut("Unable to get array of Assemblies for the given AppDomain\n");
                 goto Failure;
             }
 
@@ -2231,14 +2233,14 @@ DWORD_PTR *ModuleFromName(__in_opt LPSTR mName, int *numModule)
                 DacpAssemblyData assemblyData;
                 if (FAILED(assemblyData.Request(g_sos, pAssemblyArray[nAssem])))
                 {
-                    ExtOut("Failed to request assembly.\n");
+                    ExtOut("Failed to request assembly\n");
                     goto Failure;
                 }
 
                 pModules = new CLRDATA_ADDRESS[assemblyData.ModuleCount];
                 if (FAILED(g_sos->GetAssemblyModuleList(assemblyData.AssemblyPtr, assemblyData.ModuleCount, pModules, NULL)))
                 {
-                    ExtOut("Failed to get the modules for the given assembly.\n");
+                    ExtOut("Failed to get the modules for the given assembly\n");
                     goto Failure;
                 }
 
@@ -2252,10 +2254,10 @@ DWORD_PTR *ModuleFromName(__in_opt LPSTR mName, int *numModule)
 
                     CLRDATA_ADDRESS ModuleAddr = pModules[nModule];
                     DacpModuleData ModuleData;
-                    if (FAILED(ModuleData.Request(g_sos,ModuleAddr)))
+                    if (FAILED(ModuleData.Request(g_sos, ModuleAddr)))
                     {
-                        ExtOut("Failed to request Module data from assembly.\n");
-                        goto Failure;
+                        ExtDbgOut("Failed to request module data from assembly at %p\n", ModuleAddr);
+                        continue;
                     }
 
                     if (mName != NULL)