Sat, 03 Jan 2015 20:18:00 +0100
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 | // -*- mode: c++ -*- |
michael@0 | 2 | |
michael@0 | 3 | // Copyright (c) 2010 Google Inc. |
michael@0 | 4 | // All rights reserved. |
michael@0 | 5 | // |
michael@0 | 6 | // Redistribution and use in source and binary forms, with or without |
michael@0 | 7 | // modification, are permitted provided that the following conditions are |
michael@0 | 8 | // met: |
michael@0 | 9 | // |
michael@0 | 10 | // * Redistributions of source code must retain the above copyright |
michael@0 | 11 | // notice, this list of conditions and the following disclaimer. |
michael@0 | 12 | // * Redistributions in binary form must reproduce the above |
michael@0 | 13 | // copyright notice, this list of conditions and the following disclaimer |
michael@0 | 14 | // in the documentation and/or other materials provided with the |
michael@0 | 15 | // distribution. |
michael@0 | 16 | // * Neither the name of Google Inc. nor the names of its |
michael@0 | 17 | // contributors may be used to endorse or promote products derived from |
michael@0 | 18 | // this software without specific prior written permission. |
michael@0 | 19 | // |
michael@0 | 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
michael@0 | 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@0 | 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 31 | |
michael@0 | 32 | // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> |
michael@0 | 33 | |
michael@0 | 34 | // The DwarfLineToModule class accepts line number information from a |
michael@0 | 35 | // DWARF parser and adds it to a google_breakpad::Module. The Module |
michael@0 | 36 | // can write that data out as a Breakpad symbol file. |
michael@0 | 37 | |
michael@0 | 38 | #ifndef COMMON_LINUX_DWARF_LINE_TO_MODULE_H |
michael@0 | 39 | #define COMMON_LINUX_DWARF_LINE_TO_MODULE_H |
michael@0 | 40 | |
michael@0 | 41 | #include <string> |
michael@0 | 42 | |
michael@0 | 43 | #include "common/module.h" |
michael@0 | 44 | #include "common/dwarf/dwarf2reader.h" |
michael@0 | 45 | #include "common/using_std_string.h" |
michael@0 | 46 | |
michael@0 | 47 | namespace google_breakpad { |
michael@0 | 48 | |
michael@0 | 49 | // A class for producing a vector of google_breakpad::Module::Line |
michael@0 | 50 | // instances from parsed DWARF line number data. |
michael@0 | 51 | // |
michael@0 | 52 | // An instance of this class can be provided as a handler to a |
michael@0 | 53 | // dwarf2reader::LineInfo DWARF line number information parser. The |
michael@0 | 54 | // handler accepts source location information from the parser and |
michael@0 | 55 | // uses it to produce a vector of google_breakpad::Module::Line |
michael@0 | 56 | // objects, referring to google_breakpad::Module::File objects added |
michael@0 | 57 | // to a particular google_breakpad::Module. |
michael@0 | 58 | // |
michael@0 | 59 | // GNU toolchain omitted sections support: |
michael@0 | 60 | // ====================================== |
michael@0 | 61 | // |
michael@0 | 62 | // Given the right options, the GNU toolchain will omit unreferenced |
michael@0 | 63 | // functions from the final executable. Unfortunately, when it does so, it |
michael@0 | 64 | // does not remove the associated portions of the DWARF line number |
michael@0 | 65 | // program; instead, it gives the DW_LNE_set_address instructions referring |
michael@0 | 66 | // to the now-deleted code addresses of zero. Given this input, the DWARF |
michael@0 | 67 | // line parser will call AddLine with a series of lines starting at address |
michael@0 | 68 | // zero. For example, here is the output from 'readelf -wl' for a program |
michael@0 | 69 | // with four functions, the first three of which have been omitted: |
michael@0 | 70 | // |
michael@0 | 71 | // Line Number Statements: |
michael@0 | 72 | // Extended opcode 2: set Address to 0x0 |
michael@0 | 73 | // Advance Line by 14 to 15 |
michael@0 | 74 | // Copy |
michael@0 | 75 | // Special opcode 48: advance Address by 3 to 0x3 and Line by 1 to 16 |
michael@0 | 76 | // Special opcode 119: advance Address by 8 to 0xb and Line by 2 to 18 |
michael@0 | 77 | // Advance PC by 2 to 0xd |
michael@0 | 78 | // Extended opcode 1: End of Sequence |
michael@0 | 79 | // |
michael@0 | 80 | // Extended opcode 2: set Address to 0x0 |
michael@0 | 81 | // Advance Line by 14 to 15 |
michael@0 | 82 | // Copy |
michael@0 | 83 | // Special opcode 48: advance Address by 3 to 0x3 and Line by 1 to 16 |
michael@0 | 84 | // Special opcode 119: advance Address by 8 to 0xb and Line by 2 to 18 |
michael@0 | 85 | // Advance PC by 2 to 0xd |
michael@0 | 86 | // Extended opcode 1: End of Sequence |
michael@0 | 87 | // |
michael@0 | 88 | // Extended opcode 2: set Address to 0x0 |
michael@0 | 89 | // Advance Line by 19 to 20 |
michael@0 | 90 | // Copy |
michael@0 | 91 | // Special opcode 48: advance Address by 3 to 0x3 and Line by 1 to 21 |
michael@0 | 92 | // Special opcode 76: advance Address by 5 to 0x8 and Line by 1 to 22 |
michael@0 | 93 | // Advance PC by 2 to 0xa |
michael@0 | 94 | // Extended opcode 1: End of Sequence |
michael@0 | 95 | // |
michael@0 | 96 | // Extended opcode 2: set Address to 0x80483a4 |
michael@0 | 97 | // Advance Line by 23 to 24 |
michael@0 | 98 | // Copy |
michael@0 | 99 | // Special opcode 202: advance Address by 14 to 0x80483b2 and Line by 1 to 25 |
michael@0 | 100 | // Special opcode 76: advance Address by 5 to 0x80483b7 and Line by 1 to 26 |
michael@0 | 101 | // Advance PC by 6 to 0x80483bd |
michael@0 | 102 | // Extended opcode 1: End of Sequence |
michael@0 | 103 | // |
michael@0 | 104 | // Instead of collecting runs of lines describing code that is not there, |
michael@0 | 105 | // we try to recognize and drop them. Since the linker doesn't explicitly |
michael@0 | 106 | // distinguish references to dropped sections from genuine references to |
michael@0 | 107 | // code at address zero, we must use a heuristic. We have chosen: |
michael@0 | 108 | // |
michael@0 | 109 | // - If a line starts at address zero, omit it. (On the platforms |
michael@0 | 110 | // breakpad targets, it is extremely unlikely that there will be code |
michael@0 | 111 | // at address zero.) |
michael@0 | 112 | // |
michael@0 | 113 | // - If a line starts immediately after an omitted line, omit it too. |
michael@0 | 114 | class DwarfLineToModule: public dwarf2reader::LineInfoHandler { |
michael@0 | 115 | public: |
michael@0 | 116 | // As the DWARF line info parser passes us line records, add source |
michael@0 | 117 | // files to MODULE, and add all lines to the end of LINES. LINES |
michael@0 | 118 | // need not be empty. If the parser hands us a zero-length line, we |
michael@0 | 119 | // omit it. If the parser hands us a line that extends beyond the |
michael@0 | 120 | // end of the address space, we clip it. It's up to our client to |
michael@0 | 121 | // sort out which lines belong to which functions; we don't add them |
michael@0 | 122 | // to any particular function in MODULE ourselves. |
michael@0 | 123 | DwarfLineToModule(Module *module, const string& compilation_dir, |
michael@0 | 124 | vector<Module::Line> *lines) |
michael@0 | 125 | : module_(module), |
michael@0 | 126 | compilation_dir_(compilation_dir), |
michael@0 | 127 | lines_(lines), |
michael@0 | 128 | highest_file_number_(-1), |
michael@0 | 129 | omitted_line_end_(0), |
michael@0 | 130 | warned_bad_file_number_(false), |
michael@0 | 131 | warned_bad_directory_number_(false) { } |
michael@0 | 132 | |
michael@0 | 133 | ~DwarfLineToModule() { } |
michael@0 | 134 | |
michael@0 | 135 | void DefineDir(const string &name, uint32 dir_num); |
michael@0 | 136 | void DefineFile(const string &name, int32 file_num, |
michael@0 | 137 | uint32 dir_num, uint64 mod_time, |
michael@0 | 138 | uint64 length); |
michael@0 | 139 | void AddLine(uint64 address, uint64 length, |
michael@0 | 140 | uint32 file_num, uint32 line_num, uint32 column_num); |
michael@0 | 141 | |
michael@0 | 142 | private: |
michael@0 | 143 | |
michael@0 | 144 | typedef std::map<uint32, string> DirectoryTable; |
michael@0 | 145 | typedef std::map<uint32, Module::File *> FileTable; |
michael@0 | 146 | |
michael@0 | 147 | // The module we're contributing debugging info to. Owned by our |
michael@0 | 148 | // client. |
michael@0 | 149 | Module *module_; |
michael@0 | 150 | |
michael@0 | 151 | // The compilation directory for the current compilation unit whose |
michael@0 | 152 | // lines are being accumulated. |
michael@0 | 153 | string compilation_dir_; |
michael@0 | 154 | |
michael@0 | 155 | // The vector of lines we're accumulating. Owned by our client. |
michael@0 | 156 | // |
michael@0 | 157 | // In a Module, as in a breakpad symbol file, lines belong to |
michael@0 | 158 | // specific functions, but DWARF simply assigns lines to addresses; |
michael@0 | 159 | // one must infer the line/function relationship using the |
michael@0 | 160 | // functions' beginning and ending addresses. So we can't add these |
michael@0 | 161 | // to the appropriate function from module_ until we've read the |
michael@0 | 162 | // function info as well. Instead, we accumulate lines here, and let |
michael@0 | 163 | // whoever constructed this sort it all out. |
michael@0 | 164 | vector<Module::Line> *lines_; |
michael@0 | 165 | |
michael@0 | 166 | // A table mapping directory numbers to paths. |
michael@0 | 167 | DirectoryTable directories_; |
michael@0 | 168 | |
michael@0 | 169 | // A table mapping file numbers to Module::File pointers. |
michael@0 | 170 | FileTable files_; |
michael@0 | 171 | |
michael@0 | 172 | // The highest file number we've seen so far, or -1 if we've seen |
michael@0 | 173 | // none. Used for dynamically defined file numbers. |
michael@0 | 174 | int32 highest_file_number_; |
michael@0 | 175 | |
michael@0 | 176 | // This is the ending address of the last line we omitted, or zero if we |
michael@0 | 177 | // didn't omit the previous line. It is zero before we have received any |
michael@0 | 178 | // AddLine calls. |
michael@0 | 179 | uint64 omitted_line_end_; |
michael@0 | 180 | |
michael@0 | 181 | // True if we've warned about: |
michael@0 | 182 | bool warned_bad_file_number_; // bad file numbers |
michael@0 | 183 | bool warned_bad_directory_number_; // bad directory numbers |
michael@0 | 184 | }; |
michael@0 | 185 | |
michael@0 | 186 | } // namespace google_breakpad |
michael@0 | 187 | |
michael@0 | 188 | #endif // COMMON_LINUX_DWARF_LINE_TO_MODULE_H |