1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/google-breakpad/src/processor/module_serializer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,127 @@ 1.4 +// Copyright (c) 2010, Google Inc. 1.5 +// All rights reserved. 1.6 +// 1.7 +// Redistribution and use in source and binary forms, with or without 1.8 +// modification, are permitted provided that the following conditions are 1.9 +// met: 1.10 +// 1.11 +// * Redistributions of source code must retain the above copyright 1.12 +// notice, this list of conditions and the following disclaimer. 1.13 +// * Redistributions in binary form must reproduce the above 1.14 +// copyright notice, this list of conditions and the following disclaimer 1.15 +// in the documentation and/or other materials provided with the 1.16 +// distribution. 1.17 +// * Neither the name of Google Inc. nor the names of its 1.18 +// contributors may be used to endorse or promote products derived from 1.19 +// this software without specific prior written permission. 1.20 +// 1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.32 +// 1.33 +// module_serializer.h: ModuleSerializer serializes a loaded symbol, 1.34 +// i.e., a loaded BasicSouceLineResolver::Module instance, into a memory 1.35 +// chunk of data. The serialized data can be read and loaded by 1.36 +// FastSourceLineResolver without CPU & memory-intensive parsing. 1.37 +// 1.38 +// Author: Siyang Xie (lambxsy@google.com) 1.39 + 1.40 +#ifndef PROCESSOR_MODULE_SERIALIZER_H__ 1.41 +#define PROCESSOR_MODULE_SERIALIZER_H__ 1.42 + 1.43 +#include <map> 1.44 +#include <string> 1.45 + 1.46 +#include "google_breakpad/processor/basic_source_line_resolver.h" 1.47 +#include "google_breakpad/processor/fast_source_line_resolver.h" 1.48 +#include "processor/basic_source_line_resolver_types.h" 1.49 +#include "processor/fast_source_line_resolver_types.h" 1.50 +#include "processor/linked_ptr.h" 1.51 +#include "processor/map_serializers-inl.h" 1.52 +#include "processor/simple_serializer-inl.h" 1.53 +#include "processor/windows_frame_info.h" 1.54 + 1.55 +namespace google_breakpad { 1.56 + 1.57 +// ModuleSerializer serializes a loaded BasicSourceLineResolver::Module into a 1.58 +// chunk of memory data. ModuleSerializer also provides interface to compute 1.59 +// memory size of the serialized data, write serialized data directly into 1.60 +// memory, convert ASCII format symbol data into serialized binary data, and 1.61 +// convert loaded BasicSourceLineResolver::Module into 1.62 +// FastSourceLineResolver::Module. 1.63 +class ModuleSerializer { 1.64 + public: 1.65 + // Compute the size of memory required to serialize a module. Return the 1.66 + // total size needed for serialization. 1.67 + size_t SizeOf(const BasicSourceLineResolver::Module &module); 1.68 + 1.69 + // Write a module into an allocated memory chunk with required size. 1.70 + // Return the "end" of data, i.e., the address after the final byte of data. 1.71 + char* Write(const BasicSourceLineResolver::Module &module, char *dest); 1.72 + 1.73 + // Serializes a loaded Module object into a chunk of memory data and returns 1.74 + // the address of memory chunk. If size != NULL, *size is set to the memory 1.75 + // size allocated for the serialized data. 1.76 + // Caller takes the ownership of the memory chunk (allocated on heap), and 1.77 + // owner should call delete [] to free the memory after use. 1.78 + char* Serialize(const BasicSourceLineResolver::Module &module, 1.79 + unsigned int *size = NULL); 1.80 + 1.81 + // Given the string format symbol_data, produces a chunk of serialized data. 1.82 + // Caller takes ownership of the serialized data (on heap), and owner should 1.83 + // call delete [] to free the memory after use. 1.84 + char* SerializeSymbolFileData(const string &symbol_data, 1.85 + unsigned int *size = NULL); 1.86 + 1.87 + // Serializes one loaded module with given moduleid in the basic source line 1.88 + // resolver, and loads the serialized data into the fast source line resolver. 1.89 + // Return false if the basic source line doesn't have a module with the given 1.90 + // moduleid. 1.91 + bool ConvertOneModule(const string &moduleid, 1.92 + const BasicSourceLineResolver *basic_resolver, 1.93 + FastSourceLineResolver *fast_resolver); 1.94 + 1.95 + // Serializes all the loaded modules in a basic source line resolver, and 1.96 + // loads the serialized data into a fast source line resolver. 1.97 + void ConvertAllModules(const BasicSourceLineResolver *basic_resolver, 1.98 + FastSourceLineResolver *fast_resolver); 1.99 + 1.100 + private: 1.101 + // Convenient type names. 1.102 + typedef BasicSourceLineResolver::Line Line; 1.103 + typedef BasicSourceLineResolver::Function Function; 1.104 + typedef BasicSourceLineResolver::PublicSymbol PublicSymbol; 1.105 + 1.106 + // Internal implementation for ConvertOneModule and ConvertAllModules methods. 1.107 + bool SerializeModuleAndLoadIntoFastResolver( 1.108 + const BasicSourceLineResolver::ModuleMap::const_iterator &iter, 1.109 + FastSourceLineResolver *fast_resolver); 1.110 + 1.111 + // Number of Maps that Module class contains. 1.112 + static const int32_t kNumberMaps_ = 1.113 + FastSourceLineResolver::Module::kNumberMaps_; 1.114 + 1.115 + // Memory sizes required to serialize map components in Module. 1.116 + uint32_t map_sizes_[kNumberMaps_]; 1.117 + 1.118 + // Serializers for each individual map component in Module class. 1.119 + StdMapSerializer<int, string> files_serializer_; 1.120 + RangeMapSerializer<MemAddr, linked_ptr<Function> > functions_serializer_; 1.121 + AddressMapSerializer<MemAddr, linked_ptr<PublicSymbol> > pubsym_serializer_; 1.122 + ContainedRangeMapSerializer<MemAddr, 1.123 + linked_ptr<WindowsFrameInfo> > wfi_serializer_; 1.124 + RangeMapSerializer<MemAddr, string> cfi_init_rules_serializer_; 1.125 + StdMapSerializer<MemAddr, string> cfi_delta_rules_serializer_; 1.126 +}; 1.127 + 1.128 +} // namespace google_breakpad 1.129 + 1.130 +#endif // PROCESSOR_MODULE_SERIALIZER_H__