1 // Copyright (c) 2019, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //     * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //     * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //     * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 
30 #include "common/windows/pe_source_line_writer.h"
31 
32 #include "common/windows/pe_util.h"
33 
34 namespace google_breakpad {
PESourceLineWriter(const wstring & pe_file)35 PESourceLineWriter::PESourceLineWriter(const wstring& pe_file) :
36   pe_file_(pe_file) {
37 }
38 
~PESourceLineWriter()39 PESourceLineWriter::~PESourceLineWriter() {
40 }
41 
WriteSymbols(FILE * symbol_file)42 bool PESourceLineWriter::WriteSymbols(FILE* symbol_file) {
43   PDBModuleInfo module_info;
44   if (!GetModuleInfo(&module_info)) {
45     return false;
46   }
47   // Hard-code "windows" for the OS because that's the only thing that makes
48   // sense for PDB files.  (This might not be strictly correct for Windows CE
49   // support, but we don't care about that at the moment.)
50   fprintf(symbol_file, "MODULE windows %ws %ws %ws\n",
51     module_info.cpu.c_str(), module_info.debug_identifier.c_str(),
52     module_info.debug_file.c_str());
53 
54   PEModuleInfo pe_info;
55   if (!GetPEInfo(&pe_info)) {
56     return false;
57   }
58   fprintf(symbol_file, "INFO CODE_ID %ws %ws\n",
59     pe_info.code_identifier.c_str(),
60     pe_info.code_file.c_str());
61 
62   if (!PrintPEFrameData(pe_file_, symbol_file)) {
63     return false;
64   }
65 
66   return true;
67 }
68 
GetModuleInfo(PDBModuleInfo * info)69 bool PESourceLineWriter::GetModuleInfo(PDBModuleInfo* info) {
70   return ReadModuleInfo(pe_file_, info);
71 }
72 
GetPEInfo(PEModuleInfo * info)73 bool PESourceLineWriter::GetPEInfo(PEModuleInfo* info) {
74   return ReadPEInfo(pe_file_, info);
75 }
76 
77 }  // namespace google_breakpad
78