Various fixes and update cdb (#477)
authorMike McLaughlin <mikem@microsoft.com>
Sat, 14 Sep 2019 04:08:15 +0000 (21:08 -0700)
committerGitHub <noreply@github.com>
Sat, 14 Sep 2019 04:08:15 +0000 (21:08 -0700)
Various fixes

Change cdb version in config

Fix symbol not found problem caused by directory symstore not setting the stream position to 0.

eng/Versions.props
src/Microsoft.Diagnostics.DebugServices/RegisterService.cs
src/SOS/SOS.Hosting/SOSHost.cs
src/SOS/SOS.NETCore/SymbolReader.cs
src/SOS/SOS.UnitTests/ConfigFiles/Windows/Debugger.Tests.Config.txt
src/SOS/Strike/strike.cpp
src/pal/prebuilt/inc/fxver.h

index 6ac5419fe47d52c381b454c5216bece1d536fe72..130751b89fba82b6ad959400208f3bd1209ed942 100644 (file)
@@ -32,7 +32,7 @@
     <XUnitVersion>2.4.1</XUnitVersion>
     <XUnitAbstractionsVersion>2.0.3</XUnitAbstractionsVersion>
 
-    <cdbsosversion>1.1.0</cdbsosversion>
+    <cdbsosversion>10.0.18362</cdbsosversion>
 
   </PropertyGroup>
 
index 3bd96d6f3a541af21a802a3b2bf7ac24462e7f7f..a7fea168aab9858d307a86d176cafac226b638d6 100644 (file)
@@ -5,6 +5,7 @@
 using Microsoft.Diagnostics.Runtime;
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
 using System.Reflection;
 using System.Runtime.InteropServices;
@@ -56,7 +57,8 @@ namespace Microsoft.Diagnostics.DebugServices
             switch (target.Architecture)
             {
                 case Architecture.Amd64:
-                    _contextSize = AMD64Context.Size;
+                    // Dumps generated with newer dbgeng have bigger context buffers and clrmd requires the context size to at least be that size.
+                    _contextSize = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 0x700 : AMD64Context.Size;
                     _contextFlags = AMD64Context.ContextControl | AMD64Context.ContextInteger | AMD64Context.ContextSegments;
                     contextType = typeof(AMD64Context);
                     break;
@@ -160,7 +162,7 @@ namespace Microsoft.Diagnostics.DebugServices
         /// <param name="index">register index</param>
         /// <param name="value">value returned</param>
         /// <returns>true if value found</returns>
-        public unsafe bool GetRegisterValue(uint threadId, int index, out ulong value)
+        public bool GetRegisterValue(uint threadId, int index, out ulong value)
         {
             value = 0;
 
@@ -169,22 +171,25 @@ namespace Microsoft.Diagnostics.DebugServices
                 byte[] threadContext = GetThreadContext(threadId);
                 if (threadContext != null)
                 {
-                    fixed (byte* ptr = threadContext)
+                    unsafe
                     {
-                        switch (info.RegisterSize)
+                        fixed (byte* ptr = threadContext)
                         {
-                            case 1:
-                                value = *((byte*)(ptr + info.RegisterOffset));
-                                return true;
-                            case 2:
-                                value = *((ushort*)(ptr + info.RegisterOffset));
-                                return true;
-                            case 4:
-                                value = *((uint*)(ptr + info.RegisterOffset));
-                                return true;
-                            case 8:
-                                value = *((ulong*)(ptr + info.RegisterOffset));
-                                return true;
+                            switch (info.RegisterSize)
+                            {
+                                case 1:
+                                    value = *((byte*)(ptr + info.RegisterOffset));
+                                    return true;
+                                case 2:
+                                    value = *((ushort*)(ptr + info.RegisterOffset));
+                                    return true;
+                                case 4:
+                                    value = *((uint*)(ptr + info.RegisterOffset));
+                                    return true;
+                                case 8:
+                                    value = *((ulong*)(ptr + info.RegisterOffset));
+                                    return true;
+                            }
                         }
                     }
                 }
@@ -192,7 +197,12 @@ namespace Microsoft.Diagnostics.DebugServices
             return false;
         }
 
-        private unsafe byte[] GetThreadContext(uint threadId)
+        /// <summary>
+        /// Returns the raw context buffer bytes for the specified thread.
+        /// </summary>
+        /// <param name="threadId">thread id</param>
+        /// <returns>register context or null if error</returns>
+        public byte[] GetThreadContext(uint threadId)
         {
             if (_threadContextCache.TryGetValue(threadId, out byte[] threadContext))
             {
@@ -200,13 +210,23 @@ namespace Microsoft.Diagnostics.DebugServices
             }
             else
             {
-                threadContext = new byte[_contextSize];
-                fixed (byte* ptr = threadContext)
+                unsafe
                 {
-                    if (_target.DataReader.GetThreadContext(threadId, _contextFlags, (uint)_contextSize, new IntPtr(ptr)))
+                    threadContext = new byte[_contextSize];
+                    fixed (byte* ptr = threadContext)
                     {
-                        _threadContextCache.Add(threadId, threadContext);
-                        return threadContext;
+                        try
+                        {
+                            if (_target.DataReader.GetThreadContext(threadId, _contextFlags, (uint)_contextSize, new IntPtr(ptr)))
+                            {
+                                _threadContextCache.Add(threadId, threadContext);
+                                return threadContext;
+                            }
+                        }
+                        catch (ClrDiagnosticsException ex)
+                        {
+                            Trace.TraceError(ex.ToString());
+                        }
                     }
                 }
             }
index e0a7c5a25c552bd18bedde36459f770d1b68fb23..8fa2e4f87c01aa94a3bbab59b77dcec17c1bb71d 100644 (file)
@@ -508,7 +508,11 @@ namespace SOS
                                 // If the address isn't contained in one of the sections, assume that SOS is reader the PE headers directly.
                                 block = reader.GetEntireImage();
                             }
-                            BlobReader blob = block.GetReader();
+                            else
+                            {
+                                rva = 0;
+                            }
+                            BlobReader blob = block.GetReader(rva, (int)bytesRequested);
                             byte[] data = blob.ReadBytes((int)bytesRequested);
 
                             Marshal.Copy(data, 0, buffer, data.Length);
@@ -957,9 +961,18 @@ namespace SOS
             uint contextSize)
         {
             uint threadId = (uint)_analyzeContext.CurrentThreadId;
-            if (!DataReader.GetThreadContext(threadId, uint.MaxValue, contextSize, context)) {
+            byte[] registerContext = _registerService.GetThreadContext(threadId);
+            if (registerContext == null) {
                 return E_FAIL;
             }
+            try
+            {
+                Marshal.Copy(registerContext, 0, context, (int)contextSize);
+            }
+            catch (Exception ex) when (ex is ArgumentOutOfRangeException || ex is ArgumentNullException)
+            {
+                return E_INVALIDARG;
+            }
             return S_OK;
         }
 
index 392c42ca3411a0ce1d02c2c12cf275f149421df2..29081401a688985ebd220fce2ac5020080c00a1e 100644 (file)
@@ -332,6 +332,9 @@ namespace SOS
                         {
                             downloadFilePath = file.FileName;
 
+                            // Make sure the stream is at the beginning of the module
+                            file.Stream.Position = 0;
+
                             // If the downloaded doesn't already exists on disk in the cache, then write it to a temporary location.
                             if (!File.Exists(downloadFilePath))
                             {
@@ -931,6 +934,8 @@ namespace SOS
                     {
                         return null;
                     }
+                    // Make sure the stream is at the beginning of the pdb.
+                    pdbStream.Position = 0;
                 }
 
                 provider = MetadataReaderProvider.FromPortablePdbStream(pdbStream);
index 6880bfc6edfd01498f579a3c648a7b295e84444e..a837c13d6672c26c3d4ab24da5d63221f62ec93b 100644 (file)
@@ -17,7 +17,7 @@
   <InstallDir>$(RootBinDir)\bin\Windows_NT.$(TargetArchitecture).$(TargetConfiguration)</InstallDir>
   <LogDir>$(RootBinDir)\TestResults\$(TargetConfiguration)\sos.unittests_$(Timestamp)</LogDir>
   <DumpDir>$(RootBinDir)\tmp\$(TargetConfiguration)\dumps</DumpDir>
-  <CDBPath>$(NuGetPackageCacheDir)\cdb-sos\1.1.0\runtimes\win-$(TargetArchitecture)\native\cdb.exe</CDBPath>
+  <CDBPath>$(NuGetPackageCacheDir)\cdb-sos\10.0.18362\runtimes\win-$(TargetArchitecture)\native\cdb.exe</CDBPath>
   <CDBHelperExtension>$(InstallDir)\runcommand.dll</CDBHelperExtension>
 
   <DebuggeeSourceRoot>$(RepoRootDir)\src\SOS\SOS.UnitTests\Debuggees</DebuggeeSourceRoot>
index 4f3546154f29ac0a34adf96792d227ee1b45aa81..d8207eeaba61cf2d1967b8d1719bffcd226c91c2 100644 (file)
@@ -10066,7 +10066,7 @@ DECLARE_API (EEVersion)
 #ifndef FEATURE_PAL
             if (version.dwFileFlags & VS_FF_DEBUG) 
             {                    
-                ExtOut(" Checked or debug build");
+                ExtOut(" checked or debug build");
             }
             else
             { 
@@ -10113,7 +10113,7 @@ DECLARE_API (EEVersion)
 
             if (sosVersion.dwFileFlags & VS_FF_DEBUG) 
             {                    
-                ExtOut(" Checked or debug build");                    
+                ExtOut(" debug build");                    
             }
             else
             { 
index 7cb0cae0f42f757c5a4945cd9d009c1c1409ed14..383b95ad36dd14afcc783e6060489b2eeb3e4a68 100644 (file)
@@ -86,7 +86,7 @@
 #define VER_FILESUBTYPE             VFT2_UNKNOWN
 
 /* default is nodebug */
-#if DBG
+#if _DEBUG
 #define VER_DEBUG                   VS_FF_DEBUG
 #else
 #define VER_DEBUG                   0