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