/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. // Author: Siyang Xie (lambxsy@google.com)
  39. #ifndef GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_BASE_H__
  40. #define GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_BASE_H__
  41. #include <map>
  42. #include <string>
  43. #include "google_breakpad/processor/source_line_resolver_interface.h"
  44. namespace google_breakpad {
  45. using std::map;
  46. // Forward declaration.
  47. // ModuleFactory is a simple factory interface for creating a Module instance
  48. // at run-time.
  49. class ModuleFactory;
  50. class SourceLineResolverBase : public SourceLineResolverInterface {
  51. public:
  52. // Read the symbol_data from a file with given file_name.
  53. // The part of code was originally in BasicSourceLineResolver::Module's
  54. // LoadMap() method.
  55. // Place dynamically allocated heap buffer in symbol_data. Caller has the
  56. // ownership of the buffer, and should call delete [] to free the buffer.
  57. static bool ReadSymbolFile(char **symbol_data, const string &file_name);
  58. protected:
  59. // Users are not allowed create SourceLineResolverBase instance directly.
  60. SourceLineResolverBase(ModuleFactory *module_factory);
  61. virtual ~SourceLineResolverBase();
  62. // Virtual methods inherited from SourceLineResolverInterface.
  63. virtual bool LoadModule(const CodeModule *module, const string &map_file);
  64. virtual bool LoadModuleUsingMapBuffer(const CodeModule *module,
  65. const string &map_buffer);
  66. virtual bool LoadModuleUsingMemoryBuffer(const CodeModule *module,
  67. char *memory_buffer);
  68. virtual bool ShouldDeleteMemoryBufferAfterLoadModule();
  69. virtual void UnloadModule(const CodeModule *module);
  70. virtual bool HasModule(const CodeModule *module);
  71. virtual void FillSourceLineInfo(StackFrame *frame);
  72. virtual WindowsFrameInfo *FindWindowsFrameInfo(const StackFrame *frame);
  73. virtual CFIFrameInfo *FindCFIFrameInfo(const StackFrame *frame);
  74. // Nested structs and classes.
  75. struct Line;
  76. struct Function;
  77. struct PublicSymbol;
  78. struct CompareString {
  79. bool operator()(const string &s1, const string &s2) const;
  80. };
  81. // Module is an interface for an in-memory symbol file.
  82. class Module;
  83. class AutoFileCloser;
  84. // All of the modules that are loaded.
  85. typedef map<string, Module*, CompareString> ModuleMap;
  86. ModuleMap *modules_;
  87. // All of heap-allocated buffers that are owned locally by resolver.
  88. typedef std::map<string, char*, CompareString> MemoryMap;
  89. MemoryMap *memory_buffers_;
  90. // Creates a concrete module at run-time.
  91. ModuleFactory *module_factory_;
  92. private:
  93. // ModuleFactory needs to have access to protected type Module.
  94. friend class ModuleFactory;
  95. // Disallow unwanted copy ctor and assignment operator
  96. SourceLineResolverBase(const SourceLineResolverBase&);
  97. void operator=(const SourceLineResolverBase&);
  98. };
  99. } // namespace google_breakpad
  100. #endif // GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_BASE_H__