• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // -*- mode: C++ -*-
2 
3 // Copyright (c) 2012 Google Inc.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 //     * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //     * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 //     * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 // Helper class that encapsulates the logic of how symbol supplier interacts
33 // with source line resolver to fill stack frame information.
34 
35 #ifndef GOOGLE_BREAKPAD_PROCESSOR_STACK_FRAME_SYMBOLIZER_H__
36 #define GOOGLE_BREAKPAD_PROCESSOR_STACK_FRAME_SYMBOLIZER_H__
37 
38 #include <set>
39 #include <string>
40 
41 #include "common/using_std_string.h"
42 #include "google_breakpad/common/breakpad_types.h"
43 #include "google_breakpad/processor/code_module.h"
44 
45 namespace google_breakpad {
46 class CFIFrameInfo;
47 class CodeModules;
48 class SymbolSupplier;
49 class SourceLineResolverInterface;
50 struct StackFrame;
51 struct SystemInfo;
52 struct WindowsFrameInfo;
53 
54 class StackFrameSymbolizer {
55  public:
56   enum SymbolizerResult {
57     // Symbol data was found and successfully loaded in resolver.
58     // This does NOT guarantee source line info is found within symbol file.
59     kNoError,
60     // This indicates non-critical error, such as, no code module found for
61     // frame's instruction, no symbol file, or resolver failed to load symbol.
62     kError,
63     // This indicates error for which stack walk should be interrupted
64     // and retried in future.
65     kInterrupt,
66     // Symbol data was found and loaded in resolver however some corruptions
67     // were detected.
68     kWarningCorruptSymbols,
69   };
70 
71   StackFrameSymbolizer(SymbolSupplier* supplier,
72                        SourceLineResolverInterface* resolver);
73 
~StackFrameSymbolizer()74   virtual ~StackFrameSymbolizer() { }
75 
76   // Encapsulate the step of resolving source line info for a stack frame.
77   // "frame" must not be NULL.
78   virtual SymbolizerResult FillSourceLineInfo(const CodeModules* modules,
79                                               const SystemInfo* system_info,
80                                               StackFrame* stack_frame);
81 
82   virtual WindowsFrameInfo* FindWindowsFrameInfo(const StackFrame* frame);
83 
84   virtual CFIFrameInfo* FindCFIFrameInfo(const StackFrame* frame);
85 
86   // Reset internal (locally owned) data as if the helper is re-instantiated.
87   // A typical case is to call Reset() after processing an individual report
88   // before start to process next one, in order to reset internal information
89   // about missing symbols found so far.
Reset()90   virtual void Reset() { no_symbol_modules_.clear(); }
91 
92   // Returns true if there is valid implementation for stack symbolization.
HasImplementation()93   virtual bool HasImplementation() { return resolver_ && supplier_; }
94 
resolver()95   SourceLineResolverInterface* resolver() { return resolver_; }
supplier()96   SymbolSupplier* supplier() { return supplier_; }
97 
98  protected:
99   SymbolSupplier* supplier_;
100   SourceLineResolverInterface* resolver_;
101   // A list of modules known to have symbols missing. This helps avoid
102   // repeated lookups for the missing symbols within one minidump.
103   std::set<string> no_symbol_modules_;
104 };
105 
106 }  // namespace google_breakpad
107 
108 #endif  // GOOGLE_BREAKPAD_PROCESSOR_STACK_FRAME_SYMBOLIZER_H__
109