toolkit/crashreporter/google-breakpad/src/processor/simple_symbol_supplier.cc

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // Copyright (c) 2006, 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_symbol_supplier.cc: A simple SymbolSupplier implementation
michael@0 31 //
michael@0 32 // See simple_symbol_supplier.h for documentation.
michael@0 33 //
michael@0 34 // Author: Mark Mentovai
michael@0 35
michael@0 36 #include "processor/simple_symbol_supplier.h"
michael@0 37
michael@0 38 #include <assert.h>
michael@0 39 #include <string.h>
michael@0 40 #include <sys/types.h>
michael@0 41 #include <sys/stat.h>
michael@0 42
michael@0 43 #include <algorithm>
michael@0 44 #include <iostream>
michael@0 45 #include <fstream>
michael@0 46
michael@0 47 #include "common/using_std_string.h"
michael@0 48 #include "google_breakpad/processor/code_module.h"
michael@0 49 #include "google_breakpad/processor/system_info.h"
michael@0 50 #include "processor/logging.h"
michael@0 51 #include "processor/pathname_stripper.h"
michael@0 52
michael@0 53 namespace google_breakpad {
michael@0 54
michael@0 55 static bool file_exists(const string &file_name) {
michael@0 56 struct stat sb;
michael@0 57 return stat(file_name.c_str(), &sb) == 0;
michael@0 58 }
michael@0 59
michael@0 60 SymbolSupplier::SymbolResult SimpleSymbolSupplier::GetSymbolFile(
michael@0 61 const CodeModule *module, const SystemInfo *system_info,
michael@0 62 string *symbol_file) {
michael@0 63 BPLOG_IF(ERROR, !symbol_file) << "SimpleSymbolSupplier::GetSymbolFile "
michael@0 64 "requires |symbol_file|";
michael@0 65 assert(symbol_file);
michael@0 66 symbol_file->clear();
michael@0 67
michael@0 68 for (unsigned int path_index = 0; path_index < paths_.size(); ++path_index) {
michael@0 69 SymbolResult result;
michael@0 70 if ((result = GetSymbolFileAtPathFromRoot(module, system_info,
michael@0 71 paths_[path_index],
michael@0 72 symbol_file)) != NOT_FOUND) {
michael@0 73 return result;
michael@0 74 }
michael@0 75 }
michael@0 76 return NOT_FOUND;
michael@0 77 }
michael@0 78
michael@0 79 SymbolSupplier::SymbolResult SimpleSymbolSupplier::GetSymbolFile(
michael@0 80 const CodeModule *module,
michael@0 81 const SystemInfo *system_info,
michael@0 82 string *symbol_file,
michael@0 83 string *symbol_data) {
michael@0 84 assert(symbol_data);
michael@0 85 symbol_data->clear();
michael@0 86
michael@0 87 SymbolSupplier::SymbolResult s = GetSymbolFile(module, system_info, symbol_file);
michael@0 88
michael@0 89 if (s == FOUND) {
michael@0 90 std::ifstream in(symbol_file->c_str());
michael@0 91 std::getline(in, *symbol_data, string::traits_type::to_char_type(
michael@0 92 string::traits_type::eof()));
michael@0 93 in.close();
michael@0 94 }
michael@0 95 return s;
michael@0 96 }
michael@0 97
michael@0 98 SymbolSupplier::SymbolResult SimpleSymbolSupplier::GetCStringSymbolData(
michael@0 99 const CodeModule *module,
michael@0 100 const SystemInfo *system_info,
michael@0 101 string *symbol_file,
michael@0 102 char **symbol_data) {
michael@0 103 assert(symbol_data);
michael@0 104
michael@0 105 string symbol_data_string;
michael@0 106 SymbolSupplier::SymbolResult s =
michael@0 107 GetSymbolFile(module, system_info, symbol_file, &symbol_data_string);
michael@0 108
michael@0 109 if (s == FOUND) {
michael@0 110 unsigned int size = symbol_data_string.size() + 1;
michael@0 111 *symbol_data = new char[size];
michael@0 112 if (*symbol_data == NULL) {
michael@0 113 BPLOG(ERROR) << "Memory allocation for size " << size << " failed";
michael@0 114 return INTERRUPT;
michael@0 115 }
michael@0 116 memcpy(*symbol_data, symbol_data_string.c_str(), size - 1);
michael@0 117 (*symbol_data)[size - 1] = '\0';
michael@0 118 memory_buffers_.insert(make_pair(module->code_file(), *symbol_data));
michael@0 119 }
michael@0 120 return s;
michael@0 121 }
michael@0 122
michael@0 123 void SimpleSymbolSupplier::FreeSymbolData(const CodeModule *module) {
michael@0 124 if (!module) {
michael@0 125 BPLOG(INFO) << "Cannot free symbol data buffer for NULL module";
michael@0 126 return;
michael@0 127 }
michael@0 128
michael@0 129 map<string, char *>::iterator it = memory_buffers_.find(module->code_file());
michael@0 130 if (it == memory_buffers_.end()) {
michael@0 131 BPLOG(INFO) << "Cannot find symbol data buffer for module "
michael@0 132 << module->code_file();
michael@0 133 return;
michael@0 134 }
michael@0 135 delete [] it->second;
michael@0 136 memory_buffers_.erase(it);
michael@0 137 }
michael@0 138
michael@0 139 SymbolSupplier::SymbolResult SimpleSymbolSupplier::GetSymbolFileAtPathFromRoot(
michael@0 140 const CodeModule *module, const SystemInfo *system_info,
michael@0 141 const string &root_path, string *symbol_file) {
michael@0 142 BPLOG_IF(ERROR, !symbol_file) << "SimpleSymbolSupplier::GetSymbolFileAtPath "
michael@0 143 "requires |symbol_file|";
michael@0 144 assert(symbol_file);
michael@0 145 symbol_file->clear();
michael@0 146
michael@0 147 if (!module)
michael@0 148 return NOT_FOUND;
michael@0 149
michael@0 150 // Start with the base path.
michael@0 151 string path = root_path;
michael@0 152
michael@0 153 // Append the debug (pdb) file name as a directory name.
michael@0 154 path.append("/");
michael@0 155 string debug_file_name = PathnameStripper::File(module->debug_file());
michael@0 156 if (debug_file_name.empty()) {
michael@0 157 BPLOG(ERROR) << "Can't construct symbol file path without debug_file "
michael@0 158 "(code_file = " <<
michael@0 159 PathnameStripper::File(module->code_file()) << ")";
michael@0 160 return NOT_FOUND;
michael@0 161 }
michael@0 162 path.append(debug_file_name);
michael@0 163
michael@0 164 // Append the identifier as a directory name.
michael@0 165 path.append("/");
michael@0 166 string identifier = module->debug_identifier();
michael@0 167 if (identifier.empty()) {
michael@0 168 BPLOG(ERROR) << "Can't construct symbol file path without debug_identifier "
michael@0 169 "(code_file = " <<
michael@0 170 PathnameStripper::File(module->code_file()) <<
michael@0 171 ", debug_file = " << debug_file_name << ")";
michael@0 172 return NOT_FOUND;
michael@0 173 }
michael@0 174 path.append(identifier);
michael@0 175
michael@0 176 // Transform the debug file name into one ending in .sym. If the existing
michael@0 177 // name ends in .pdb, strip the .pdb. Otherwise, add .sym to the non-.pdb
michael@0 178 // name.
michael@0 179 path.append("/");
michael@0 180 string debug_file_extension;
michael@0 181 if (debug_file_name.size() > 4)
michael@0 182 debug_file_extension = debug_file_name.substr(debug_file_name.size() - 4);
michael@0 183 std::transform(debug_file_extension.begin(), debug_file_extension.end(),
michael@0 184 debug_file_extension.begin(), tolower);
michael@0 185 if (debug_file_extension == ".pdb") {
michael@0 186 path.append(debug_file_name.substr(0, debug_file_name.size() - 4));
michael@0 187 } else {
michael@0 188 path.append(debug_file_name);
michael@0 189 }
michael@0 190 path.append(".sym");
michael@0 191
michael@0 192 if (!file_exists(path)) {
michael@0 193 BPLOG(INFO) << "No symbol file at " << path;
michael@0 194 return NOT_FOUND;
michael@0 195 }
michael@0 196
michael@0 197 *symbol_file = path;
michael@0 198 return FOUND;
michael@0 199 }
michael@0 200
michael@0 201 } // namespace google_breakpad

mercurial