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