From: Mike McLaughlin Date: Sat, 14 Sep 2019 04:08:15 +0000 (-0700) Subject: Various fixes and update cdb (#477) X-Git-Tag: submit/tizen/20191015.063341~10^2~1^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ecd7223a328384c2af4747ce77cd864ae1eae865;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Various fixes and update cdb (#477) Various fixes Change cdb version in config Fix symbol not found problem caused by directory symstore not setting the stream position to 0. --- diff --git a/eng/Versions.props b/eng/Versions.props index 6ac5419fe..130751b89 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -32,7 +32,7 @@ 2.4.1 2.0.3 - 1.1.0 + 10.0.18362 diff --git a/src/Microsoft.Diagnostics.DebugServices/RegisterService.cs b/src/Microsoft.Diagnostics.DebugServices/RegisterService.cs index 3bd96d6f3..a7fea168a 100644 --- a/src/Microsoft.Diagnostics.DebugServices/RegisterService.cs +++ b/src/Microsoft.Diagnostics.DebugServices/RegisterService.cs @@ -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 /// register index /// value returned /// true if value found - 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) + /// + /// Returns the raw context buffer bytes for the specified thread. + /// + /// thread id + /// register context or null if error + 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()); + } } } } diff --git a/src/SOS/SOS.Hosting/SOSHost.cs b/src/SOS/SOS.Hosting/SOSHost.cs index e0a7c5a25..8fa2e4f87 100644 --- a/src/SOS/SOS.Hosting/SOSHost.cs +++ b/src/SOS/SOS.Hosting/SOSHost.cs @@ -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; } diff --git a/src/SOS/SOS.NETCore/SymbolReader.cs b/src/SOS/SOS.NETCore/SymbolReader.cs index 392c42ca3..29081401a 100644 --- a/src/SOS/SOS.NETCore/SymbolReader.cs +++ b/src/SOS/SOS.NETCore/SymbolReader.cs @@ -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); diff --git a/src/SOS/SOS.UnitTests/ConfigFiles/Windows/Debugger.Tests.Config.txt b/src/SOS/SOS.UnitTests/ConfigFiles/Windows/Debugger.Tests.Config.txt index 6880bfc6e..a837c13d6 100644 --- a/src/SOS/SOS.UnitTests/ConfigFiles/Windows/Debugger.Tests.Config.txt +++ b/src/SOS/SOS.UnitTests/ConfigFiles/Windows/Debugger.Tests.Config.txt @@ -17,7 +17,7 @@ $(RootBinDir)\bin\Windows_NT.$(TargetArchitecture).$(TargetConfiguration) $(RootBinDir)\TestResults\$(TargetConfiguration)\sos.unittests_$(Timestamp) $(RootBinDir)\tmp\$(TargetConfiguration)\dumps - $(NuGetPackageCacheDir)\cdb-sos\1.1.0\runtimes\win-$(TargetArchitecture)\native\cdb.exe + $(NuGetPackageCacheDir)\cdb-sos\10.0.18362\runtimes\win-$(TargetArchitecture)\native\cdb.exe $(InstallDir)\runcommand.dll $(RepoRootDir)\src\SOS\SOS.UnitTests\Debuggees diff --git a/src/SOS/Strike/strike.cpp b/src/SOS/Strike/strike.cpp index 4f3546154..d8207eeab 100644 --- a/src/SOS/Strike/strike.cpp +++ b/src/SOS/Strike/strike.cpp @@ -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 { diff --git a/src/pal/prebuilt/inc/fxver.h b/src/pal/prebuilt/inc/fxver.h index 7cb0cae0f..383b95ad3 100644 --- a/src/pal/prebuilt/inc/fxver.h +++ b/src/pal/prebuilt/inc/fxver.h @@ -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