| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | // =========================================================================== |
| 5 | // File: symbinder.cpp |
| 6 | // |
| 7 | |
| 8 | // =========================================================================== |
| 9 | |
| 10 | #include "pch.h" |
| 11 | #include "symbinder.h" |
| 12 | |
| 13 | /* ------------------------------------------------------------------------- * |
| 14 | * SymBinder class |
| 15 | * ------------------------------------------------------------------------- */ |
| 16 | |
| 17 | HRESULT |
| 18 | SymBinder::QueryInterface( |
| 19 | REFIID riid, |
| 20 | void **ppvObject |
| 21 | ) |
| 22 | { |
| 23 | HRESULT hr = S_OK; |
| 24 | |
| 25 | _ASSERTE(IsValidIID(riid)); |
| 26 | _ASSERTE(IsValidWritePtr(ppvObject, void*)); |
| 27 | |
| 28 | IfFalseGo( ppvObject, E_INVALIDARG ); |
| 29 | |
| 30 | if (riid == IID_ISymUnmanagedBinder) |
| 31 | { |
| 32 | *ppvObject = (ISymUnmanagedBinder*) this; |
| 33 | } |
| 34 | else if (riid == IID_ISymUnmanagedBinder2) |
| 35 | { |
| 36 | *ppvObject = (ISymUnmanagedBinder2*) this; |
| 37 | } |
| 38 | else if (riid == IID_IUnknown) |
| 39 | { |
| 40 | *ppvObject = (IUnknown*)this; |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | *ppvObject = NULL; |
| 45 | hr = E_NOINTERFACE; |
| 46 | } |
| 47 | |
| 48 | if (*ppvObject) |
| 49 | { |
| 50 | AddRef(); |
| 51 | } |
| 52 | |
| 53 | ErrExit: |
| 54 | |
| 55 | return hr; |
| 56 | } |
| 57 | |
| 58 | HRESULT |
| 59 | SymBinder::NewSymBinder( |
| 60 | REFCLSID clsid, |
| 61 | void** ppObj |
| 62 | ) |
| 63 | { |
| 64 | HRESULT hr = S_OK; |
| 65 | SymBinder* pSymBinder = NULL; |
| 66 | |
| 67 | _ASSERTE(IsValidCLSID(clsid)); |
| 68 | _ASSERTE(IsValidWritePtr(ppObj, IUnknown*)); |
| 69 | |
| 70 | if (clsid != IID_ISymUnmanagedBinder) |
| 71 | return (E_UNEXPECTED); |
| 72 | |
| 73 | IfFalseGo( ppObj, E_INVALIDARG ); |
| 74 | |
| 75 | *ppObj = NULL; |
| 76 | |
| 77 | IfNullGo( pSymBinder = NEW(SymBinder()) ); |
| 78 | *ppObj = pSymBinder; |
| 79 | pSymBinder->AddRef(); |
| 80 | pSymBinder = NULL; |
| 81 | |
| 82 | ErrExit: |
| 83 | |
| 84 | RELEASE( pSymBinder ); |
| 85 | |
| 86 | return hr; |
| 87 | } |
| 88 | |
| 89 | //----------------------------------------------------------- |
| 90 | // GetReaderForFile |
| 91 | //----------------------------------------------------------- |
| 92 | HRESULT |
| 93 | SymBinder::GetReaderForFile( |
| 94 | IUnknown *importer, // IMetaDataImporter |
| 95 | const WCHAR *fileName, // File we're looking symbols for |
| 96 | const WCHAR *searchPath, // Search path for file |
| 97 | ISymUnmanagedReader **ppRetVal) // Out: SymReader for file |
| 98 | { |
| 99 | HRESULT hr = S_OK; |
| 100 | ISymUnmanagedReader *pSymReader = NULL; |
| 101 | IfFalseGo( ppRetVal && fileName && fileName[0] != '\0', E_INVALIDARG ); |
| 102 | |
| 103 | // Init Out parameter |
| 104 | *ppRetVal = NULL; |
| 105 | |
| 106 | // Call the class factory directly. |
| 107 | IfFailGo(IldbSymbolsCreateInstance(CLSID_CorSymReader_SxS, |
| 108 | IID_ISymUnmanagedReader, |
| 109 | (void**)&pSymReader)); |
| 110 | |
| 111 | IfFailGo(pSymReader->Initialize(importer, fileName, searchPath, NULL)); |
| 112 | |
| 113 | // Transfer ownership to the out parameter |
| 114 | *ppRetVal = pSymReader; |
| 115 | pSymReader = NULL; |
| 116 | |
| 117 | ErrExit: |
| 118 | RELEASE(pSymReader); |
| 119 | return hr; |
| 120 | } |
| 121 | |
| 122 | HRESULT |
| 123 | SymBinder::GetReaderFromStream( |
| 124 | IUnknown *importer, |
| 125 | IStream *pStream, |
| 126 | ISymUnmanagedReader **ppRetVal |
| 127 | ) |
| 128 | { |
| 129 | HRESULT hr = S_OK; |
| 130 | ISymUnmanagedReader *pSymReader = NULL; |
| 131 | IfFalseGo( ppRetVal && importer && pStream, E_INVALIDARG ); |
| 132 | |
| 133 | // Init Out parameter |
| 134 | *ppRetVal = NULL; |
| 135 | |
| 136 | // Call the class factory directly |
| 137 | IfFailGo(IldbSymbolsCreateInstance(CLSID_CorSymReader_SxS, |
| 138 | IID_ISymUnmanagedReader, |
| 139 | (void**)&pSymReader)); |
| 140 | |
| 141 | IfFailGo(pSymReader->Initialize(importer, NULL, NULL, pStream)); |
| 142 | |
| 143 | // Transfer ownership to the out parameter |
| 144 | *ppRetVal = pSymReader; |
| 145 | pSymReader = NULL; |
| 146 | |
| 147 | ErrExit: |
| 148 | RELEASE(pSymReader); |
| 149 | return hr; |
| 150 | } |
| 151 | |
| 152 | HRESULT SymBinder::GetReaderForFile2( |
| 153 | IUnknown *importer, |
| 154 | const WCHAR *fileName, |
| 155 | const WCHAR *searchPath, |
| 156 | ULONG32 searchPolicy, |
| 157 | ISymUnmanagedReader **pRetVal) |
| 158 | { |
| 159 | // This API exists just to allow VS to function properly. |
| 160 | // ILDB doesn't support any search policy or search path - we only look |
| 161 | // next to the image file. |
| 162 | return GetReaderForFile(importer, fileName, searchPath, pRetVal); |
| 163 | } |
| 164 | |