/thirdparty/breakpad/processor/fast_source_line_resolver_types.h

http://github.com/tomahawk-player/tomahawk · C Header · 179 lines · 85 code · 25 blank · 69 comment · 0 complexity · 0874fc13bb70a6e488d0658543519d01 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. // fast_source_line_resolver_types.h: definition of nested classes/structs in
  31. // FastSourceLineResolver. It moves the definitions out of
  32. // fast_source_line_resolver.cc, so that other classes could have access
  33. // to these private nested types without including fast_source_line_resolver.cc
  34. //
  35. // Author: lambxsy@google.com (Siyang Xie)
  36. #ifndef PROCESSOR_FAST_SOURCE_LINE_RESOLVER_TYPES_H__
  37. #define PROCESSOR_FAST_SOURCE_LINE_RESOLVER_TYPES_H__
  38. #include "google_breakpad/processor/fast_source_line_resolver.h"
  39. #include "processor/source_line_resolver_base_types.h"
  40. #include <map>
  41. #include <string>
  42. #include "google_breakpad/processor/stack_frame.h"
  43. #include "processor/cfi_frame_info.h"
  44. #include "processor/static_address_map-inl.h"
  45. #include "processor/static_contained_range_map-inl.h"
  46. #include "processor/static_map.h"
  47. #include "processor/static_range_map-inl.h"
  48. #include "processor/windows_frame_info.h"
  49. namespace google_breakpad {
  50. struct FastSourceLineResolver::Line : public SourceLineResolverBase::Line {
  51. void CopyFrom(const Line *line_ptr) {
  52. const char *raw = reinterpret_cast<const char*>(line_ptr);
  53. CopyFrom(raw);
  54. }
  55. // De-serialize the memory data of a Line.
  56. void CopyFrom(const char *raw) {
  57. address = *(reinterpret_cast<const MemAddr*>(raw));
  58. size = *(reinterpret_cast<const MemAddr*>(raw + sizeof(address)));
  59. source_file_id = *(reinterpret_cast<const int32_t *>(
  60. raw + 2 * sizeof(address)));
  61. line = *(reinterpret_cast<const int32_t*>(
  62. raw + 2 * sizeof(address) + sizeof(source_file_id)));
  63. }
  64. };
  65. struct FastSourceLineResolver::Function :
  66. public SourceLineResolverBase::Function {
  67. void CopyFrom(const Function *func_ptr) {
  68. const char *raw = reinterpret_cast<const char*>(func_ptr);
  69. CopyFrom(raw);
  70. }
  71. // De-serialize the memory data of a Function.
  72. void CopyFrom(const char *raw) {
  73. size_t name_size = strlen(raw) + 1;
  74. name = raw;
  75. address = *(reinterpret_cast<const MemAddr*>(raw + name_size));
  76. size = *(reinterpret_cast<const MemAddr*>(
  77. raw + name_size + sizeof(MemAddr)));
  78. parameter_size = *(reinterpret_cast<const int32_t*>(
  79. raw + name_size + 2 * sizeof(MemAddr)));
  80. lines = StaticRangeMap<MemAddr, Line>(
  81. raw + name_size + 2 * sizeof(MemAddr) + sizeof(int32_t));
  82. }
  83. StaticRangeMap<MemAddr, Line> lines;
  84. };
  85. struct FastSourceLineResolver::PublicSymbol :
  86. public SourceLineResolverBase::PublicSymbol {
  87. void CopyFrom(const PublicSymbol *public_symbol_ptr) {
  88. const char *raw = reinterpret_cast<const char*>(public_symbol_ptr);
  89. CopyFrom(raw);
  90. }
  91. // De-serialize the memory data of a PublicSymbol.
  92. void CopyFrom(const char *raw) {
  93. size_t name_size = strlen(raw) + 1;
  94. name = raw;
  95. address = *(reinterpret_cast<const MemAddr*>(raw + name_size));
  96. parameter_size = *(reinterpret_cast<const int32_t*>(
  97. raw + name_size + sizeof(MemAddr)));
  98. }
  99. };
  100. class FastSourceLineResolver::Module: public SourceLineResolverBase::Module {
  101. public:
  102. explicit Module(const string &name) : name_(name) { }
  103. virtual ~Module() { }
  104. // Looks up the given relative address, and fills the StackFrame struct
  105. // with the result.
  106. virtual void LookupAddress(StackFrame *frame) const;
  107. // Loads a map from the given buffer in char* type.
  108. virtual bool LoadMapFromMemory(char *memory_buffer);
  109. // If Windows stack walking information is available covering ADDRESS,
  110. // return a WindowsFrameInfo structure describing it. If the information
  111. // is not available, returns NULL. A NULL return value does not indicate
  112. // an error. The caller takes ownership of any returned WindowsFrameInfo
  113. // object.
  114. virtual WindowsFrameInfo *FindWindowsFrameInfo(const StackFrame *frame) const;
  115. // If CFI stack walking information is available covering ADDRESS,
  116. // return a CFIFrameInfo structure describing it. If the information
  117. // is not available, return NULL. The caller takes ownership of any
  118. // returned CFIFrameInfo object.
  119. virtual CFIFrameInfo *FindCFIFrameInfo(const StackFrame *frame) const;
  120. // Number of serialized map components of Module.
  121. static const int kNumberMaps_ = 5 + WindowsFrameInfo::STACK_INFO_LAST;
  122. private:
  123. friend class FastSourceLineResolver;
  124. friend class ModuleComparer;
  125. typedef StaticMap<int, char> FileMap;
  126. string name_;
  127. StaticMap<int, char> files_;
  128. StaticRangeMap<MemAddr, Function> functions_;
  129. StaticAddressMap<MemAddr, PublicSymbol> public_symbols_;
  130. // Each element in the array is a ContainedRangeMap for a type
  131. // listed in WindowsFrameInfoTypes. These are split by type because
  132. // there may be overlaps between maps of different types, but some
  133. // information is only available as certain types.
  134. StaticContainedRangeMap<MemAddr, char>
  135. windows_frame_info_[WindowsFrameInfo::STACK_INFO_LAST];
  136. // DWARF CFI stack walking data. The Module stores the initial rule sets
  137. // and rule deltas as strings, just as they appear in the symbol file:
  138. // although the file may contain hundreds of thousands of STACK CFI
  139. // records, walking a stack will only ever use a few of them, so it's
  140. // best to delay parsing a record until it's actually needed.
  141. //
  142. // STACK CFI INIT records: for each range, an initial set of register
  143. // recovery rules. The RangeMap's itself gives the starting and ending
  144. // addresses.
  145. StaticRangeMap<MemAddr, char> cfi_initial_rules_;
  146. // STACK CFI records: at a given address, the changes to the register
  147. // recovery rules that take effect at that address. The map key is the
  148. // starting address; the ending address is the key of the next entry in
  149. // this map, or the end of the range as given by the cfi_initial_rules_
  150. // entry (which FindCFIFrameInfo looks up first).
  151. StaticMap<MemAddr, char> cfi_delta_rules_;
  152. };
  153. } // namespace google_breakpad
  154. #endif // PROCESSOR_FAST_SOURCE_LINE_RESOLVER_TYPES_H__