xref: /aosp_15_r20/external/google-breakpad/src/google_breakpad/processor/stack_frame_symbolizer.h (revision 9712c20fc9bbfbac4935993a2ca0b3958c5adad2)
1 // -*- mode: C++ -*-
2 
3 // Copyright 2012 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 // Helper class that encapsulates the logic of how symbol supplier interacts
32 // with source line resolver to fill stack frame information.
33 
34 #ifndef GOOGLE_BREAKPAD_PROCESSOR_STACK_FRAME_SYMBOLIZER_H__
35 #define GOOGLE_BREAKPAD_PROCESSOR_STACK_FRAME_SYMBOLIZER_H__
36 
37 #include <deque>
38 #include <memory>
39 #include <set>
40 #include <string>
41 #include <vector>
42 
43 #include "common/using_std_string.h"
44 #include "google_breakpad/common/breakpad_types.h"
45 #include "google_breakpad/processor/code_module.h"
46 
47 namespace google_breakpad {
48 class CFIFrameInfo;
49 class CodeModules;
50 class SymbolSupplier;
51 class SourceLineResolverInterface;
52 struct StackFrame;
53 struct SystemInfo;
54 struct WindowsFrameInfo;
55 
56 class StackFrameSymbolizer {
57  public:
58   enum SymbolizerResult {
59     // Symbol data was found and successfully loaded in resolver.
60     // This does NOT guarantee source line info is found within symbol file.
61     kNoError,
62     // This indicates non-critical error, such as, no code module found for
63     // frame's instruction, no symbol file, or resolver failed to load symbol.
64     kError,
65     // This indicates error for which stack walk should be interrupted
66     // and retried in future.
67     kInterrupt,
68     // Symbol data was found and loaded in resolver however some corruptions
69     // were detected.
70     kWarningCorruptSymbols,
71   };
72 
73   StackFrameSymbolizer(SymbolSupplier* supplier,
74                        SourceLineResolverInterface* resolver);
75 
~StackFrameSymbolizer()76   virtual ~StackFrameSymbolizer() { }
77 
78   // Encapsulate the step of resolving source line info for a stack frame.
79   // "frame" must not be NULL.
80   virtual SymbolizerResult FillSourceLineInfo(
81       const CodeModules* modules,
82       const CodeModules* unloaded_modules,
83       const SystemInfo* system_info,
84       StackFrame* stack_frame,
85       std::deque<std::unique_ptr<StackFrame>>* inlined_frames);
86 
87   virtual WindowsFrameInfo* FindWindowsFrameInfo(const StackFrame* frame);
88 
89   virtual CFIFrameInfo* FindCFIFrameInfo(const StackFrame* frame);
90 
91   // Reset internal (locally owned) data as if the helper is re-instantiated.
92   // A typical case is to call Reset() after processing an individual report
93   // before start to process next one, in order to reset internal information
94   // about missing symbols found so far.
Reset()95   virtual void Reset() { no_symbol_modules_.clear(); }
96 
97   // Returns true if there is valid implementation for stack symbolization.
HasImplementation()98   virtual bool HasImplementation() { return resolver_ && supplier_; }
99 
resolver()100   SourceLineResolverInterface* resolver() { return resolver_; }
supplier()101   SymbolSupplier* supplier() { return supplier_; }
102 
103  protected:
104   SymbolSupplier* supplier_;
105   SourceLineResolverInterface* resolver_;
106   // A list of modules known to have symbols missing. This helps avoid
107   // repeated lookups for the missing symbols within one minidump.
108   std::set<string> no_symbol_modules_;
109 };
110 
111 }  // namespace google_breakpad
112 
113 #endif  // GOOGLE_BREAKPAD_PROCESSOR_STACK_FRAME_SYMBOLIZER_H__
114