pdb_source_line_writer.h revision 8b1645d8cdb34035c0b132fe8b574bc5ee48fb62
1// Copyright (c) 2006, 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// PDBSourceLineWriter uses a pdb file produced by Visual C++ to output 31// a line/address map for use with SourceLineResolver. 32 33#ifndef _PDB_SOURCE_LINE_WRITER_H__ 34#define _PDB_SOURCE_LINE_WRITER_H__ 35 36#include <string> 37#include <atlcomcli.h> 38 39struct IDiaEnumLineNumbers; 40struct IDiaSession; 41struct IDiaSymbol; 42 43namespace google_airbag { 44 45using std::wstring; 46 47class PDBSourceLineWriter { 48 public: 49 enum FileFormat { 50 PDB_FILE, // a .pdb file containing debug symbols 51 EXE_FILE, // a .exe or .dll file 52 }; 53 54 explicit PDBSourceLineWriter(); 55 ~PDBSourceLineWriter(); 56 57 // Opens the given file. For executable files, the corresponding pdb 58 // file must be available; Open will be if it is not. 59 // If there is already a pdb file open, it is automatically closed. 60 // Returns true on success. 61 bool Open(const wstring &file, FileFormat format); 62 63 // Locates the pdb file for the given executable (exe or dll) file, 64 // and opens it. If there is already a pdb file open, it is automatically 65 // closed. Returns true on success. 66 bool OpenExecutable(const wstring &exe_file); 67 68 // Writes a map file from the current pdb file to the given file stream. 69 // Returns true on success. 70 bool WriteMap(FILE *map_file); 71 72 // Closes the current pdb file and its associated resources. 73 void Close(); 74 75 // Returns the GUID for the module, as a string, 76 // e.g. "11111111-2222-3333-4444-555555555555". 77 wstring GetModuleGUID(); 78 79 private: 80 // Outputs the line/address pairs for each line in the enumerator. 81 // Returns true on success. 82 bool PrintLines(IDiaEnumLineNumbers *lines); 83 84 // Outputs a function address and name, followed by its source line list. 85 // Returns true on success. 86 bool PrintFunction(IDiaSymbol *function); 87 88 // Outputs all functions as described above. Returns true on success. 89 bool PrintFunctions(); 90 91 // Outputs all of the source files in the session's pdb file. 92 // Returns true on success. 93 bool PrintSourceFiles(); 94 95 // Outputs all of the frame information necessary to construct stack 96 // backtraces in the absence of frame pointers. Returns true on success. 97 bool PrintFrameData(); 98 99 // The session for the currently-open pdb file. 100 CComPtr<IDiaSession> session_; 101 102 // The current output file for this WriteMap invocation. 103 FILE *output_; 104 105 // Disallow copy ctor and operator= 106 PDBSourceLineWriter(const PDBSourceLineWriter&); 107 void operator=(const PDBSourceLineWriter&); 108}; 109 110} // namespace google_airbag 111 112#endif // _PDB_SOURCE_LINE_WRITER_H__ 113