/thirdparty/breakpad/processor/module_serializer.h

http://github.com/tomahawk-player/tomahawk · C Header · 127 lines · 46 code · 17 blank · 64 comment · 0 complexity · a6cfb09a9d31ffe22ad36db9b01664e9 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. // module_serializer.h: ModuleSerializer serializes a loaded symbol,
  31. // i.e., a loaded BasicSouceLineResolver::Module instance, into a memory
  32. // chunk of data. The serialized data can be read and loaded by
  33. // FastSourceLineResolver without CPU & memory-intensive parsing.
  34. //
  35. // Author: Siyang Xie (lambxsy@google.com)
  36. #ifndef PROCESSOR_MODULE_SERIALIZER_H__
  37. #define PROCESSOR_MODULE_SERIALIZER_H__
  38. #include <map>
  39. #include <string>
  40. #include "google_breakpad/processor/basic_source_line_resolver.h"
  41. #include "google_breakpad/processor/fast_source_line_resolver.h"
  42. #include "processor/basic_source_line_resolver_types.h"
  43. #include "processor/fast_source_line_resolver_types.h"
  44. #include "processor/linked_ptr.h"
  45. #include "processor/map_serializers-inl.h"
  46. #include "processor/simple_serializer-inl.h"
  47. #include "processor/windows_frame_info.h"
  48. namespace google_breakpad {
  49. // ModuleSerializer serializes a loaded BasicSourceLineResolver::Module into a
  50. // chunk of memory data. ModuleSerializer also provides interface to compute
  51. // memory size of the serialized data, write serialized data directly into
  52. // memory, convert ASCII format symbol data into serialized binary data, and
  53. // convert loaded BasicSourceLineResolver::Module into
  54. // FastSourceLineResolver::Module.
  55. class ModuleSerializer {
  56. public:
  57. // Compute the size of memory required to serialize a module. Return the
  58. // total size needed for serialization.
  59. size_t SizeOf(const BasicSourceLineResolver::Module &module);
  60. // Write a module into an allocated memory chunk with required size.
  61. // Return the "end" of data, i.e., the address after the final byte of data.
  62. char* Write(const BasicSourceLineResolver::Module &module, char *dest);
  63. // Serializes a loaded Module object into a chunk of memory data and returns
  64. // the address of memory chunk. If size != NULL, *size is set to the memory
  65. // size allocated for the serialized data.
  66. // Caller takes the ownership of the memory chunk (allocated on heap), and
  67. // owner should call delete [] to free the memory after use.
  68. char* Serialize(const BasicSourceLineResolver::Module &module,
  69. unsigned int *size = NULL);
  70. // Given the string format symbol_data, produces a chunk of serialized data.
  71. // Caller takes ownership of the serialized data (on heap), and owner should
  72. // call delete [] to free the memory after use.
  73. char* SerializeSymbolFileData(const string &symbol_data,
  74. unsigned int *size = NULL);
  75. // Serializes one loaded module with given moduleid in the basic source line
  76. // resolver, and loads the serialized data into the fast source line resolver.
  77. // Return false if the basic source line doesn't have a module with the given
  78. // moduleid.
  79. bool ConvertOneModule(const string &moduleid,
  80. const BasicSourceLineResolver *basic_resolver,
  81. FastSourceLineResolver *fast_resolver);
  82. // Serializes all the loaded modules in a basic source line resolver, and
  83. // loads the serialized data into a fast source line resolver.
  84. void ConvertAllModules(const BasicSourceLineResolver *basic_resolver,
  85. FastSourceLineResolver *fast_resolver);
  86. private:
  87. // Convenient type names.
  88. typedef BasicSourceLineResolver::Line Line;
  89. typedef BasicSourceLineResolver::Function Function;
  90. typedef BasicSourceLineResolver::PublicSymbol PublicSymbol;
  91. // Internal implementation for ConvertOneModule and ConvertAllModules methods.
  92. bool SerializeModuleAndLoadIntoFastResolver(
  93. const BasicSourceLineResolver::ModuleMap::const_iterator &iter,
  94. FastSourceLineResolver *fast_resolver);
  95. // Number of Maps that Module class contains.
  96. static const u_int32_t kNumberMaps_ =
  97. FastSourceLineResolver::Module::kNumberMaps_;
  98. // Memory sizes required to serialize map components in Module.
  99. u_int32_t map_sizes_[kNumberMaps_];
  100. // Serializers for each individual map component in Module class.
  101. StdMapSerializer<int, string> files_serializer_;
  102. RangeMapSerializer<MemAddr, linked_ptr<Function> > functions_serializer_;
  103. AddressMapSerializer<MemAddr, linked_ptr<PublicSymbol> > pubsym_serializer_;
  104. ContainedRangeMapSerializer<MemAddr,
  105. linked_ptr<WindowsFrameInfo> > wfi_serializer_;
  106. RangeMapSerializer<MemAddr, string> cfi_init_rules_serializer_;
  107. StdMapSerializer<MemAddr, string> cfi_delta_rules_serializer_;
  108. };
  109. } // namespace google_breakpad
  110. #endif // PROCESSOR_MODULE_SERIALIZER_H__