OLD | NEW |
1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 #include "common/windows/pdb_source_line_writer.h" | 30 #include "common/windows/pdb_source_line_writer.h" |
31 | 31 |
32 #include <windows.h> | 32 #include <windows.h> |
33 #include <winnt.h> | 33 #include <winnt.h> |
34 #include <atlbase.h> | 34 #include <atlbase.h> |
35 #include <dia2.h> | 35 #include <dia2.h> |
| 36 #include <diacreate.h> |
36 #include <ImageHlp.h> | 37 #include <ImageHlp.h> |
37 #include <stdio.h> | 38 #include <stdio.h> |
38 | 39 |
39 #include <limits> | 40 #include <limits> |
40 #include <set> | 41 #include <set> |
41 | 42 |
42 #include "common/windows/dia_util.h" | 43 #include "common/windows/dia_util.h" |
43 #include "common/windows/guid_string.h" | 44 #include "common/windows/guid_string.h" |
44 #include "common/windows/string_utils-inl.h" | 45 #include "common/windows/string_utils-inl.h" |
45 | 46 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 ImageUnload(img_); | 115 ImageUnload(img_); |
115 } | 116 } |
116 | 117 |
117 operator PLOADED_IMAGE() { return img_; } | 118 operator PLOADED_IMAGE() { return img_; } |
118 PLOADED_IMAGE operator->() { return img_; } | 119 PLOADED_IMAGE operator->() { return img_; } |
119 | 120 |
120 private: | 121 private: |
121 PLOADED_IMAGE img_; | 122 PLOADED_IMAGE img_; |
122 }; | 123 }; |
123 | 124 |
| 125 bool CreateDiaDataSourceInstance(CComPtr<IDiaDataSource> &data_source) { |
| 126 if (SUCCEEDED(data_source.CoCreateInstance(CLSID_DiaSource))) { |
| 127 return true; |
| 128 } |
| 129 |
| 130 class DECLSPEC_UUID("B86AE24D-BF2F-4ac9-B5A2-34B14E4CE11D") DiaSource100; |
| 131 class DECLSPEC_UUID("761D3BCD-1304-41D5-94E8-EAC54E4AC172") DiaSource110; |
| 132 class DECLSPEC_UUID("3BFCEA48-620F-4B6B-81F7-B9AF75454C7D") DiaSource120; |
| 133 class DECLSPEC_UUID("E6756135-1E65-4D17-8576-610761398C3C") DiaSource140; |
| 134 |
| 135 // If the CoCreateInstance call above failed, msdia*.dll is not registered. |
| 136 // We can try loading the DLL corresponding to the #included DIA SDK, but |
| 137 // the DIA headers don't provide a version. Lets try to figure out which DIA |
| 138 // version we're compiling against by comparing CLSIDs. |
| 139 const wchar_t *msdia_dll = nullptr; |
| 140 if (CLSID_DiaSource == _uuidof(DiaSource100)) { |
| 141 msdia_dll = L"msdia100.dll"; |
| 142 } else if (CLSID_DiaSource == _uuidof(DiaSource110)) { |
| 143 msdia_dll = L"msdia110.dll"; |
| 144 } else if (CLSID_DiaSource == _uuidof(DiaSource120)) { |
| 145 msdia_dll = L"msdia120.dll"; |
| 146 } else if (CLSID_DiaSource == _uuidof(DiaSource140)) { |
| 147 msdia_dll = L"msdia140.dll"; |
| 148 } |
| 149 |
| 150 if (msdia_dll && |
| 151 SUCCEEDED(NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource, |
| 152 reinterpret_cast<void **>(&data_source)))) { |
| 153 return true; |
| 154 } |
| 155 |
| 156 return false; |
| 157 } |
| 158 |
124 } // namespace | 159 } // namespace |
125 | 160 |
126 PDBSourceLineWriter::PDBSourceLineWriter() : output_(NULL) { | 161 PDBSourceLineWriter::PDBSourceLineWriter() : output_(NULL) { |
127 } | 162 } |
128 | 163 |
129 PDBSourceLineWriter::~PDBSourceLineWriter() { | 164 PDBSourceLineWriter::~PDBSourceLineWriter() { |
130 } | 165 } |
131 | 166 |
132 bool PDBSourceLineWriter::SetCodeFile(const wstring &exe_file) { | 167 bool PDBSourceLineWriter::SetCodeFile(const wstring &exe_file) { |
133 if (code_file_.empty()) { | 168 if (code_file_.empty()) { |
134 code_file_ = exe_file; | 169 code_file_ = exe_file; |
135 return true; | 170 return true; |
136 } | 171 } |
137 // Setting a different code file path is an error. It is success only if the | 172 // Setting a different code file path is an error. It is success only if the |
138 // file paths are the same. | 173 // file paths are the same. |
139 return exe_file == code_file_; | 174 return exe_file == code_file_; |
140 } | 175 } |
141 | 176 |
142 bool PDBSourceLineWriter::Open(const wstring &file, FileFormat format) { | 177 bool PDBSourceLineWriter::Open(const wstring &file, FileFormat format) { |
143 Close(); | 178 Close(); |
144 code_file_.clear(); | 179 code_file_.clear(); |
145 | 180 |
146 if (FAILED(CoInitialize(NULL))) { | 181 if (FAILED(CoInitialize(NULL))) { |
147 fprintf(stderr, "CoInitialize failed\n"); | 182 fprintf(stderr, "CoInitialize failed\n"); |
148 return false; | 183 return false; |
149 } | 184 } |
150 | 185 |
151 CComPtr<IDiaDataSource> data_source; | 186 CComPtr<IDiaDataSource> data_source; |
152 if (FAILED(data_source.CoCreateInstance(CLSID_DiaSource))) { | 187 if (!CreateDiaDataSourceInstance(data_source)) { |
153 const int kGuidSize = 64; | 188 const int kGuidSize = 64; |
154 wchar_t classid[kGuidSize] = {0}; | 189 wchar_t classid[kGuidSize] = {0}; |
155 StringFromGUID2(CLSID_DiaSource, classid, kGuidSize); | 190 StringFromGUID2(CLSID_DiaSource, classid, kGuidSize); |
156 // vc80 uses bce36434-2c24-499e-bf49-8bd99b0eeb68. | |
157 // vc90 uses 4C41678E-887B-4365-A09E-925D28DB33C2. | |
158 // vc100 uses B86AE24D-BF2F-4AC9-B5A2-34B14E4CE11D. | |
159 fprintf(stderr, "CoCreateInstance CLSID_DiaSource %S failed " | 191 fprintf(stderr, "CoCreateInstance CLSID_DiaSource %S failed " |
160 "(msdia*.dll unregistered?)\n", classid); | 192 "(msdia*.dll unregistered?)\n", classid); |
161 return false; | 193 return false; |
162 } | 194 } |
163 | 195 |
164 switch (format) { | 196 switch (format) { |
165 case PDB_FILE: | 197 case PDB_FILE: |
166 if (FAILED(data_source->loadDataFromPdb(file.c_str()))) { | 198 if (FAILED(data_source->loadDataFromPdb(file.c_str()))) { |
167 fprintf(stderr, "loadDataFromPdb failed for %ws\n", file.c_str()); | 199 fprintf(stderr, "loadDataFromPdb failed for %ws\n", file.c_str()); |
168 return false; | 200 return false; |
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 // an old-style CodeView record if a real 128-bit GUID has its first 32 | 1350 // an old-style CodeView record if a real 128-bit GUID has its first 32 |
1319 // bits set the same as the module's signature (timestamp) and the rest of | 1351 // bits set the same as the module's signature (timestamp) and the rest of |
1320 // the GUID is set to 0. This is highly unlikely. | 1352 // the GUID is set to 0. This is highly unlikely. |
1321 | 1353 |
1322 GUID signature_guid = {signature}; // 0-initializes other members | 1354 GUID signature_guid = {signature}; // 0-initializes other members |
1323 *uses_guid = !IsEqualGUID(guid, signature_guid); | 1355 *uses_guid = !IsEqualGUID(guid, signature_guid); |
1324 return true; | 1356 return true; |
1325 } | 1357 } |
1326 | 1358 |
1327 } // namespace google_breakpad | 1359 } // namespace google_breakpad |
OLD | NEW |