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 | // 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 | // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> |
michael@0 | 31 | |
michael@0 | 32 | // dump_stabs_unittest.cc: Unit tests for StabsToModule. |
michael@0 | 33 | |
michael@0 | 34 | #include <vector> |
michael@0 | 35 | |
michael@0 | 36 | #include "breakpad_googletest_includes.h" |
michael@0 | 37 | #include "common/stabs_to_module.h" |
michael@0 | 38 | |
michael@0 | 39 | using google_breakpad::Module; |
michael@0 | 40 | using google_breakpad::StabsToModule; |
michael@0 | 41 | using std::vector; |
michael@0 | 42 | |
michael@0 | 43 | TEST(StabsToModule, SimpleCU) { |
michael@0 | 44 | Module m("name", "os", "arch", "id"); |
michael@0 | 45 | StabsToModule h(&m); |
michael@0 | 46 | |
michael@0 | 47 | // Feed in a simple compilation unit that defines a function with |
michael@0 | 48 | // one line. |
michael@0 | 49 | EXPECT_TRUE(h.StartCompilationUnit("compilation-unit", 0x9f4d1271e50db93bLL, |
michael@0 | 50 | "build-directory")); |
michael@0 | 51 | EXPECT_TRUE(h.StartFunction("function", 0xfde4abbed390c394LL)); |
michael@0 | 52 | EXPECT_TRUE(h.Line(0xfde4abbed390c394LL, "source-file-name", 174823314)); |
michael@0 | 53 | EXPECT_TRUE(h.EndFunction(0xfde4abbed390c3a4LL)); |
michael@0 | 54 | EXPECT_TRUE(h.EndCompilationUnit(0xfee4abbed390c3a4LL)); |
michael@0 | 55 | h.Finalize(); |
michael@0 | 56 | |
michael@0 | 57 | // Now check to see what has been added to the Module. |
michael@0 | 58 | Module::File *file = m.FindExistingFile("source-file-name"); |
michael@0 | 59 | ASSERT_TRUE(file != NULL); |
michael@0 | 60 | |
michael@0 | 61 | vector<Module::Function *> functions; |
michael@0 | 62 | m.GetFunctions(&functions, functions.end()); |
michael@0 | 63 | ASSERT_EQ((size_t) 1, functions.size()); |
michael@0 | 64 | Module::Function *function = functions[0]; |
michael@0 | 65 | EXPECT_STREQ("function", function->name.c_str()); |
michael@0 | 66 | EXPECT_EQ(0xfde4abbed390c394LL, function->address); |
michael@0 | 67 | EXPECT_EQ(0x10U, function->size); |
michael@0 | 68 | EXPECT_EQ(0U, function->parameter_size); |
michael@0 | 69 | ASSERT_EQ((size_t) 1, function->lines.size()); |
michael@0 | 70 | Module::Line *line = &function->lines[0]; |
michael@0 | 71 | EXPECT_EQ(0xfde4abbed390c394LL, line->address); |
michael@0 | 72 | EXPECT_EQ(0x10U, line->size); // derived from EndFunction |
michael@0 | 73 | EXPECT_TRUE(line->file == file); |
michael@0 | 74 | EXPECT_EQ(174823314, line->number); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | #ifdef __GNUC__ |
michael@0 | 78 | // Function name mangling can vary by compiler, so only run mangled-name |
michael@0 | 79 | // tests on GCC for simplicity's sake. |
michael@0 | 80 | TEST(StabsToModule, Externs) { |
michael@0 | 81 | Module m("name", "os", "arch", "id"); |
michael@0 | 82 | StabsToModule h(&m); |
michael@0 | 83 | |
michael@0 | 84 | // Feed in a few Extern symbols. |
michael@0 | 85 | EXPECT_TRUE(h.Extern("_foo", 0xffff)); |
michael@0 | 86 | EXPECT_TRUE(h.Extern("__Z21dyldGlobalLockAcquirev", 0xaaaa)); |
michael@0 | 87 | EXPECT_TRUE(h.Extern("_MorphTableGetNextMorphChain", 0x1111)); |
michael@0 | 88 | h.Finalize(); |
michael@0 | 89 | |
michael@0 | 90 | // Now check to see what has been added to the Module. |
michael@0 | 91 | vector<Module::Extern *> externs; |
michael@0 | 92 | m.GetExterns(&externs, externs.end()); |
michael@0 | 93 | ASSERT_EQ((size_t) 3, externs.size()); |
michael@0 | 94 | Module::Extern *extern1 = externs[0]; |
michael@0 | 95 | EXPECT_STREQ("MorphTableGetNextMorphChain", extern1->name.c_str()); |
michael@0 | 96 | EXPECT_EQ((Module::Address)0x1111, extern1->address); |
michael@0 | 97 | Module::Extern *extern2 = externs[1]; |
michael@0 | 98 | EXPECT_STREQ("dyldGlobalLockAcquire()", extern2->name.c_str()); |
michael@0 | 99 | EXPECT_EQ((Module::Address)0xaaaa, extern2->address); |
michael@0 | 100 | Module::Extern *extern3 = externs[2]; |
michael@0 | 101 | EXPECT_STREQ("foo", extern3->name.c_str()); |
michael@0 | 102 | EXPECT_EQ((Module::Address)0xffff, extern3->address); |
michael@0 | 103 | } |
michael@0 | 104 | #endif // __GNUC__ |
michael@0 | 105 | |
michael@0 | 106 | TEST(StabsToModule, DuplicateFunctionNames) { |
michael@0 | 107 | Module m("name", "os", "arch", "id"); |
michael@0 | 108 | StabsToModule h(&m); |
michael@0 | 109 | |
michael@0 | 110 | // Compilation unit with one function, mangled name. |
michael@0 | 111 | EXPECT_TRUE(h.StartCompilationUnit("compilation-unit", 0xf2cfda36ecf7f46cLL, |
michael@0 | 112 | "build-directory")); |
michael@0 | 113 | EXPECT_TRUE(h.StartFunction("funcfoo", |
michael@0 | 114 | 0xf2cfda36ecf7f46dLL)); |
michael@0 | 115 | EXPECT_TRUE(h.EndFunction(0)); |
michael@0 | 116 | EXPECT_TRUE(h.StartFunction("funcfoo", |
michael@0 | 117 | 0xf2cfda36ecf7f46dLL)); |
michael@0 | 118 | EXPECT_TRUE(h.EndFunction(0)); |
michael@0 | 119 | EXPECT_TRUE(h.EndCompilationUnit(0)); |
michael@0 | 120 | |
michael@0 | 121 | h.Finalize(); |
michael@0 | 122 | |
michael@0 | 123 | // Now check to see what has been added to the Module. |
michael@0 | 124 | Module::File *file = m.FindExistingFile("compilation-unit"); |
michael@0 | 125 | ASSERT_TRUE(file != NULL); |
michael@0 | 126 | |
michael@0 | 127 | vector<Module::Function *> functions; |
michael@0 | 128 | m.GetFunctions(&functions, functions.end()); |
michael@0 | 129 | ASSERT_EQ(1U, functions.size()); |
michael@0 | 130 | |
michael@0 | 131 | Module::Function *function = functions[0]; |
michael@0 | 132 | EXPECT_EQ(0xf2cfda36ecf7f46dLL, function->address); |
michael@0 | 133 | EXPECT_LT(0U, function->size); // should have used dummy size |
michael@0 | 134 | EXPECT_EQ(0U, function->parameter_size); |
michael@0 | 135 | ASSERT_EQ(0U, function->lines.size()); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | TEST(InferSizes, LineSize) { |
michael@0 | 139 | Module m("name", "os", "arch", "id"); |
michael@0 | 140 | StabsToModule h(&m); |
michael@0 | 141 | |
michael@0 | 142 | // Feed in a simple compilation unit that defines a function with |
michael@0 | 143 | // one line. |
michael@0 | 144 | EXPECT_TRUE(h.StartCompilationUnit("compilation-unit", 0xb4513962eff94e92LL, |
michael@0 | 145 | "build-directory")); |
michael@0 | 146 | EXPECT_TRUE(h.StartFunction("function", 0xb4513962eff94e92LL)); |
michael@0 | 147 | EXPECT_TRUE(h.Line(0xb4513962eff94e92LL, "source-file-name-1", 77396614)); |
michael@0 | 148 | EXPECT_TRUE(h.Line(0xb4513963eff94e92LL, "source-file-name-2", 87660088)); |
michael@0 | 149 | EXPECT_TRUE(h.EndFunction(0)); // unknown function end address |
michael@0 | 150 | EXPECT_TRUE(h.EndCompilationUnit(0)); // unknown CU end address |
michael@0 | 151 | EXPECT_TRUE(h.StartCompilationUnit("compilation-unit-2", 0xb4523963eff94e92LL, |
michael@0 | 152 | "build-directory-2")); // next boundary |
michael@0 | 153 | EXPECT_TRUE(h.EndCompilationUnit(0)); |
michael@0 | 154 | h.Finalize(); |
michael@0 | 155 | |
michael@0 | 156 | // Now check to see what has been added to the Module. |
michael@0 | 157 | Module::File *file1 = m.FindExistingFile("source-file-name-1"); |
michael@0 | 158 | ASSERT_TRUE(file1 != NULL); |
michael@0 | 159 | Module::File *file2 = m.FindExistingFile("source-file-name-2"); |
michael@0 | 160 | ASSERT_TRUE(file2 != NULL); |
michael@0 | 161 | |
michael@0 | 162 | vector<Module::Function *> functions; |
michael@0 | 163 | m.GetFunctions(&functions, functions.end()); |
michael@0 | 164 | ASSERT_EQ((size_t) 1, functions.size()); |
michael@0 | 165 | |
michael@0 | 166 | Module::Function *function = functions[0]; |
michael@0 | 167 | EXPECT_STREQ("function", function->name.c_str()); |
michael@0 | 168 | EXPECT_EQ(0xb4513962eff94e92LL, function->address); |
michael@0 | 169 | EXPECT_EQ(0x1000100000000ULL, function->size); // inferred from CU end |
michael@0 | 170 | EXPECT_EQ(0U, function->parameter_size); |
michael@0 | 171 | ASSERT_EQ((size_t) 2, function->lines.size()); |
michael@0 | 172 | |
michael@0 | 173 | Module::Line *line1 = &function->lines[0]; |
michael@0 | 174 | EXPECT_EQ(0xb4513962eff94e92LL, line1->address); |
michael@0 | 175 | EXPECT_EQ(0x100000000ULL, line1->size); // derived from EndFunction |
michael@0 | 176 | EXPECT_TRUE(line1->file == file1); |
michael@0 | 177 | EXPECT_EQ(77396614, line1->number); |
michael@0 | 178 | |
michael@0 | 179 | Module::Line *line2 = &function->lines[1]; |
michael@0 | 180 | EXPECT_EQ(0xb4513963eff94e92LL, line2->address); |
michael@0 | 181 | EXPECT_EQ(0x1000000000000ULL, line2->size); // derived from EndFunction |
michael@0 | 182 | EXPECT_TRUE(line2->file == file2); |
michael@0 | 183 | EXPECT_EQ(87660088, line2->number); |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | #ifdef __GNUC__ |
michael@0 | 187 | // Function name mangling can vary by compiler, so only run mangled-name |
michael@0 | 188 | // tests on GCC for simplicity's sake. |
michael@0 | 189 | TEST(FunctionNames, Mangled) { |
michael@0 | 190 | Module m("name", "os", "arch", "id"); |
michael@0 | 191 | StabsToModule h(&m); |
michael@0 | 192 | |
michael@0 | 193 | // Compilation unit with one function, mangled name. |
michael@0 | 194 | EXPECT_TRUE(h.StartCompilationUnit("compilation-unit", 0xf2cfda63cef7f46cLL, |
michael@0 | 195 | "build-directory")); |
michael@0 | 196 | EXPECT_TRUE(h.StartFunction("_ZNSt6vectorIySaIyEE9push_backERKy", |
michael@0 | 197 | 0xf2cfda63cef7f46dLL)); |
michael@0 | 198 | EXPECT_TRUE(h.EndFunction(0)); |
michael@0 | 199 | EXPECT_TRUE(h.EndCompilationUnit(0)); |
michael@0 | 200 | |
michael@0 | 201 | h.Finalize(); |
michael@0 | 202 | |
michael@0 | 203 | // Now check to see what has been added to the Module. |
michael@0 | 204 | Module::File *file = m.FindExistingFile("compilation-unit"); |
michael@0 | 205 | ASSERT_TRUE(file != NULL); |
michael@0 | 206 | |
michael@0 | 207 | vector<Module::Function *> functions; |
michael@0 | 208 | m.GetFunctions(&functions, functions.end()); |
michael@0 | 209 | ASSERT_EQ(1U, functions.size()); |
michael@0 | 210 | |
michael@0 | 211 | Module::Function *function = functions[0]; |
michael@0 | 212 | // This is GCC-specific, but we shouldn't be seeing STABS data anywhere |
michael@0 | 213 | // but Linux. |
michael@0 | 214 | EXPECT_STREQ("std::vector<unsigned long long, " |
michael@0 | 215 | "std::allocator<unsigned long long> >::" |
michael@0 | 216 | "push_back(unsigned long long const&)", |
michael@0 | 217 | function->name.c_str()); |
michael@0 | 218 | EXPECT_EQ(0xf2cfda63cef7f46dLL, function->address); |
michael@0 | 219 | EXPECT_LT(0U, function->size); // should have used dummy size |
michael@0 | 220 | EXPECT_EQ(0U, function->parameter_size); |
michael@0 | 221 | ASSERT_EQ(0U, function->lines.size()); |
michael@0 | 222 | } |
michael@0 | 223 | #endif // __GNUC__ |
michael@0 | 224 | |
michael@0 | 225 | // The GNU toolchain can omit functions that are not used; however, |
michael@0 | 226 | // when it does so, it doesn't clean up the debugging information that |
michael@0 | 227 | // refers to them. In STABS, this results in compilation units whose |
michael@0 | 228 | // SO addresses are zero. |
michael@0 | 229 | TEST(Omitted, Function) { |
michael@0 | 230 | Module m("name", "os", "arch", "id"); |
michael@0 | 231 | StabsToModule h(&m); |
michael@0 | 232 | |
michael@0 | 233 | // The StartCompilationUnit and EndCompilationUnit calls may both have an |
michael@0 | 234 | // address of zero if the compilation unit has had sections removed. |
michael@0 | 235 | EXPECT_TRUE(h.StartCompilationUnit("compilation-unit", 0, "build-directory")); |
michael@0 | 236 | EXPECT_TRUE(h.StartFunction("function", 0x2a133596)); |
michael@0 | 237 | EXPECT_TRUE(h.EndFunction(0)); |
michael@0 | 238 | EXPECT_TRUE(h.EndCompilationUnit(0)); |
michael@0 | 239 | } |
michael@0 | 240 | |
michael@0 | 241 | // TODO --- if we actually cared about STABS. Even without these we've |
michael@0 | 242 | // got full coverage of non-failure source lines in dump_stabs.cc. |
michael@0 | 243 | |
michael@0 | 244 | // Line size from next line |
michael@0 | 245 | // Line size from function end |
michael@0 | 246 | // Line size from next function start |
michael@0 | 247 | // line size from cu end |
michael@0 | 248 | // line size from next cu start |
michael@0 | 249 | // fallback size is something plausible |
michael@0 | 250 | |
michael@0 | 251 | // function size from function end |
michael@0 | 252 | // function size from next function start |
michael@0 | 253 | // function size from cu end |
michael@0 | 254 | // function size from next cu start |
michael@0 | 255 | // fallback size is something plausible |
michael@0 | 256 | |
michael@0 | 257 | // omitting functions outside the compilation unit's address range |
michael@0 | 258 | // zero-line, one-line, many-line functions |