• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 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 // basic_source_line_resolver.h: BasicSourceLineResolver is derived from
31 // SourceLineResolverBase, and is a concrete implementation of
32 // SourceLineResolverInterface, using address map files produced by a
33 // compatible writer, e.g. PDBSourceLineWriter.
34 //
35 // see "processor/source_line_resolver_base.h"
36 // and "source_line_resolver_interface.h" for more documentation.
37 
38 #ifndef GOOGLE_BREAKPAD_PROCESSOR_BASIC_SOURCE_LINE_RESOLVER_H__
39 #define GOOGLE_BREAKPAD_PROCESSOR_BASIC_SOURCE_LINE_RESOLVER_H__
40 
41 #include <map>
42 #include <string>
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();
~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   // Parses a |file_line| declaration.  Returns true on success.
88   // Format: FILE <id> <filename>.
89   // Notice, that this method modifies the input |file_line| which is why it
90   // can't be const.  On success, <id>, and <filename> are stored in |*index|,
91   // and |*filename|.  No allocation is done, |*filename| simply points inside
92   // |file_line|.
93   static bool ParseFile(char *file_line,   // in
94                         long *index,       // out
95                         char **filename);  // out
96 
97   // Parses a |function_line| declaration.  Returns true on success.
98   // Format:  FUNC [<multiple>] <address> <size> <stack_param_size> <name>.
99   // Notice, that this method modifies the input |function_line| which is why it
100   // can't be const.  On success, the presence of <multiple>, <address>, <size>,
101   // <stack_param_size>, and <name> are stored in |*is_multiple|, |*address|,
102   // |*size|, |*stack_param_size|, and |*name|.  No allocation is done, |*name|
103   // simply points inside |function_line|.
104   static bool ParseFunction(char *function_line,     // in
105                             bool *is_multiple,       // out
106                             uint64_t *address,       // out
107                             uint64_t *size,          // out
108                             long *stack_param_size,  // out
109                             char **name);            // out
110 
111   // Parses a |line| declaration.  Returns true on success.
112   // Format:  <address> <size> <line number> <source file id>
113   // Notice, that this method modifies the input |function_line| which is why
114   // it can't be const.  On success, <address>, <size>, <line number>, and
115   // <source file id> are stored in |*address|, |*size|, |*line_number|, and
116   // |*source_file|.
117   static bool ParseLine(char *line_line,     // in
118                         uint64_t *address,   // out
119                         uint64_t *size,      // out
120                         long *line_number,   // out
121                         long *source_file);  // out
122 
123   // Parses a |public_line| declaration.  Returns true on success.
124   // Format:  PUBLIC [<multiple>] <address> <stack_param_size> <name>
125   // Notice, that this method modifies the input |function_line| which is why
126   // it can't be const.  On success, the presence of <multiple>, <address>,
127   // <stack_param_size>, <name> are stored in |*is_multiple|, |*address|,
128   // |*stack_param_size|, and |*name|.  No allocation is done, |*name| simply
129   // points inside |public_line|.
130   static bool ParsePublicSymbol(char *public_line,       // in
131                                 bool *is_multiple,       // out
132                                 uint64_t *address,       // out
133                                 long *stack_param_size,  // out
134                                 char **name);            // out
135 
136  private:
137   // Used for success checks after strtoull and strtol.
138   static bool IsValidAfterNumber(char *after_number);
139 
140   // Only allow static methods.
141   SymbolParseHelper();
142   SymbolParseHelper(const SymbolParseHelper&);
143   void operator=(const SymbolParseHelper&);
144 };
145 
146 }  // namespace google_breakpad
147 
148 #endif  // GOOGLE_BREAKPAD_PROCESSOR_BASIC_SOURCE_LINE_RESOLVER_H__
149