michael@0: // Copyright (c) 2010, Google Inc. michael@0: // All rights reserved. michael@0: // michael@0: // Redistribution and use in source and binary forms, with or without michael@0: // modification, are permitted provided that the following conditions are michael@0: // met: michael@0: // michael@0: // * Redistributions of source code must retain the above copyright michael@0: // notice, this list of conditions and the following disclaimer. michael@0: // * Redistributions in binary form must reproduce the above michael@0: // copyright notice, this list of conditions and the following disclaimer michael@0: // in the documentation and/or other materials provided with the michael@0: // distribution. michael@0: // * Neither the name of Google Inc. nor the names of its michael@0: // contributors may be used to endorse or promote products derived from michael@0: // this software without specific prior written permission. michael@0: // michael@0: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT michael@0: // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@0: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, michael@0: // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY michael@0: // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: // michael@0: // module_serializer.h: ModuleSerializer serializes a loaded symbol, michael@0: // i.e., a loaded BasicSouceLineResolver::Module instance, into a memory michael@0: // chunk of data. The serialized data can be read and loaded by michael@0: // FastSourceLineResolver without CPU & memory-intensive parsing. michael@0: // michael@0: // Author: Siyang Xie (lambxsy@google.com) michael@0: michael@0: #ifndef PROCESSOR_MODULE_SERIALIZER_H__ michael@0: #define PROCESSOR_MODULE_SERIALIZER_H__ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "google_breakpad/processor/basic_source_line_resolver.h" michael@0: #include "google_breakpad/processor/fast_source_line_resolver.h" michael@0: #include "processor/basic_source_line_resolver_types.h" michael@0: #include "processor/fast_source_line_resolver_types.h" michael@0: #include "processor/linked_ptr.h" michael@0: #include "processor/map_serializers-inl.h" michael@0: #include "processor/simple_serializer-inl.h" michael@0: #include "processor/windows_frame_info.h" michael@0: michael@0: namespace google_breakpad { michael@0: michael@0: // ModuleSerializer serializes a loaded BasicSourceLineResolver::Module into a michael@0: // chunk of memory data. ModuleSerializer also provides interface to compute michael@0: // memory size of the serialized data, write serialized data directly into michael@0: // memory, convert ASCII format symbol data into serialized binary data, and michael@0: // convert loaded BasicSourceLineResolver::Module into michael@0: // FastSourceLineResolver::Module. michael@0: class ModuleSerializer { michael@0: public: michael@0: // Compute the size of memory required to serialize a module. Return the michael@0: // total size needed for serialization. michael@0: size_t SizeOf(const BasicSourceLineResolver::Module &module); michael@0: michael@0: // Write a module into an allocated memory chunk with required size. michael@0: // Return the "end" of data, i.e., the address after the final byte of data. michael@0: char* Write(const BasicSourceLineResolver::Module &module, char *dest); michael@0: michael@0: // Serializes a loaded Module object into a chunk of memory data and returns michael@0: // the address of memory chunk. If size != NULL, *size is set to the memory michael@0: // size allocated for the serialized data. michael@0: // Caller takes the ownership of the memory chunk (allocated on heap), and michael@0: // owner should call delete [] to free the memory after use. michael@0: char* Serialize(const BasicSourceLineResolver::Module &module, michael@0: unsigned int *size = NULL); michael@0: michael@0: // Given the string format symbol_data, produces a chunk of serialized data. michael@0: // Caller takes ownership of the serialized data (on heap), and owner should michael@0: // call delete [] to free the memory after use. michael@0: char* SerializeSymbolFileData(const string &symbol_data, michael@0: unsigned int *size = NULL); michael@0: michael@0: // Serializes one loaded module with given moduleid in the basic source line michael@0: // resolver, and loads the serialized data into the fast source line resolver. michael@0: // Return false if the basic source line doesn't have a module with the given michael@0: // moduleid. michael@0: bool ConvertOneModule(const string &moduleid, michael@0: const BasicSourceLineResolver *basic_resolver, michael@0: FastSourceLineResolver *fast_resolver); michael@0: michael@0: // Serializes all the loaded modules in a basic source line resolver, and michael@0: // loads the serialized data into a fast source line resolver. michael@0: void ConvertAllModules(const BasicSourceLineResolver *basic_resolver, michael@0: FastSourceLineResolver *fast_resolver); michael@0: michael@0: private: michael@0: // Convenient type names. michael@0: typedef BasicSourceLineResolver::Line Line; michael@0: typedef BasicSourceLineResolver::Function Function; michael@0: typedef BasicSourceLineResolver::PublicSymbol PublicSymbol; michael@0: michael@0: // Internal implementation for ConvertOneModule and ConvertAllModules methods. michael@0: bool SerializeModuleAndLoadIntoFastResolver( michael@0: const BasicSourceLineResolver::ModuleMap::const_iterator &iter, michael@0: FastSourceLineResolver *fast_resolver); michael@0: michael@0: // Number of Maps that Module class contains. michael@0: static const int32_t kNumberMaps_ = michael@0: FastSourceLineResolver::Module::kNumberMaps_; michael@0: michael@0: // Memory sizes required to serialize map components in Module. michael@0: uint32_t map_sizes_[kNumberMaps_]; michael@0: michael@0: // Serializers for each individual map component in Module class. michael@0: StdMapSerializer files_serializer_; michael@0: RangeMapSerializer > functions_serializer_; michael@0: AddressMapSerializer > pubsym_serializer_; michael@0: ContainedRangeMapSerializer > wfi_serializer_; michael@0: RangeMapSerializer cfi_init_rules_serializer_; michael@0: StdMapSerializer cfi_delta_rules_serializer_; michael@0: }; michael@0: michael@0: } // namespace google_breakpad michael@0: michael@0: #endif // PROCESSOR_MODULE_SERIALIZER_H__