• 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 <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, <address>, <size>, <stack_param_size>, and
101   // <name> are stored in |*address|, |*size|, |*stack_param_size|, and |*name|.
102   // No allocation is done, |*name| simply points inside |function_line|.
103   static bool ParseFunction(char *function_line,     // in
104                             uint64_t *address,       // out
105                             uint64_t *size,          // out
106                             long *stack_param_size,  // out
107                             char **name);            // out
108 
109   // Parses a |line| declaration.  Returns true on success.
110   // Format:  <address> <size> <line number> <source file id>
111   // Notice, that this method modifies the input |function_line| which is why
112   // it can't be const.  On success, <address>, <size>, <line number>, and
113   // <source file id> are stored in |*address|, |*size|, |*line_number|, and
114   // |*source_file|.
115   static bool ParseLine(char *line_line,     // in
116                         uint64_t *address,   // out
117                         uint64_t *size,      // out
118                         long *line_number,   // out
119                         long *source_file);  // out
120 
121   // Parses a |public_line| declaration.  Returns true on success.
122   // Format:  PUBLIC <address> <stack_param_size> <name>
123   // Notice, that this method modifies the input |function_line| which is why
124   // it can't be const.  On success, <address>, <stack_param_size>, <name>
125   // are stored in |*address|, |*stack_param_size|, and |*name|.
126   // No allocation is done, |*name| simply points inside |public_line|.
127   static bool ParsePublicSymbol(char *public_line,       // in
128                                 uint64_t *address,       // out
129                                 long *stack_param_size,  // out
130                                 char **name);            // out
131 
132  private:
133   // Used for success checks after strtoull and strtol.
134   static bool IsValidAfterNumber(char *after_number);
135 
136   // Only allow static methods.
137   SymbolParseHelper();
138   SymbolParseHelper(const SymbolParseHelper&);
139   void operator=(const SymbolParseHelper&);
140 };
141 
142 }  // namespace google_breakpad
143 
144 #endif  // GOOGLE_BREAKPAD_PROCESSOR_BASIC_SOURCE_LINE_RESOLVER_H__
145