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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2010, Google Inc.
michael@0 2 // All rights reserved.
michael@0 3 //
michael@0 4 // Redistribution and use in source and binary forms, with or without
michael@0 5 // modification, are permitted provided that the following conditions are
michael@0 6 // met:
michael@0 7 //
michael@0 8 // * Redistributions of source code must retain the above copyright
michael@0 9 // notice, this list of conditions and the following disclaimer.
michael@0 10 // * Redistributions in binary form must reproduce the above
michael@0 11 // copyright notice, this list of conditions and the following disclaimer
michael@0 12 // in the documentation and/or other materials provided with the
michael@0 13 // distribution.
michael@0 14 // * Neither the name of Google Inc. nor the names of its
michael@0 15 // contributors may be used to endorse or promote products derived from
michael@0 16 // this software without specific prior written permission.
michael@0 17 //
michael@0 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
michael@0 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@0 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 29 //
michael@0 30 // simple_serializer-inl.h: template specializations for following types:
michael@0 31 // bool, const char *(C-string), string,
michael@0 32 // Line, Function, PublicSymbol, WindowsFrameInfo and their linked pointers.
michael@0 33 //
michael@0 34 // See simple_serializer.h for moredocumentation.
michael@0 35 //
michael@0 36 // Author: Siyang Xie (lambxsy@google.com)
michael@0 37
michael@0 38 #ifndef PROCESSOR_SIMPLE_SERIALIZER_INL_H__
michael@0 39 #define PROCESSOR_SIMPLE_SERIALIZER_INL_H__
michael@0 40
michael@0 41 #include <string>
michael@0 42
michael@0 43 #include "processor/simple_serializer.h"
michael@0 44 #include "map_serializers-inl.h"
michael@0 45
michael@0 46 #include "google_breakpad/processor/basic_source_line_resolver.h"
michael@0 47 #include "processor/basic_source_line_resolver_types.h"
michael@0 48 #include "processor/linked_ptr.h"
michael@0 49 #include "processor/windows_frame_info.h"
michael@0 50
michael@0 51 namespace google_breakpad {
michael@0 52
michael@0 53 // Specializations of SimpleSerializer: bool
michael@0 54 template<>
michael@0 55 class SimpleSerializer<bool> {
michael@0 56 public:
michael@0 57 static size_t SizeOf(bool boolean) { return 1; }
michael@0 58
michael@0 59 static char *Write(bool boolean, char *dest) {
michael@0 60 *dest = static_cast<char>(boolean? 255 : 0);
michael@0 61 return ++dest;
michael@0 62 }
michael@0 63 };
michael@0 64
michael@0 65 // Specializations of SimpleSerializer: string
michael@0 66 template<>
michael@0 67 class SimpleSerializer<string> {
michael@0 68 public:
michael@0 69 static size_t SizeOf(const string &str) { return str.size() + 1; }
michael@0 70
michael@0 71 static char *Write(const string &str, char *dest) {
michael@0 72 strcpy(dest, str.c_str());
michael@0 73 return dest + SizeOf(str);
michael@0 74 }
michael@0 75 };
michael@0 76
michael@0 77 // Specializations of SimpleSerializer: C-string
michael@0 78 template<>
michael@0 79 class SimpleSerializer<const char*> {
michael@0 80 public:
michael@0 81 static size_t SizeOf(const char *cstring) {
michael@0 82 return strlen(cstring) + 1;
michael@0 83 }
michael@0 84
michael@0 85 static char *Write(const char *cstring, char *dest) {
michael@0 86 strcpy(dest, cstring);
michael@0 87 return dest + SizeOf(cstring);
michael@0 88 }
michael@0 89 };
michael@0 90
michael@0 91 // Specializations of SimpleSerializer: Line
michael@0 92 template<>
michael@0 93 class SimpleSerializer<BasicSourceLineResolver::Line> {
michael@0 94 typedef BasicSourceLineResolver::Line Line;
michael@0 95 public:
michael@0 96 static size_t SizeOf(const Line &line) {
michael@0 97 return SimpleSerializer<MemAddr>::SizeOf(line.address)
michael@0 98 + SimpleSerializer<MemAddr>::SizeOf(line.size)
michael@0 99 + SimpleSerializer<int32_t>::SizeOf(line.source_file_id)
michael@0 100 + SimpleSerializer<int32_t>::SizeOf(line.line);
michael@0 101 }
michael@0 102 static char *Write(const Line &line, char *dest) {
michael@0 103 dest = SimpleSerializer<MemAddr>::Write(line.address, dest);
michael@0 104 dest = SimpleSerializer<MemAddr>::Write(line.size, dest);
michael@0 105 dest = SimpleSerializer<int32_t>::Write(line.source_file_id, dest);
michael@0 106 dest = SimpleSerializer<int32_t>::Write(line.line, dest);
michael@0 107 return dest;
michael@0 108 }
michael@0 109 };
michael@0 110
michael@0 111 // Specializations of SimpleSerializer: PublicSymbol
michael@0 112 template<>
michael@0 113 class SimpleSerializer<BasicSourceLineResolver::PublicSymbol> {
michael@0 114 typedef BasicSourceLineResolver::PublicSymbol PublicSymbol;
michael@0 115 public:
michael@0 116 static size_t SizeOf(const PublicSymbol &pubsymbol) {
michael@0 117 return SimpleSerializer<string>::SizeOf(pubsymbol.name)
michael@0 118 + SimpleSerializer<MemAddr>::SizeOf(pubsymbol.address)
michael@0 119 + SimpleSerializer<int32_t>::SizeOf(pubsymbol.parameter_size);
michael@0 120 }
michael@0 121 static char *Write(const PublicSymbol &pubsymbol, char *dest) {
michael@0 122 dest = SimpleSerializer<string>::Write(pubsymbol.name, dest);
michael@0 123 dest = SimpleSerializer<MemAddr>::Write(pubsymbol.address, dest);
michael@0 124 dest = SimpleSerializer<int32_t>::Write(pubsymbol.parameter_size, dest);
michael@0 125 return dest;
michael@0 126 }
michael@0 127 };
michael@0 128
michael@0 129 // Specializations of SimpleSerializer: WindowsFrameInfo
michael@0 130 template<>
michael@0 131 class SimpleSerializer<WindowsFrameInfo> {
michael@0 132 public:
michael@0 133 static size_t SizeOf(const WindowsFrameInfo &wfi) {
michael@0 134 unsigned int size = 0;
michael@0 135 size += sizeof(int32_t); // wfi.type_
michael@0 136 size += SimpleSerializer<int32_t>::SizeOf(wfi.valid);
michael@0 137 size += SimpleSerializer<uint32_t>::SizeOf(wfi.prolog_size);
michael@0 138 size += SimpleSerializer<uint32_t>::SizeOf(wfi.epilog_size);
michael@0 139 size += SimpleSerializer<uint32_t>::SizeOf(wfi.parameter_size);
michael@0 140 size += SimpleSerializer<uint32_t>::SizeOf(wfi.saved_register_size);
michael@0 141 size += SimpleSerializer<uint32_t>::SizeOf(wfi.local_size);
michael@0 142 size += SimpleSerializer<uint32_t>::SizeOf(wfi.max_stack_size);
michael@0 143 size += SimpleSerializer<bool>::SizeOf(wfi.allocates_base_pointer);
michael@0 144 size += SimpleSerializer<string>::SizeOf(wfi.program_string);
michael@0 145 return size;
michael@0 146 }
michael@0 147 static char *Write(const WindowsFrameInfo &wfi, char *dest) {
michael@0 148 dest = SimpleSerializer<int32_t>::Write(
michael@0 149 static_cast<const int32_t>(wfi.type_), dest);
michael@0 150 dest = SimpleSerializer<int32_t>::Write(wfi.valid, dest);
michael@0 151 dest = SimpleSerializer<uint32_t>::Write(wfi.prolog_size, dest);
michael@0 152 dest = SimpleSerializer<uint32_t>::Write(wfi.epilog_size, dest);
michael@0 153 dest = SimpleSerializer<uint32_t>::Write(wfi.parameter_size, dest);
michael@0 154 dest = SimpleSerializer<uint32_t>::Write(wfi.saved_register_size, dest);
michael@0 155 dest = SimpleSerializer<uint32_t>::Write(wfi.local_size, dest);
michael@0 156 dest = SimpleSerializer<uint32_t>::Write(wfi.max_stack_size, dest);
michael@0 157 dest = SimpleSerializer<bool>::Write(wfi.allocates_base_pointer, dest);
michael@0 158 return SimpleSerializer<string>::Write(wfi.program_string, dest);
michael@0 159 }
michael@0 160 };
michael@0 161
michael@0 162 // Specializations of SimpleSerializer: Linked_ptr version of
michael@0 163 // Line, Function, PublicSymbol, WindowsFrameInfo.
michael@0 164 template<>
michael@0 165 class SimpleSerializer< linked_ptr<BasicSourceLineResolver::Line> > {
michael@0 166 typedef BasicSourceLineResolver::Line Line;
michael@0 167 public:
michael@0 168 static size_t SizeOf(const linked_ptr<Line> &lineptr) {
michael@0 169 if (lineptr.get() == NULL) return 0;
michael@0 170 return SimpleSerializer<Line>::SizeOf(*(lineptr.get()));
michael@0 171 }
michael@0 172 static char *Write(const linked_ptr<Line> &lineptr, char *dest) {
michael@0 173 if (lineptr.get())
michael@0 174 dest = SimpleSerializer<Line>::Write(*(lineptr.get()), dest);
michael@0 175 return dest;
michael@0 176 }
michael@0 177 };
michael@0 178
michael@0 179 template<>
michael@0 180 class SimpleSerializer<BasicSourceLineResolver::Function> {
michael@0 181 // Convenient type names.
michael@0 182 typedef BasicSourceLineResolver::Function Function;
michael@0 183 typedef BasicSourceLineResolver::Line Line;
michael@0 184 public:
michael@0 185 static size_t SizeOf(const Function &func) {
michael@0 186 unsigned int size = 0;
michael@0 187 size += SimpleSerializer<string>::SizeOf(func.name);
michael@0 188 size += SimpleSerializer<MemAddr>::SizeOf(func.address);
michael@0 189 size += SimpleSerializer<MemAddr>::SizeOf(func.size);
michael@0 190 size += SimpleSerializer<int32_t>::SizeOf(func.parameter_size);
michael@0 191 size += range_map_serializer_.SizeOf(func.lines);
michael@0 192 return size;
michael@0 193 }
michael@0 194
michael@0 195 static char *Write(const Function &func, char *dest) {
michael@0 196 dest = SimpleSerializer<string>::Write(func.name, dest);
michael@0 197 dest = SimpleSerializer<MemAddr>::Write(func.address, dest);
michael@0 198 dest = SimpleSerializer<MemAddr>::Write(func.size, dest);
michael@0 199 dest = SimpleSerializer<int32_t>::Write(func.parameter_size, dest);
michael@0 200 dest = range_map_serializer_.Write(func.lines, dest);
michael@0 201 return dest;
michael@0 202 }
michael@0 203 private:
michael@0 204 // This static member is defined in module_serializer.cc.
michael@0 205 static RangeMapSerializer< MemAddr, linked_ptr<Line> > range_map_serializer_;
michael@0 206 };
michael@0 207
michael@0 208 template<>
michael@0 209 class SimpleSerializer< linked_ptr<BasicSourceLineResolver::Function> > {
michael@0 210 typedef BasicSourceLineResolver::Function Function;
michael@0 211 public:
michael@0 212 static size_t SizeOf(const linked_ptr<Function> &func) {
michael@0 213 if (!func.get()) return 0;
michael@0 214 return SimpleSerializer<Function>::SizeOf(*(func.get()));
michael@0 215 }
michael@0 216
michael@0 217 static char *Write(const linked_ptr<Function> &func, char *dest) {
michael@0 218 if (func.get())
michael@0 219 dest = SimpleSerializer<Function>::Write(*(func.get()), dest);
michael@0 220 return dest;
michael@0 221 }
michael@0 222 };
michael@0 223
michael@0 224 template<>
michael@0 225 class SimpleSerializer< linked_ptr<BasicSourceLineResolver::PublicSymbol> > {
michael@0 226 typedef BasicSourceLineResolver::PublicSymbol PublicSymbol;
michael@0 227 public:
michael@0 228 static size_t SizeOf(const linked_ptr<PublicSymbol> &pubsymbol) {
michael@0 229 if (pubsymbol.get() == NULL) return 0;
michael@0 230 return SimpleSerializer<PublicSymbol>::SizeOf(*(pubsymbol.get()));
michael@0 231 }
michael@0 232 static char *Write(const linked_ptr<PublicSymbol> &pubsymbol, char *dest) {
michael@0 233 if (pubsymbol.get())
michael@0 234 dest = SimpleSerializer<PublicSymbol>::Write(*(pubsymbol.get()), dest);
michael@0 235 return dest;
michael@0 236 }
michael@0 237 };
michael@0 238
michael@0 239 template<>
michael@0 240 class SimpleSerializer< linked_ptr<WindowsFrameInfo> > {
michael@0 241 public:
michael@0 242 static size_t SizeOf(const linked_ptr<WindowsFrameInfo> &wfi) {
michael@0 243 if (wfi.get() == NULL) return 0;
michael@0 244 return SimpleSerializer<WindowsFrameInfo>::SizeOf(*(wfi.get()));
michael@0 245 }
michael@0 246 static char *Write(const linked_ptr<WindowsFrameInfo> &wfi, char *dest) {
michael@0 247 if (wfi.get())
michael@0 248 dest = SimpleSerializer<WindowsFrameInfo>::Write(*(wfi.get()), dest);
michael@0 249 return dest;
michael@0 250 }
michael@0 251 };
michael@0 252
michael@0 253 } // namespace google_breakpad
michael@0 254
michael@0 255 #endif // PROCESSOR_SIMPLE_SERIALIZER_INL_H__

mercurial