toolkit/crashreporter/google-breakpad/src/processor/simple_serializer-inl.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/processor/simple_serializer-inl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,255 @@
     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 +// simple_serializer-inl.h: template specializations for following types:
    1.34 +// bool, const char *(C-string), string,
    1.35 +// Line, Function, PublicSymbol, WindowsFrameInfo and their linked pointers.
    1.36 +//
    1.37 +// See simple_serializer.h for moredocumentation.
    1.38 +//
    1.39 +// Author: Siyang Xie (lambxsy@google.com)
    1.40 +
    1.41 +#ifndef PROCESSOR_SIMPLE_SERIALIZER_INL_H__
    1.42 +#define PROCESSOR_SIMPLE_SERIALIZER_INL_H__
    1.43 +
    1.44 +#include <string>
    1.45 +
    1.46 +#include "processor/simple_serializer.h"
    1.47 +#include "map_serializers-inl.h"
    1.48 +
    1.49 +#include "google_breakpad/processor/basic_source_line_resolver.h"
    1.50 +#include "processor/basic_source_line_resolver_types.h"
    1.51 +#include "processor/linked_ptr.h"
    1.52 +#include "processor/windows_frame_info.h"
    1.53 +
    1.54 +namespace google_breakpad {
    1.55 +
    1.56 +// Specializations of SimpleSerializer: bool
    1.57 +template<>
    1.58 +class SimpleSerializer<bool> {
    1.59 + public:
    1.60 +  static size_t SizeOf(bool boolean) { return 1; }
    1.61 +
    1.62 +  static char *Write(bool boolean, char *dest) {
    1.63 +    *dest = static_cast<char>(boolean? 255 : 0);
    1.64 +    return ++dest;
    1.65 +  }
    1.66 +};
    1.67 +
    1.68 +// Specializations of SimpleSerializer: string
    1.69 +template<>
    1.70 +class SimpleSerializer<string> {
    1.71 + public:
    1.72 +  static size_t SizeOf(const string &str) { return str.size() + 1; }
    1.73 +
    1.74 +  static char *Write(const string &str, char *dest) {
    1.75 +    strcpy(dest, str.c_str());
    1.76 +    return dest + SizeOf(str);
    1.77 +  }
    1.78 +};
    1.79 +
    1.80 +// Specializations of SimpleSerializer: C-string
    1.81 +template<>
    1.82 +class SimpleSerializer<const char*> {
    1.83 + public:
    1.84 +  static size_t SizeOf(const char *cstring) {
    1.85 +    return strlen(cstring) + 1;
    1.86 +  }
    1.87 +
    1.88 +  static char *Write(const char *cstring, char *dest) {
    1.89 +    strcpy(dest, cstring);
    1.90 +    return dest + SizeOf(cstring);
    1.91 +  }
    1.92 +};
    1.93 +
    1.94 +// Specializations of SimpleSerializer: Line
    1.95 +template<>
    1.96 +class SimpleSerializer<BasicSourceLineResolver::Line> {
    1.97 +  typedef BasicSourceLineResolver::Line Line;
    1.98 + public:
    1.99 +  static size_t SizeOf(const Line &line) {
   1.100 +    return SimpleSerializer<MemAddr>::SizeOf(line.address)
   1.101 +         + SimpleSerializer<MemAddr>::SizeOf(line.size)
   1.102 +         + SimpleSerializer<int32_t>::SizeOf(line.source_file_id)
   1.103 +         + SimpleSerializer<int32_t>::SizeOf(line.line);
   1.104 +  }
   1.105 +  static char *Write(const Line &line, char *dest) {
   1.106 +    dest = SimpleSerializer<MemAddr>::Write(line.address, dest);
   1.107 +    dest = SimpleSerializer<MemAddr>::Write(line.size, dest);
   1.108 +    dest = SimpleSerializer<int32_t>::Write(line.source_file_id, dest);
   1.109 +    dest = SimpleSerializer<int32_t>::Write(line.line, dest);
   1.110 +    return dest;
   1.111 +  }
   1.112 +};
   1.113 +
   1.114 +// Specializations of SimpleSerializer: PublicSymbol
   1.115 +template<>
   1.116 +class SimpleSerializer<BasicSourceLineResolver::PublicSymbol> {
   1.117 +  typedef BasicSourceLineResolver::PublicSymbol PublicSymbol;
   1.118 + public:
   1.119 +  static size_t SizeOf(const PublicSymbol &pubsymbol) {
   1.120 +    return SimpleSerializer<string>::SizeOf(pubsymbol.name)
   1.121 +         + SimpleSerializer<MemAddr>::SizeOf(pubsymbol.address)
   1.122 +         + SimpleSerializer<int32_t>::SizeOf(pubsymbol.parameter_size);
   1.123 +  }
   1.124 +  static char *Write(const PublicSymbol &pubsymbol, char *dest) {
   1.125 +    dest = SimpleSerializer<string>::Write(pubsymbol.name, dest);
   1.126 +    dest = SimpleSerializer<MemAddr>::Write(pubsymbol.address, dest);
   1.127 +    dest = SimpleSerializer<int32_t>::Write(pubsymbol.parameter_size, dest);
   1.128 +    return dest;
   1.129 +  }
   1.130 +};
   1.131 +
   1.132 +// Specializations of SimpleSerializer: WindowsFrameInfo
   1.133 +template<>
   1.134 +class SimpleSerializer<WindowsFrameInfo> {
   1.135 + public:
   1.136 +  static size_t SizeOf(const WindowsFrameInfo &wfi) {
   1.137 +    unsigned int size = 0;
   1.138 +    size += sizeof(int32_t);  // wfi.type_
   1.139 +    size += SimpleSerializer<int32_t>::SizeOf(wfi.valid);
   1.140 +    size += SimpleSerializer<uint32_t>::SizeOf(wfi.prolog_size);
   1.141 +    size += SimpleSerializer<uint32_t>::SizeOf(wfi.epilog_size);
   1.142 +    size += SimpleSerializer<uint32_t>::SizeOf(wfi.parameter_size);
   1.143 +    size += SimpleSerializer<uint32_t>::SizeOf(wfi.saved_register_size);
   1.144 +    size += SimpleSerializer<uint32_t>::SizeOf(wfi.local_size);
   1.145 +    size += SimpleSerializer<uint32_t>::SizeOf(wfi.max_stack_size);
   1.146 +    size += SimpleSerializer<bool>::SizeOf(wfi.allocates_base_pointer);
   1.147 +    size += SimpleSerializer<string>::SizeOf(wfi.program_string);
   1.148 +    return size;
   1.149 +  }
   1.150 +  static char *Write(const WindowsFrameInfo &wfi, char *dest) {
   1.151 +    dest = SimpleSerializer<int32_t>::Write(
   1.152 +        static_cast<const int32_t>(wfi.type_), dest);
   1.153 +    dest = SimpleSerializer<int32_t>::Write(wfi.valid, dest);
   1.154 +    dest = SimpleSerializer<uint32_t>::Write(wfi.prolog_size, dest);
   1.155 +    dest = SimpleSerializer<uint32_t>::Write(wfi.epilog_size, dest);
   1.156 +    dest = SimpleSerializer<uint32_t>::Write(wfi.parameter_size, dest);
   1.157 +    dest = SimpleSerializer<uint32_t>::Write(wfi.saved_register_size, dest);
   1.158 +    dest = SimpleSerializer<uint32_t>::Write(wfi.local_size, dest);
   1.159 +    dest = SimpleSerializer<uint32_t>::Write(wfi.max_stack_size, dest);
   1.160 +    dest = SimpleSerializer<bool>::Write(wfi.allocates_base_pointer, dest);
   1.161 +    return SimpleSerializer<string>::Write(wfi.program_string, dest);
   1.162 +  }
   1.163 +};
   1.164 +
   1.165 +// Specializations of SimpleSerializer: Linked_ptr version of
   1.166 +// Line, Function, PublicSymbol, WindowsFrameInfo.
   1.167 +template<>
   1.168 +class SimpleSerializer< linked_ptr<BasicSourceLineResolver::Line> > {
   1.169 +  typedef BasicSourceLineResolver::Line Line;
   1.170 + public:
   1.171 +  static size_t SizeOf(const linked_ptr<Line> &lineptr) {
   1.172 +    if (lineptr.get() == NULL) return 0;
   1.173 +    return SimpleSerializer<Line>::SizeOf(*(lineptr.get()));
   1.174 +  }
   1.175 +  static char *Write(const linked_ptr<Line> &lineptr, char *dest) {
   1.176 +    if (lineptr.get())
   1.177 +      dest = SimpleSerializer<Line>::Write(*(lineptr.get()), dest);
   1.178 +    return dest;
   1.179 +  }
   1.180 +};
   1.181 +
   1.182 +template<>
   1.183 +class SimpleSerializer<BasicSourceLineResolver::Function> {
   1.184 +  // Convenient type names.
   1.185 +  typedef BasicSourceLineResolver::Function Function;
   1.186 +  typedef BasicSourceLineResolver::Line Line;
   1.187 + public:
   1.188 +  static size_t SizeOf(const Function &func) {
   1.189 +    unsigned int size = 0;
   1.190 +    size += SimpleSerializer<string>::SizeOf(func.name);
   1.191 +    size += SimpleSerializer<MemAddr>::SizeOf(func.address);
   1.192 +    size += SimpleSerializer<MemAddr>::SizeOf(func.size);
   1.193 +    size += SimpleSerializer<int32_t>::SizeOf(func.parameter_size);
   1.194 +    size += range_map_serializer_.SizeOf(func.lines);
   1.195 +    return size;
   1.196 +  }
   1.197 +
   1.198 +  static char *Write(const Function &func, char *dest) {
   1.199 +    dest = SimpleSerializer<string>::Write(func.name, dest);
   1.200 +    dest = SimpleSerializer<MemAddr>::Write(func.address, dest);
   1.201 +    dest = SimpleSerializer<MemAddr>::Write(func.size, dest);
   1.202 +    dest = SimpleSerializer<int32_t>::Write(func.parameter_size, dest);
   1.203 +    dest = range_map_serializer_.Write(func.lines, dest);
   1.204 +    return dest;
   1.205 +  }
   1.206 + private:
   1.207 +  // This static member is defined in module_serializer.cc.
   1.208 +  static RangeMapSerializer< MemAddr, linked_ptr<Line> > range_map_serializer_;
   1.209 +};
   1.210 +
   1.211 +template<>
   1.212 +class SimpleSerializer< linked_ptr<BasicSourceLineResolver::Function> > {
   1.213 +  typedef BasicSourceLineResolver::Function Function;
   1.214 + public:
   1.215 +  static size_t SizeOf(const linked_ptr<Function> &func) {
   1.216 +    if (!func.get()) return 0;
   1.217 +    return SimpleSerializer<Function>::SizeOf(*(func.get()));
   1.218 +  }
   1.219 +
   1.220 +  static char *Write(const linked_ptr<Function> &func, char *dest) {
   1.221 +    if (func.get())
   1.222 +      dest = SimpleSerializer<Function>::Write(*(func.get()), dest);
   1.223 +    return dest;
   1.224 +  }
   1.225 +};
   1.226 +
   1.227 +template<>
   1.228 +class SimpleSerializer< linked_ptr<BasicSourceLineResolver::PublicSymbol> > {
   1.229 +  typedef BasicSourceLineResolver::PublicSymbol PublicSymbol;
   1.230 + public:
   1.231 +  static size_t SizeOf(const linked_ptr<PublicSymbol> &pubsymbol) {
   1.232 +    if (pubsymbol.get() == NULL) return 0;
   1.233 +    return SimpleSerializer<PublicSymbol>::SizeOf(*(pubsymbol.get()));
   1.234 +  }
   1.235 +  static char *Write(const linked_ptr<PublicSymbol> &pubsymbol, char *dest) {
   1.236 +    if (pubsymbol.get())
   1.237 +      dest = SimpleSerializer<PublicSymbol>::Write(*(pubsymbol.get()), dest);
   1.238 +    return dest;
   1.239 +  }
   1.240 +};
   1.241 +
   1.242 +template<>
   1.243 +class SimpleSerializer< linked_ptr<WindowsFrameInfo> > {
   1.244 + public:
   1.245 +  static size_t SizeOf(const linked_ptr<WindowsFrameInfo> &wfi) {
   1.246 +    if (wfi.get() == NULL) return 0;
   1.247 +    return SimpleSerializer<WindowsFrameInfo>::SizeOf(*(wfi.get()));
   1.248 +  }
   1.249 +  static char *Write(const linked_ptr<WindowsFrameInfo> &wfi, char *dest) {
   1.250 +    if (wfi.get())
   1.251 +      dest = SimpleSerializer<WindowsFrameInfo>::Write(*(wfi.get()), dest);
   1.252 +    return dest;
   1.253 +  }
   1.254 +};
   1.255 +
   1.256 +}  // namespace google_breakpad
   1.257 +
   1.258 +#endif  // PROCESSOR_SIMPLE_SERIALIZER_INL_H__

mercurial