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