1*9712c20fSFrederick Mayle // -*- mode: c++ -*- 2*9712c20fSFrederick Mayle 3*9712c20fSFrederick Mayle // Copyright 2011 Google LLC 4*9712c20fSFrederick Mayle // 5*9712c20fSFrederick Mayle // Redistribution and use in source and binary forms, with or without 6*9712c20fSFrederick Mayle // modification, are permitted provided that the following conditions are 7*9712c20fSFrederick Mayle // met: 8*9712c20fSFrederick Mayle // 9*9712c20fSFrederick Mayle // * Redistributions of source code must retain the above copyright 10*9712c20fSFrederick Mayle // notice, this list of conditions and the following disclaimer. 11*9712c20fSFrederick Mayle // * Redistributions in binary form must reproduce the above 12*9712c20fSFrederick Mayle // copyright notice, this list of conditions and the following disclaimer 13*9712c20fSFrederick Mayle // in the documentation and/or other materials provided with the 14*9712c20fSFrederick Mayle // distribution. 15*9712c20fSFrederick Mayle // * Neither the name of Google LLC nor the names of its 16*9712c20fSFrederick Mayle // contributors may be used to endorse or promote products derived from 17*9712c20fSFrederick Mayle // this software without specific prior written permission. 18*9712c20fSFrederick Mayle // 19*9712c20fSFrederick Mayle // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20*9712c20fSFrederick Mayle // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21*9712c20fSFrederick Mayle // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22*9712c20fSFrederick Mayle // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23*9712c20fSFrederick Mayle // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24*9712c20fSFrederick Mayle // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25*9712c20fSFrederick Mayle // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26*9712c20fSFrederick Mayle // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27*9712c20fSFrederick Mayle // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28*9712c20fSFrederick Mayle // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29*9712c20fSFrederick Mayle // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30*9712c20fSFrederick Mayle 31*9712c20fSFrederick Mayle // dump_symbols.h: Read debugging information from an ELF file, and write 32*9712c20fSFrederick Mayle // it out as a Breakpad symbol file. 33*9712c20fSFrederick Mayle 34*9712c20fSFrederick Mayle #ifndef COMMON_LINUX_DUMP_SYMBOLS_H__ 35*9712c20fSFrederick Mayle #define COMMON_LINUX_DUMP_SYMBOLS_H__ 36*9712c20fSFrederick Mayle 37*9712c20fSFrederick Mayle #include <iostream> 38*9712c20fSFrederick Mayle #include <string> 39*9712c20fSFrederick Mayle #include <vector> 40*9712c20fSFrederick Mayle 41*9712c20fSFrederick Mayle #include "common/symbol_data.h" 42*9712c20fSFrederick Mayle #include "common/using_std_string.h" 43*9712c20fSFrederick Mayle 44*9712c20fSFrederick Mayle namespace google_breakpad { 45*9712c20fSFrederick Mayle 46*9712c20fSFrederick Mayle class Module; 47*9712c20fSFrederick Mayle 48*9712c20fSFrederick Mayle struct DumpOptions { DumpOptionsDumpOptions49*9712c20fSFrederick Mayle DumpOptions(SymbolData symbol_data, 50*9712c20fSFrederick Mayle bool handle_inter_cu_refs, 51*9712c20fSFrederick Mayle bool enable_multiple_field) 52*9712c20fSFrederick Mayle : symbol_data(symbol_data), 53*9712c20fSFrederick Mayle handle_inter_cu_refs(handle_inter_cu_refs), 54*9712c20fSFrederick Mayle enable_multiple_field(enable_multiple_field) {} 55*9712c20fSFrederick Mayle 56*9712c20fSFrederick Mayle SymbolData symbol_data; 57*9712c20fSFrederick Mayle bool handle_inter_cu_refs; 58*9712c20fSFrederick Mayle bool enable_multiple_field; 59*9712c20fSFrederick Mayle }; 60*9712c20fSFrederick Mayle 61*9712c20fSFrederick Mayle // Find all the debugging information in OBJ_FILE, an ELF executable 62*9712c20fSFrederick Mayle // or shared library, and write it to SYM_STREAM in the Breakpad symbol 63*9712c20fSFrederick Mayle // file format. 64*9712c20fSFrederick Mayle // If OBJ_FILE has been stripped but contains a .gnu_debuglink section, 65*9712c20fSFrederick Mayle // then look for the debug file in DEBUG_DIRS. 66*9712c20fSFrederick Mayle // SYMBOL_DATA allows limiting the type of symbol data written. 67*9712c20fSFrederick Mayle bool WriteSymbolFile(const string& load_path, 68*9712c20fSFrederick Mayle const string& obj_file, 69*9712c20fSFrederick Mayle const string& obj_os, 70*9712c20fSFrederick Mayle const std::vector<string>& debug_dirs, 71*9712c20fSFrederick Mayle const DumpOptions& options, 72*9712c20fSFrederick Mayle std::ostream& sym_stream); 73*9712c20fSFrederick Mayle 74*9712c20fSFrederick Mayle // Read the selected object file's debugging information, and write out the 75*9712c20fSFrederick Mayle // header only to |stream|. Return true on success; if an error occurs, report 76*9712c20fSFrederick Mayle // it and return false. |obj_file| becomes the MODULE file name and |obj_os| 77*9712c20fSFrederick Mayle // becomes the MODULE operating system. 78*9712c20fSFrederick Mayle bool WriteSymbolFileHeader(const string& load_path, 79*9712c20fSFrederick Mayle const string& obj_file, 80*9712c20fSFrederick Mayle const string& obj_os, 81*9712c20fSFrederick Mayle std::ostream& sym_stream); 82*9712c20fSFrederick Mayle 83*9712c20fSFrederick Mayle // As above, but simply return the debugging information in MODULE 84*9712c20fSFrederick Mayle // instead of writing it to a stream. The caller owns the resulting 85*9712c20fSFrederick Mayle // Module object and must delete it when finished. 86*9712c20fSFrederick Mayle bool ReadSymbolData(const string& load_path, 87*9712c20fSFrederick Mayle const string& obj_file, 88*9712c20fSFrederick Mayle const string& obj_os, 89*9712c20fSFrederick Mayle const std::vector<string>& debug_dirs, 90*9712c20fSFrederick Mayle const DumpOptions& options, 91*9712c20fSFrederick Mayle Module** module); 92*9712c20fSFrederick Mayle 93*9712c20fSFrederick Mayle } // namespace google_breakpad 94*9712c20fSFrederick Mayle 95*9712c20fSFrederick Mayle #endif // COMMON_LINUX_DUMP_SYMBOLS_H__ 96