/ src / google_breakpad / processor / basic_source_line_resolver.h
basic_source_line_resolver.h
  1  // Copyright 2010 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  // basic_source_line_resolver.h: BasicSourceLineResolver is derived from
 30  // SourceLineResolverBase, and is a concrete implementation of
 31  // SourceLineResolverInterface, using address map files produced by a
 32  // compatible writer, e.g. PDBSourceLineWriter.
 33  //
 34  // see "processor/source_line_resolver_base.h"
 35  // and "source_line_resolver_interface.h" for more documentation.
 36  
 37  #ifndef GOOGLE_BREAKPAD_PROCESSOR_BASIC_SOURCE_LINE_RESOLVER_H__
 38  #define GOOGLE_BREAKPAD_PROCESSOR_BASIC_SOURCE_LINE_RESOLVER_H__
 39  
 40  #include <map>
 41  #include <string>
 42  #include <vector>
 43  
 44  #include "common/using_std_string.h"
 45  #include "google_breakpad/processor/source_line_resolver_base.h"
 46  
 47  namespace google_breakpad {
 48  
 49  using std::map;
 50  
 51  class BasicSourceLineResolver : public SourceLineResolverBase {
 52   public:
 53    BasicSourceLineResolver();
 54    virtual ~BasicSourceLineResolver() { }
 55  
 56    using SourceLineResolverBase::LoadModule;
 57    using SourceLineResolverBase::LoadModuleUsingMapBuffer;
 58    using SourceLineResolverBase::LoadModuleUsingMemoryBuffer;
 59    using SourceLineResolverBase::ShouldDeleteMemoryBufferAfterLoadModule;
 60    using SourceLineResolverBase::UnloadModule;
 61    using SourceLineResolverBase::HasModule;
 62    using SourceLineResolverBase::IsModuleCorrupt;
 63    using SourceLineResolverBase::FillSourceLineInfo;
 64    using SourceLineResolverBase::FindWindowsFrameInfo;
 65    using SourceLineResolverBase::FindCFIFrameInfo;
 66  
 67   private:
 68    // friend declarations:
 69    friend class BasicModuleFactory;
 70    friend class ModuleComparer;
 71    friend class ModuleSerializer;
 72    template<class> friend class SimpleSerializer;
 73  
 74    // Function derives from SourceLineResolverBase::Function.
 75    struct Function;
 76    // Module implements SourceLineResolverBase::Module interface.
 77    class Module;
 78  
 79    // Disallow unwanted copy ctor and assignment operator
 80    BasicSourceLineResolver(const BasicSourceLineResolver&);
 81    void operator=(const BasicSourceLineResolver&);
 82  };
 83  
 84  // Helper class, containing useful methods for parsing of Breakpad symbol files.
 85  class SymbolParseHelper {
 86   public:
 87    using MemAddr = SourceLineResolverInterface::MemAddr;
 88  
 89    // Parses a |file_line| declaration.  Returns true on success.
 90    // Format: FILE <id> <filename>.
 91    // Notice, that this method modifies the input |file_line| which is why it
 92    // can't be const.  On success, <id>, and <filename> are stored in |*index|,
 93    // and |*filename|.  No allocation is done, |*filename| simply points inside
 94    // |file_line|.
 95    static bool ParseFile(char* file_line,   // in
 96                          long* index,       // out
 97                          char** filename);  // out
 98  
 99    // Parses a |inline_origin_line| declaration.  Returns true on success.
100    // Old Format: INLINE_ORIGIN <origin_id> <file_id> <name>.
101    // New Format: INLINE_ORIGIN <origin_id> <name>.
102    // Notice, that this method modifies the input |inline_origin_line| which is
103    // why it can't be const.  On success, <has_file_id>, <origin_id>, <file_id>
104    // and <name> are stored in |*has_file_id*|, |*origin_id|, |*file_id|, and
105    // |*name|.  No allocation is done, |*name| simply points inside
106    // |inline_origin_line|.
107    static bool ParseInlineOrigin(char* inline_origin_line,  // in
108                                  bool* has_file_id,       // out
109                                  long* origin_id,           // out
110                                  long* file_id,             // out
111                                  char** name);              // out
112  
113    // Parses a |inline| declaration.  Returns true on success.
114    // Old Format: INLINE <inline_nest_level> <call_site_line> <origin_id>
115    // [<address> <size>]+
116    // New Format: INLINE <inline_nest_level> <call_site_line> <call_site_file_id>
117    // <origin_id> [<address> <size>]+
118    // Notice, that this method modifies the input |inline|
119    // which is why it can't be const.  On success, <has_call_site_file_id>,
120    // <inline_nest_level>, <call_site_line> and <origin_id> are stored in
121    // |*has_call_site_file_id*|, |*inline_nest_level|, |*call_site_line|, and
122    // |*origin_id|, and all pairs of (<address>, <size>) are added into ranges.
123    static bool ParseInline(
124        char* inline_line,                                  // in
125        bool* has_call_site_file_id,                        // out
126        long* inline_nest_level,                            // out
127        long* call_site_line,                               // out
128        long* call_site_file_id,                            // out
129        long* origin_id,                                    // out
130        std::vector<std::pair<MemAddr, MemAddr>>* ranges);  // out
131  
132    // Parses a |function_line| declaration.  Returns true on success.
133    // Format:  FUNC [<multiple>] <address> <size> <stack_param_size> <name>.
134    // Notice, that this method modifies the input |function_line| which is why it
135    // can't be const.  On success, the presence of <multiple>, <address>, <size>,
136    // <stack_param_size>, and <name> are stored in |*is_multiple|, |*address|,
137    // |*size|, |*stack_param_size|, and |*name|.  No allocation is done, |*name|
138    // simply points inside |function_line|.
139    static bool ParseFunction(char* function_line,     // in
140                              bool* is_multiple,       // out
141                              uint64_t* address,       // out
142                              uint64_t* size,          // out
143                              long* stack_param_size,  // out
144                              char** name);            // out
145  
146    // Parses a |line| declaration.  Returns true on success.
147    // Format:  <address> <size> <line number> <source file id>
148    // Notice, that this method modifies the input |function_line| which is why
149    // it can't be const.  On success, <address>, <size>, <line number>, and
150    // <source file id> are stored in |*address|, |*size|, |*line_number|, and
151    // |*source_file|.
152    static bool ParseLine(char* line_line,     // in
153                          uint64_t* address,   // out
154                          uint64_t* size,      // out
155                          long* line_number,   // out
156                          long* source_file);  // out
157  
158    // Parses a |public_line| declaration.  Returns true on success.
159    // Format:  PUBLIC [<multiple>] <address> <stack_param_size> <name>
160    // Notice, that this method modifies the input |function_line| which is why
161    // it can't be const.  On success, the presence of <multiple>, <address>,
162    // <stack_param_size>, <name> are stored in |*is_multiple|, |*address|,
163    // |*stack_param_size|, and |*name|.  No allocation is done, |*name| simply
164    // points inside |public_line|.
165    static bool ParsePublicSymbol(char* public_line,       // in
166                                  bool* is_multiple,       // out
167                                  uint64_t* address,       // out
168                                  long* stack_param_size,  // out
169                                  char** name);            // out
170  
171   private:
172    // Used for success checks after strtoull and strtol.
173    static bool IsValidAfterNumber(char* after_number);
174  
175    // Only allow static methods.
176    SymbolParseHelper();
177    SymbolParseHelper(const SymbolParseHelper&);
178    void operator=(const SymbolParseHelper&);
179  };
180  
181  }  // namespace google_breakpad
182  
183  #endif  // GOOGLE_BREAKPAD_PROCESSOR_BASIC_SOURCE_LINE_RESOLVER_H__