private static bool TryGetConstantValue(this ISymUnmanagedConstant constant, out NamedLocalConstant value) { value = default(NamedLocalConstant); int length; int hresult = constant.GetName(0, out length, null); SymUnmanagedReaderExtensions.ThrowExceptionForHR(hresult); Debug.Assert(length > 0); if (length == 0) { return(false); } var chars = new char[length]; hresult = constant.GetName(length, out length, chars); SymUnmanagedReaderExtensions.ThrowExceptionForHR(hresult); Debug.Assert(chars[length - 1] == 0); var name = new string(chars, 0, length - 1); constant.GetSignature(0, out length, null); Debug.Assert(length > 0); if (length == 0) { return(false); } var signature = new byte[length]; constant.GetSignature(length, out length, signature); object val; constant.GetValue(out val); var constantValue = GetConstantValue(signature, val); value = new NamedLocalConstant(name, signature, constantValue); return(true); }
private static ISymUnmanagedReader3 CreateNativeSymReader(Stream pdbStream, object metadataImporter) { object symReader = null; var guid = default(Guid); if (IntPtr.Size == 4) { CreateSymReader32(ref guid, out symReader); } else { CreateSymReader64(ref guid, out symReader); } var reader = (ISymUnmanagedReader3)symReader; int hr = reader.Initialize(metadataImporter, null, null, new ComStreamWrapper(pdbStream)); SymUnmanagedReaderExtensions.ThrowExceptionForHR(hr); return(reader); }
public static ISymUnmanagedReader CreateReader(Stream pdbStream, object metadataImporter) { pdbStream.Position = 0; bool isPortable = pdbStream.ReadByte() == 'B' && pdbStream.ReadByte() == 'S' && pdbStream.ReadByte() == 'J' && pdbStream.ReadByte() == 'B'; pdbStream.Position = 0; if (isPortable) { var binder = new PortablePdb.SymBinder(); ISymUnmanagedReader reader; int hr = binder.GetReaderFromStream(metadataImporter, new ComStreamWrapper(pdbStream), out reader); SymUnmanagedReaderExtensions.ThrowExceptionForHR(hr); return(reader); } else { return(CreateNativeSymReader(pdbStream, metadataImporter)); } }
public unsafe static MethodDebugInfo <TTypeSymbol, TLocalSymbol> ReadMethodDebugInfo( ISymUnmanagedReader symReader, EESymbolProvider <TTypeSymbol, TLocalSymbol> symbolProviderOpt, // TODO: only null in DTEE case where we looking for default namesapace int methodToken, int methodVersion, int ilOffset, bool isVisualBasicMethod) { // no symbols if (symReader == null) { return(None); } var symReader4 = symReader as ISymUnmanagedReader4; if (symReader4 != null) // TODO: VB Portable PDBs { byte *metadata; int size; // TODO: version int hr = symReader4.GetPortableDebugMetadata(out metadata, out size); SymUnmanagedReaderExtensions.ThrowExceptionForHR(hr); if (metadata != null) { var mdReader = new MetadataReader(metadata, size); try { return(ReadFromPortable(mdReader, methodToken, ilOffset, symbolProviderOpt, isVisualBasicMethod)); } catch (BadImageFormatException) { // bad CDI, ignore return(None); } } } var allScopes = ArrayBuilder <ISymUnmanagedScope> .GetInstance(); var containingScopes = ArrayBuilder <ISymUnmanagedScope> .GetInstance(); try { ImmutableArray <HoistedLocalScopeRecord> hoistedLocalScopeRecords; ImmutableArray <ImmutableArray <ImportRecord> > importRecordGroups; ImmutableArray <ExternAliasRecord> externAliasRecords; ImmutableDictionary <int, ImmutableArray <bool> > dynamicLocalMap; ImmutableDictionary <string, ImmutableArray <bool> > dynamicLocalConstantMap; string defaultNamespaceName; var symMethod = symReader.GetMethodByVersion(methodToken, methodVersion); if (symMethod != null) { symMethod.GetAllScopes(allScopes, containingScopes, ilOffset, isScopeEndInclusive: isVisualBasicMethod); } if (isVisualBasicMethod) { ReadVisualBasicImportsDebugInfo( symReader, methodToken, methodVersion, out importRecordGroups, out defaultNamespaceName); hoistedLocalScopeRecords = ImmutableArray <HoistedLocalScopeRecord> .Empty; externAliasRecords = ImmutableArray <ExternAliasRecord> .Empty; dynamicLocalMap = null; dynamicLocalConstantMap = null; } else { Debug.Assert(symbolProviderOpt != null); ReadCSharpNativeImportsInfo( symReader, symbolProviderOpt, methodToken, methodVersion, out importRecordGroups, out externAliasRecords); ReadCSharpNativeCustomDebugInfo( symReader, methodToken, methodVersion, allScopes, out hoistedLocalScopeRecords, out dynamicLocalMap, out dynamicLocalConstantMap); defaultNamespaceName = ""; } var constantsBuilder = ArrayBuilder <TLocalSymbol> .GetInstance(); if (symbolProviderOpt != null) // TODO { GetConstants(constantsBuilder, symbolProviderOpt, containingScopes, dynamicLocalConstantMap); } var reuseSpan = GetReuseSpan(allScopes, ilOffset, isVisualBasicMethod); return(new MethodDebugInfo <TTypeSymbol, TLocalSymbol>( hoistedLocalScopeRecords, importRecordGroups, externAliasRecords, dynamicLocalMap, defaultNamespaceName, containingScopes.GetLocalNames(), constantsBuilder.ToImmutableAndFree(), reuseSpan)); } catch (InvalidOperationException) { // bad CDI, ignore return(None); } finally { allScopes.Free(); containingScopes.Free(); } }
public unsafe static MethodDebugInfo <TTypeSymbol, TLocalSymbol> ReadMethodDebugInfo( ISymUnmanagedReader3 symReader, EESymbolProvider <TTypeSymbol, TLocalSymbol> symbolProviderOpt, // TODO: only null in DTEE case where we looking for default namesapace int methodToken, int methodVersion, int ilOffset, bool isVisualBasicMethod) { // no symbols if (symReader == null) { return(None); } if (symReader is ISymUnmanagedReader5 symReader5) { int hr = symReader5.GetPortableDebugMetadataByVersion(methodVersion, out byte *metadata, out int size); SymUnmanagedReaderExtensions.ThrowExceptionForHR(hr); if (hr == 0) { var mdReader = new MetadataReader(metadata, size); try { return(ReadFromPortable(mdReader, methodToken, ilOffset, symbolProviderOpt, isVisualBasicMethod)); } catch (BadImageFormatException) { // bad CDI, ignore return(None); } } } var allScopes = ArrayBuilder <ISymUnmanagedScope> .GetInstance(); var containingScopes = ArrayBuilder <ISymUnmanagedScope> .GetInstance(); try { var symMethod = symReader.GetMethodByVersion(methodToken, methodVersion); if (symMethod != null) { symMethod.GetAllScopes(allScopes, containingScopes, ilOffset, isScopeEndInclusive: isVisualBasicMethod); } ImmutableArray <ImmutableArray <ImportRecord> > importRecordGroups; ImmutableArray <ExternAliasRecord> externAliasRecords; string defaultNamespaceName; if (isVisualBasicMethod) { ReadVisualBasicImportsDebugInfo( symReader, methodToken, methodVersion, out importRecordGroups, out defaultNamespaceName); externAliasRecords = ImmutableArray <ExternAliasRecord> .Empty; } else { Debug.Assert(symbolProviderOpt != null); ReadCSharpNativeImportsInfo( symReader, symbolProviderOpt, methodToken, methodVersion, out importRecordGroups, out externAliasRecords); defaultNamespaceName = ""; } // VB should read hoisted scope information from local variables: var hoistedLocalScopeRecords = isVisualBasicMethod ? default(ImmutableArray <HoistedLocalScopeRecord>) : ImmutableArray <HoistedLocalScopeRecord> .Empty; ImmutableDictionary <int, ImmutableArray <bool> > dynamicLocalMap = null; ImmutableDictionary <string, ImmutableArray <bool> > dynamicLocalConstantMap = null; ImmutableDictionary <int, ImmutableArray <string> > tupleLocalMap = null; ImmutableDictionary <LocalNameAndScope, ImmutableArray <string> > tupleLocalConstantMap = null; byte[] customDebugInfo = symReader.GetCustomDebugInfoBytes(methodToken, methodVersion); if (customDebugInfo != null) { if (!isVisualBasicMethod) { var customDebugInfoRecord = CustomDebugInfoReader.TryGetCustomDebugInfoRecord(customDebugInfo, CustomDebugInfoKind.StateMachineHoistedLocalScopes); if (!customDebugInfoRecord.IsDefault) { hoistedLocalScopeRecords = CustomDebugInfoReader.DecodeStateMachineHoistedLocalScopesRecord(customDebugInfoRecord) .SelectAsArray(s => new HoistedLocalScopeRecord(s.StartOffset, s.Length)); } GetCSharpDynamicLocalInfo( customDebugInfo, allScopes, out dynamicLocalMap, out dynamicLocalConstantMap); } GetTupleElementNamesLocalInfo( customDebugInfo, out tupleLocalMap, out tupleLocalConstantMap); } var constantsBuilder = ArrayBuilder <TLocalSymbol> .GetInstance(); if (symbolProviderOpt != null) // TODO { GetConstants(constantsBuilder, symbolProviderOpt, containingScopes, dynamicLocalConstantMap, tupleLocalConstantMap); } var reuseSpan = GetReuseSpan(allScopes, ilOffset, isVisualBasicMethod); return(new MethodDebugInfo <TTypeSymbol, TLocalSymbol>( hoistedLocalScopeRecords, importRecordGroups, externAliasRecords, dynamicLocalMap, tupleLocalMap, defaultNamespaceName, containingScopes.GetLocalNames(), constantsBuilder.ToImmutableAndFree(), reuseSpan)); } catch (InvalidOperationException) { // bad CDI, ignore return(None); } finally { allScopes.Free(); containingScopes.Free(); } }
internal static ISymUnmanagedReader CreateReader(Stream pdb) { return(SymUnmanagedReaderExtensions.CreateReader(pdb, DummyMetadataImport.Instance)); }