From 3c509e50088dbbc9b7da42093ead6e5616497909 Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Mon, 12 Dec 2016 14:31:03 -0800 Subject: [PATCH] Enable interop debugging for Windows amd64 and x86. Found sos portable pdb problem on x86. Fixed interop problems between the native sos and SOS.NetCore managed helper assembly. --- clrdefinitions.cmake | 3 +++ src/ToolBox/SOS/NETCore/SymbolReader.cs | 16 ++++++++-------- src/ToolBox/SOS/Strike/util.cpp | 2 +- src/ToolBox/SOS/Strike/util.h | 12 ++++++------ 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/clrdefinitions.cmake b/clrdefinitions.cmake index 08712d45c652..91346eceefc9 100644 --- a/clrdefinitions.cmake +++ b/clrdefinitions.cmake @@ -131,6 +131,9 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL NetBSD) endif(NOT CMAKE_SYSTEM_NAME STREQUAL NetBSD) add_definitions(-DFEATURE_HOST_ASSEMBLY_RESOLVER) add_definitions(-DFEATURE_ICASTABLE) +if (WIN32 AND (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386)) +add_definitions(-DFEATURE_INTEROP_DEBUGGING) +endif (WIN32 AND (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386)) if (CLR_CMAKE_PLATFORM_UNIX OR CLR_CMAKE_TARGET_ARCH_ARM64) add_definitions(-DFEATURE_IMPLICIT_TLS) set(FEATURE_IMPLICIT_TLS 1) diff --git a/src/ToolBox/SOS/NETCore/SymbolReader.cs b/src/ToolBox/SOS/NETCore/SymbolReader.cs index 7da55c94b8ba..492f7cbd1f8d 100644 --- a/src/ToolBox/SOS/NETCore/SymbolReader.cs +++ b/src/ToolBox/SOS/NETCore/SymbolReader.cs @@ -37,7 +37,7 @@ internal struct MethodDebugInfo /// Read memory callback /// /// number of bytes read or 0 for error - internal unsafe delegate int ReadMemoryDelegate(IntPtr address, byte* buffer, int count); + internal unsafe delegate int ReadMemoryDelegate(ulong address, byte* buffer, int count); private sealed class OpenedReader : IDisposable { @@ -61,7 +61,7 @@ public OpenedReader(MetadataReaderProvider provider, MetadataReader reader) /// private class TargetStream : Stream { - readonly IntPtr _address; + readonly ulong _address; readonly ReadMemoryDelegate _readMemory; public override long Position { get; set; } @@ -70,7 +70,7 @@ private class TargetStream : Stream public override bool CanRead { get { return true; } } public override bool CanWrite { get { return false; } } - public TargetStream(IntPtr address, int size, ReadMemoryDelegate readMemory) + public TargetStream(ulong address, int size, ReadMemoryDelegate readMemory) : base() { _address = address; @@ -89,7 +89,7 @@ public override int Read(byte[] buffer, int offset, int count) { fixed (byte* p = &buffer[offset]) { - int read = _readMemory(new IntPtr(_address.ToInt64() + Position), p, count); + int read = _readMemory(_address + (ulong)Position, p, count); Position += read; return read; } @@ -157,18 +157,18 @@ private static string GetFileName(string pathName) /// in memory PDB address or zero /// in memory PDB size /// Symbol reader handle or zero if error - internal static IntPtr LoadSymbolsForModule(string assemblyPath, bool isFileLayout, IntPtr loadedPeAddress, int loadedPeSize, - IntPtr inMemoryPdbAddress, int inMemoryPdbSize, ReadMemoryDelegate readMemory) + internal static IntPtr LoadSymbolsForModule(string assemblyPath, bool isFileLayout, ulong loadedPeAddress, int loadedPeSize, + ulong inMemoryPdbAddress, int inMemoryPdbSize, ReadMemoryDelegate readMemory) { try { TargetStream peStream = null; - if (assemblyPath == null && loadedPeAddress != IntPtr.Zero) + if (assemblyPath == null && loadedPeAddress != 0) { peStream = new TargetStream(loadedPeAddress, loadedPeSize, readMemory); } TargetStream pdbStream = null; - if (inMemoryPdbAddress != IntPtr.Zero) + if (inMemoryPdbAddress != 0) { pdbStream = new TargetStream(inMemoryPdbAddress, inMemoryPdbSize, readMemory); } diff --git a/src/ToolBox/SOS/Strike/util.cpp b/src/ToolBox/SOS/Strike/util.cpp index b2c96fe2191d..b6336fb143d8 100644 --- a/src/ToolBox/SOS/Strike/util.cpp +++ b/src/ToolBox/SOS/Strike/util.cpp @@ -6134,7 +6134,7 @@ HRESULT SymbolReader::LoadSymbolsForWindowsPDB(___in IMetaDataImport* pMD, ___in int ReadMemoryForSymbols(ULONG64 address, char *buffer, int cb) { ULONG read; - if (SafeReadMemory(address, (PVOID)buffer, cb, &read)) + if (SafeReadMemory(TO_TADDR(address), (PVOID)buffer, cb, &read)) { return read; } diff --git a/src/ToolBox/SOS/Strike/util.h b/src/ToolBox/SOS/Strike/util.h index 1932e28fe9cf..4612acc29936 100644 --- a/src/ToolBox/SOS/Strike/util.h +++ b/src/ToolBox/SOS/Strike/util.h @@ -2355,11 +2355,11 @@ static const char *SymbolReaderDllName = "SOS.NETCore"; static const char *SymbolReaderClassName = "SOS.SymbolReader"; typedef int (*ReadMemoryDelegate)(ULONG64, char *, int); -typedef ULONG64 (*LoadSymbolsForModuleDelegate)(const char*, BOOL, ULONG64, int, ULONG64, int, ReadMemoryDelegate); -typedef void (*DisposeDelegate)(ULONG64); -typedef BOOL (*ResolveSequencePointDelegate)(ULONG64, const char*, unsigned int, unsigned int*, unsigned int*); -typedef BOOL (*GetLocalVariableName)(ULONG64, int, int, BSTR*); -typedef BOOL (*GetLineByILOffsetDelegate)(ULONG64, mdMethodDef, ULONG64, ULONG *, BSTR*); +typedef PVOID (*LoadSymbolsForModuleDelegate)(const char*, BOOL, ULONG64, int, ULONG64, int, ReadMemoryDelegate); +typedef void (*DisposeDelegate)(PVOID); +typedef BOOL (*ResolveSequencePointDelegate)(PVOID, const char*, unsigned int, unsigned int*, unsigned int*); +typedef BOOL (*GetLocalVariableName)(PVOID, int, int, BSTR*); +typedef BOOL (*GetLineByILOffsetDelegate)(PVOID, mdMethodDef, ULONG64, ULONG *, BSTR*); class SymbolReader { @@ -2367,7 +2367,7 @@ class SymbolReader #ifndef FEATURE_PAL ISymUnmanagedReader* m_pSymReader; #endif - ULONG64 m_symbolReaderHandle; + PVOID m_symbolReaderHandle; static LoadSymbolsForModuleDelegate loadSymbolsForModuleDelegate; static DisposeDelegate disposeDelegate;