toolkit/crashreporter/google-breakpad/src/common/dwarf/dwarf2reader_test_common.h

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 // -*- mode: c++ -*-
michael@0 2
michael@0 3 // Copyright (c) 2012, 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 // dwarf2reader_test_common.h: Define TestCompilationUnit and
michael@0 35 // TestAbbrevTable, classes for creating properly (and improperly)
michael@0 36 // formatted DWARF compilation unit data for unit tests.
michael@0 37
michael@0 38 #ifndef COMMON_DWARF_DWARF2READER_TEST_COMMON_H__
michael@0 39 #define COMMON_DWARF_DWARF2READER_TEST_COMMON_H__
michael@0 40
michael@0 41 #include "common/test_assembler.h"
michael@0 42 #include "common/dwarf/dwarf2enums.h"
michael@0 43
michael@0 44 // A subclass of test_assembler::Section, specialized for constructing
michael@0 45 // DWARF compilation units.
michael@0 46 class TestCompilationUnit: public google_breakpad::test_assembler::Section {
michael@0 47 public:
michael@0 48 typedef dwarf2reader::DwarfTag DwarfTag;
michael@0 49 typedef dwarf2reader::DwarfAttribute DwarfAttribute;
michael@0 50 typedef dwarf2reader::DwarfForm DwarfForm;
michael@0 51 typedef google_breakpad::test_assembler::Label Label;
michael@0 52
michael@0 53 // Set the section's DWARF format size (the 32-bit DWARF format or the
michael@0 54 // 64-bit DWARF format, for lengths and section offsets --- not the
michael@0 55 // address size) to format_size.
michael@0 56 void set_format_size(size_t format_size) {
michael@0 57 assert(format_size == 4 || format_size == 8);
michael@0 58 format_size_ = format_size;
michael@0 59 }
michael@0 60
michael@0 61 // Append a DWARF section offset value, of the appropriate size for this
michael@0 62 // compilation unit.
michael@0 63 template<typename T>
michael@0 64 void SectionOffset(T offset) {
michael@0 65 if (format_size_ == 4)
michael@0 66 D32(offset);
michael@0 67 else
michael@0 68 D64(offset);
michael@0 69 }
michael@0 70
michael@0 71 // Append a DWARF compilation unit header to the section, with the given
michael@0 72 // DWARF version, abbrev table offset, and address size.
michael@0 73 TestCompilationUnit &Header(int version, const Label &abbrev_offset,
michael@0 74 size_t address_size) {
michael@0 75 if (format_size_ == 4) {
michael@0 76 D32(length_);
michael@0 77 } else {
michael@0 78 D32(0xffffffff);
michael@0 79 D64(length_);
michael@0 80 }
michael@0 81 post_length_offset_ = Size();
michael@0 82 D16(version);
michael@0 83 SectionOffset(abbrev_offset);
michael@0 84 D8(address_size);
michael@0 85 return *this;
michael@0 86 }
michael@0 87
michael@0 88 // Mark the end of this header's DIEs.
michael@0 89 TestCompilationUnit &Finish() {
michael@0 90 length_ = Size() - post_length_offset_;
michael@0 91 return *this;
michael@0 92 }
michael@0 93
michael@0 94 private:
michael@0 95 // The DWARF format size for this compilation unit.
michael@0 96 size_t format_size_;
michael@0 97
michael@0 98 // The offset of the point in the compilation unit header immediately
michael@0 99 // after the initial length field.
michael@0 100 uint64_t post_length_offset_;
michael@0 101
michael@0 102 // The length of the compilation unit, not including the initial length field.
michael@0 103 Label length_;
michael@0 104 };
michael@0 105
michael@0 106 // A subclass of test_assembler::Section specialized for constructing DWARF
michael@0 107 // abbreviation tables.
michael@0 108 class TestAbbrevTable: public google_breakpad::test_assembler::Section {
michael@0 109 public:
michael@0 110 typedef dwarf2reader::DwarfTag DwarfTag;
michael@0 111 typedef dwarf2reader::DwarfAttribute DwarfAttribute;
michael@0 112 typedef dwarf2reader::DwarfForm DwarfForm;
michael@0 113 typedef dwarf2reader::DwarfHasChild DwarfHasChild;
michael@0 114 typedef google_breakpad::test_assembler::Label Label;
michael@0 115
michael@0 116 // Start a new abbreviation table entry for abbreviation code |code|,
michael@0 117 // encoding a DIE whose tag is |tag|, and which has children if and only
michael@0 118 // if |has_children| is true.
michael@0 119 TestAbbrevTable &Abbrev(int code, DwarfTag tag, DwarfHasChild has_children) {
michael@0 120 assert(code != 0);
michael@0 121 ULEB128(code);
michael@0 122 ULEB128(static_cast<unsigned>(tag));
michael@0 123 D8(static_cast<unsigned>(has_children));
michael@0 124 return *this;
michael@0 125 };
michael@0 126
michael@0 127 // Add an attribute to the current abbreviation code whose name is |name|
michael@0 128 // and whose form is |form|.
michael@0 129 TestAbbrevTable &Attribute(DwarfAttribute name, DwarfForm form) {
michael@0 130 ULEB128(static_cast<unsigned>(name));
michael@0 131 ULEB128(static_cast<unsigned>(form));
michael@0 132 return *this;
michael@0 133 }
michael@0 134
michael@0 135 // Finish the current abbreviation code.
michael@0 136 TestAbbrevTable &EndAbbrev() {
michael@0 137 ULEB128(0);
michael@0 138 ULEB128(0);
michael@0 139 return *this;
michael@0 140 }
michael@0 141
michael@0 142 // Finish the current abbreviation table.
michael@0 143 TestAbbrevTable &EndTable() {
michael@0 144 ULEB128(0);
michael@0 145 return *this;
michael@0 146 }
michael@0 147 };
michael@0 148
michael@0 149 #endif // COMMON_DWARF_DWARF2READER_TEST_COMMON_H__

mercurial