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