PageRenderTime 59ms CodeModel.GetById 45ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/thirdparty/breakpad/google_breakpad/processor/source_line_resolver_base.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 118 lines | 45 code | 18 blank | 55 comment | 0 complexity | 1b8791dd0ef06ce4e204b6fafd824f8b MD5 | raw file
  1// Copyright (c) 2010 Google Inc.
  2// All rights reserved.
  3//
  4// Redistribution and use in source and binary forms, with or without
  5// modification, are permitted provided that the following conditions are
  6// met:
  7//
  8//     * Redistributions of source code must retain the above copyright
  9// notice, this list of conditions and the following disclaimer.
 10//     * Redistributions in binary form must reproduce the above
 11// copyright notice, this list of conditions and the following disclaimer
 12// in the documentation and/or other materials provided with the
 13// distribution.
 14//     * Neither the name of Google Inc. nor the names of its
 15// contributors may be used to endorse or promote products derived from
 16// this software without specific prior written permission.
 17//
 18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 29//
 30// source_line_resolver_base.h: SourceLineResolverBase, an (incomplete)
 31// implementation of SourceLineResolverInterface.  It serves as a common base
 32// class for concrete implementations: FastSourceLineResolver and
 33// BasicSourceLineResolver.  It is designed for refactoring that removes
 34// code redundancy in the two concrete source line resolver classes.
 35//
 36// See "google_breakpad/processor/source_line_resolver_interface.h" for more
 37// documentation.
 38
 39// Author: Siyang Xie (lambxsy@google.com)
 40
 41#ifndef GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_BASE_H__
 42#define GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_BASE_H__
 43
 44#include <map>
 45#include <string>
 46
 47#include "google_breakpad/processor/source_line_resolver_interface.h"
 48
 49namespace google_breakpad {
 50
 51using std::map;
 52
 53// Forward declaration.
 54// ModuleFactory is a simple factory interface for creating a Module instance
 55// at run-time.
 56class ModuleFactory;
 57
 58class SourceLineResolverBase : public SourceLineResolverInterface {
 59 public:
 60  // Read the symbol_data from a file with given file_name.
 61  // The part of code was originally in BasicSourceLineResolver::Module's
 62  // LoadMap() method.
 63  // Place dynamically allocated heap buffer in symbol_data. Caller has the
 64  // ownership of the buffer, and should call delete [] to free the buffer.
 65  static bool ReadSymbolFile(char **symbol_data, const string &file_name);
 66
 67 protected:
 68  // Users are not allowed create SourceLineResolverBase instance directly.
 69  SourceLineResolverBase(ModuleFactory *module_factory);
 70  virtual ~SourceLineResolverBase();
 71
 72  // Virtual methods inherited from SourceLineResolverInterface.
 73  virtual bool LoadModule(const CodeModule *module, const string &map_file);
 74  virtual bool LoadModuleUsingMapBuffer(const CodeModule *module,
 75                                        const string &map_buffer);
 76  virtual bool LoadModuleUsingMemoryBuffer(const CodeModule *module,
 77                                           char *memory_buffer);
 78  virtual bool ShouldDeleteMemoryBufferAfterLoadModule();
 79  virtual void UnloadModule(const CodeModule *module);
 80  virtual bool HasModule(const CodeModule *module);
 81  virtual void FillSourceLineInfo(StackFrame *frame);
 82  virtual WindowsFrameInfo *FindWindowsFrameInfo(const StackFrame *frame);
 83  virtual CFIFrameInfo *FindCFIFrameInfo(const StackFrame *frame);
 84
 85  // Nested structs and classes.
 86  struct Line;
 87  struct Function;
 88  struct PublicSymbol;
 89  struct CompareString {
 90    bool operator()(const string &s1, const string &s2) const;
 91  };
 92  // Module is an interface for an in-memory symbol file.
 93  class Module;
 94  class AutoFileCloser;
 95
 96  // All of the modules that are loaded.
 97  typedef map<string, Module*, CompareString> ModuleMap;
 98  ModuleMap *modules_;
 99
100  // All of heap-allocated buffers that are owned locally by resolver.
101  typedef std::map<string, char*, CompareString> MemoryMap;
102  MemoryMap *memory_buffers_;
103
104  // Creates a concrete module at run-time.
105  ModuleFactory *module_factory_;
106
107 private:
108  // ModuleFactory needs to have access to protected type Module.
109  friend class ModuleFactory;
110
111  // Disallow unwanted copy ctor and assignment operator
112  SourceLineResolverBase(const SourceLineResolverBase&);
113  void operator=(const SourceLineResolverBase&);
114};
115
116}  // namespace google_breakpad
117
118#endif  // GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_BASE_H__