1// -*- mode: C++ -*-
2
3// Copyright (c) 2010 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// Abstract interface to return function/file/line info for a memory address.
33
34#ifndef GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_INTERFACE_H__
35#define GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_INTERFACE_H__
36
37#include <deque>
38#include <memory>
39#include <string>
40#include <vector>
41
42#include "common/using_std_string.h"
43#include "google_breakpad/common/breakpad_types.h"
44#include "google_breakpad/processor/code_module.h"
45
46namespace google_breakpad {
47
48struct StackFrame;
49struct WindowsFrameInfo;
50class CFIFrameInfo;
51
52class SourceLineResolverInterface {
53 public:
54 typedef uint64_t MemAddr;
55
56 virtual ~SourceLineResolverInterface() {}
57
58 // Adds a module to this resolver, returning true on success.
59 //
60 // module should have at least the code_file, debug_file,
61 // and debug_identifier members populated.
62 //
63 // map_file should contain line/address mappings for this module.
64 virtual bool LoadModule(const CodeModule* module,
65 const string& map_file) = 0;
66 // Same as above, but takes the contents of a pre-read map buffer
67 virtual bool LoadModuleUsingMapBuffer(const CodeModule* module,
68 const string& map_buffer) = 0;
69
70 // Add an interface to load symbol using C-String data instead of string.
71 // This is useful in the optimization design for avoiding unnecessary copying
72 // of symbol data, in order to improve memory efficiency.
73 // LoadModuleUsingMemoryBuffer() does NOT take ownership of memory_buffer.
74 // LoadModuleUsingMemoryBuffer() null terminates the passed in buffer, if
75 // the last character is not a null terminator.
76 virtual bool LoadModuleUsingMemoryBuffer(const CodeModule* module,
77 char* memory_buffer,
78 size_t memory_buffer_size) = 0;
79
80 // Return true if the memory buffer should be deleted immediately after
81 // LoadModuleUsingMemoryBuffer(). Return false if the memory buffer has to be
82 // alive during the lifetime of the corresponding Module.
83 virtual bool ShouldDeleteMemoryBufferAfterLoadModule() = 0;
84
85 // Request that the specified module be unloaded from this resolver.
86 // A resolver may choose to ignore such a request.
87 virtual void UnloadModule(const CodeModule* module) = 0;
88
89 // Returns true if the module has been loaded.
90 virtual bool HasModule(const CodeModule* module) = 0;
91
92 // Returns true if the module has been loaded and it is corrupt.
93 virtual bool IsModuleCorrupt(const CodeModule* module) = 0;
94
95 // Fills in the function_base, function_name, source_file_name,
96 // and source_line fields of the StackFrame. The instruction and
97 // module_name fields must already be filled in. If inlined_frames is not
98 // nullptr, it will try to construct inlined frames by adding them into
99 // inlined_frames in an order from outermost frame to inner most frame.
100 virtual void FillSourceLineInfo(
101 StackFrame* frame,
102 std::deque<std::unique_ptr<StackFrame>>* inlined_frames) = 0;
103
104 // If Windows stack walking information is available covering
105 // FRAME's instruction address, return a WindowsFrameInfo structure
106 // describing it. If the information is not available, returns NULL.
107 // A NULL return value does not indicate an error. The caller takes
108 // ownership of any returned WindowsFrameInfo object.
109 virtual WindowsFrameInfo* FindWindowsFrameInfo(const StackFrame* frame) = 0;
110
111 // If CFI stack walking information is available covering ADDRESS,
112 // return a CFIFrameInfo structure describing it. If the information
113 // is not available, return NULL. The caller takes ownership of any
114 // returned CFIFrameInfo object.
115 virtual CFIFrameInfo* FindCFIFrameInfo(const StackFrame* frame) = 0;
116
117 protected:
118 // SourceLineResolverInterface cannot be instantiated except by subclasses
119 SourceLineResolverInterface() {}
120};
121
122} // namespace google_breakpad
123
124#endif // GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_INTERFACE_H__
125