toolkit/crashreporter/breakpad-patches/08-dwarf2reader-dynamic-cast.patch

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 # HG changeset patch
michael@0 2 # User Ted Mielczarek <ted@mielczarek.org>
michael@0 3 # Date 1362600444 18000
michael@0 4 # Node ID 0eb3c7ba8a38a269ab975eff3f95a1a5d5d937b9
michael@0 5 # Parent 6b68e82037b8322fb392cea369d517aeeaaee9d3
michael@0 6 Stop using dynamic_cast in dwarf2reader
michael@0 7 Patch by Julian Seward <jseward@acm.org>, R=ted
michael@0 8
michael@0 9 diff --git a/src/common/dwarf/dwarf2reader.cc b/src/common/dwarf/dwarf2reader.cc
michael@0 10 --- a/src/common/dwarf/dwarf2reader.cc
michael@0 11 +++ b/src/common/dwarf/dwarf2reader.cc
michael@0 12 @@ -887,68 +887,80 @@
michael@0 13
michael@0 14 // If this is a base+offset rule, change its base register to REG.
michael@0 15 // Otherwise, do nothing. (Ugly, but required for DW_CFA_def_cfa_register.)
michael@0 16 virtual void SetBaseRegister(unsigned reg) { }
michael@0 17
michael@0 18 // If this is a base+offset rule, change its offset to OFFSET. Otherwise,
michael@0 19 // do nothing. (Ugly, but required for DW_CFA_def_cfa_offset.)
michael@0 20 virtual void SetOffset(long long offset) { }
michael@0 21 +
michael@0 22 + // A RTTI workaround, to make it possible to implement equality
michael@0 23 + // comparisons on classes derived from this one.
michael@0 24 + enum CFIRTag {
michael@0 25 + CFIR_UNDEFINED_RULE,
michael@0 26 + CFIR_SAME_VALUE_RULE,
michael@0 27 + CFIR_OFFSET_RULE,
michael@0 28 + CFIR_VAL_OFFSET_RULE,
michael@0 29 + CFIR_REGISTER_RULE,
michael@0 30 + CFIR_EXPRESSION_RULE,
michael@0 31 + CFIR_VAL_EXPRESSION_RULE
michael@0 32 + };
michael@0 33 +
michael@0 34 + // Produce the tag that identifies the child class of this object.
michael@0 35 + virtual CFIRTag getTag() const = 0;
michael@0 36 };
michael@0 37
michael@0 38 // Rule: the value the register had in the caller cannot be recovered.
michael@0 39 class CallFrameInfo::UndefinedRule: public CallFrameInfo::Rule {
michael@0 40 public:
michael@0 41 UndefinedRule() { }
michael@0 42 ~UndefinedRule() { }
michael@0 43 + CFIRTag getTag() const { return CFIR_UNDEFINED_RULE; }
michael@0 44 bool Handle(Handler *handler, uint64 address, int reg) const {
michael@0 45 return handler->UndefinedRule(address, reg);
michael@0 46 }
michael@0 47 bool operator==(const Rule &rhs) const {
michael@0 48 - // dynamic_cast is allowed by the Google C++ Style Guide, if the use has
michael@0 49 - // been carefully considered; cheap RTTI-like workarounds are forbidden.
michael@0 50 - const UndefinedRule *our_rhs = dynamic_cast<const UndefinedRule *>(&rhs);
michael@0 51 - return (our_rhs != NULL);
michael@0 52 + if (rhs.getTag() != CFIR_UNDEFINED_RULE) return false;
michael@0 53 + return true;
michael@0 54 }
michael@0 55 Rule *Copy() const { return new UndefinedRule(*this); }
michael@0 56 };
michael@0 57
michael@0 58 // Rule: the register's value is the same as that it had in the caller.
michael@0 59 class CallFrameInfo::SameValueRule: public CallFrameInfo::Rule {
michael@0 60 public:
michael@0 61 SameValueRule() { }
michael@0 62 ~SameValueRule() { }
michael@0 63 + CFIRTag getTag() const { return CFIR_SAME_VALUE_RULE; }
michael@0 64 bool Handle(Handler *handler, uint64 address, int reg) const {
michael@0 65 return handler->SameValueRule(address, reg);
michael@0 66 }
michael@0 67 bool operator==(const Rule &rhs) const {
michael@0 68 - // dynamic_cast is allowed by the Google C++ Style Guide, if the use has
michael@0 69 - // been carefully considered; cheap RTTI-like workarounds are forbidden.
michael@0 70 - const SameValueRule *our_rhs = dynamic_cast<const SameValueRule *>(&rhs);
michael@0 71 - return (our_rhs != NULL);
michael@0 72 + if (rhs.getTag() != CFIR_SAME_VALUE_RULE) return false;
michael@0 73 + return true;
michael@0 74 }
michael@0 75 Rule *Copy() const { return new SameValueRule(*this); }
michael@0 76 };
michael@0 77
michael@0 78 // Rule: the register is saved at OFFSET from BASE_REGISTER. BASE_REGISTER
michael@0 79 // may be CallFrameInfo::Handler::kCFARegister.
michael@0 80 class CallFrameInfo::OffsetRule: public CallFrameInfo::Rule {
michael@0 81 public:
michael@0 82 OffsetRule(int base_register, long offset)
michael@0 83 : base_register_(base_register), offset_(offset) { }
michael@0 84 ~OffsetRule() { }
michael@0 85 + CFIRTag getTag() const { return CFIR_OFFSET_RULE; }
michael@0 86 bool Handle(Handler *handler, uint64 address, int reg) const {
michael@0 87 return handler->OffsetRule(address, reg, base_register_, offset_);
michael@0 88 }
michael@0 89 bool operator==(const Rule &rhs) const {
michael@0 90 - // dynamic_cast is allowed by the Google C++ Style Guide, if the use has
michael@0 91 - // been carefully considered; cheap RTTI-like workarounds are forbidden.
michael@0 92 - const OffsetRule *our_rhs = dynamic_cast<const OffsetRule *>(&rhs);
michael@0 93 - return (our_rhs &&
michael@0 94 - base_register_ == our_rhs->base_register_ &&
michael@0 95 + if (rhs.getTag() != CFIR_OFFSET_RULE) return false;
michael@0 96 + const OffsetRule *our_rhs = static_cast<const OffsetRule *>(&rhs);
michael@0 97 + return (base_register_ == our_rhs->base_register_ &&
michael@0 98 offset_ == our_rhs->offset_);
michael@0 99 }
michael@0 100 Rule *Copy() const { return new OffsetRule(*this); }
michael@0 101 // We don't actually need SetBaseRegister or SetOffset here, since they
michael@0 102 // are only ever applied to CFA rules, for DW_CFA_def_cfa_offset, and it
michael@0 103 // doesn't make sense to use OffsetRule for computing the CFA: it
michael@0 104 // computes the address at which a register is saved, not a value.
michael@0 105 private:
michael@0 106 @@ -959,90 +971,89 @@
michael@0 107 // Rule: the value the register had in the caller is the value of
michael@0 108 // BASE_REGISTER plus offset. BASE_REGISTER may be
michael@0 109 // CallFrameInfo::Handler::kCFARegister.
michael@0 110 class CallFrameInfo::ValOffsetRule: public CallFrameInfo::Rule {
michael@0 111 public:
michael@0 112 ValOffsetRule(int base_register, long offset)
michael@0 113 : base_register_(base_register), offset_(offset) { }
michael@0 114 ~ValOffsetRule() { }
michael@0 115 + CFIRTag getTag() const { return CFIR_VAL_OFFSET_RULE; }
michael@0 116 bool Handle(Handler *handler, uint64 address, int reg) const {
michael@0 117 return handler->ValOffsetRule(address, reg, base_register_, offset_);
michael@0 118 }
michael@0 119 bool operator==(const Rule &rhs) const {
michael@0 120 - // dynamic_cast is allowed by the Google C++ Style Guide, if the use has
michael@0 121 - // been carefully considered; cheap RTTI-like workarounds are forbidden.
michael@0 122 - const ValOffsetRule *our_rhs = dynamic_cast<const ValOffsetRule *>(&rhs);
michael@0 123 - return (our_rhs &&
michael@0 124 - base_register_ == our_rhs->base_register_ &&
michael@0 125 + if (rhs.getTag() != CFIR_VAL_OFFSET_RULE) return false;
michael@0 126 + const ValOffsetRule *our_rhs = static_cast<const ValOffsetRule *>(&rhs);
michael@0 127 + return (base_register_ == our_rhs->base_register_ &&
michael@0 128 offset_ == our_rhs->offset_);
michael@0 129 }
michael@0 130 Rule *Copy() const { return new ValOffsetRule(*this); }
michael@0 131 void SetBaseRegister(unsigned reg) { base_register_ = reg; }
michael@0 132 void SetOffset(long long offset) { offset_ = offset; }
michael@0 133 private:
michael@0 134 int base_register_;
michael@0 135 long offset_;
michael@0 136 };
michael@0 137
michael@0 138 // Rule: the register has been saved in another register REGISTER_NUMBER_.
michael@0 139 class CallFrameInfo::RegisterRule: public CallFrameInfo::Rule {
michael@0 140 public:
michael@0 141 explicit RegisterRule(int register_number)
michael@0 142 : register_number_(register_number) { }
michael@0 143 ~RegisterRule() { }
michael@0 144 + CFIRTag getTag() const { return CFIR_REGISTER_RULE; }
michael@0 145 bool Handle(Handler *handler, uint64 address, int reg) const {
michael@0 146 return handler->RegisterRule(address, reg, register_number_);
michael@0 147 }
michael@0 148 bool operator==(const Rule &rhs) const {
michael@0 149 - // dynamic_cast is allowed by the Google C++ Style Guide, if the use has
michael@0 150 - // been carefully considered; cheap RTTI-like workarounds are forbidden.
michael@0 151 - const RegisterRule *our_rhs = dynamic_cast<const RegisterRule *>(&rhs);
michael@0 152 - return (our_rhs && register_number_ == our_rhs->register_number_);
michael@0 153 + if (rhs.getTag() != CFIR_REGISTER_RULE) return false;
michael@0 154 + const RegisterRule *our_rhs = static_cast<const RegisterRule *>(&rhs);
michael@0 155 + return (register_number_ == our_rhs->register_number_);
michael@0 156 }
michael@0 157 Rule *Copy() const { return new RegisterRule(*this); }
michael@0 158 private:
michael@0 159 int register_number_;
michael@0 160 };
michael@0 161
michael@0 162 // Rule: EXPRESSION evaluates to the address at which the register is saved.
michael@0 163 class CallFrameInfo::ExpressionRule: public CallFrameInfo::Rule {
michael@0 164 public:
michael@0 165 explicit ExpressionRule(const string &expression)
michael@0 166 : expression_(expression) { }
michael@0 167 ~ExpressionRule() { }
michael@0 168 + CFIRTag getTag() const { return CFIR_EXPRESSION_RULE; }
michael@0 169 bool Handle(Handler *handler, uint64 address, int reg) const {
michael@0 170 return handler->ExpressionRule(address, reg, expression_);
michael@0 171 }
michael@0 172 bool operator==(const Rule &rhs) const {
michael@0 173 - // dynamic_cast is allowed by the Google C++ Style Guide, if the use has
michael@0 174 - // been carefully considered; cheap RTTI-like workarounds are forbidden.
michael@0 175 - const ExpressionRule *our_rhs = dynamic_cast<const ExpressionRule *>(&rhs);
michael@0 176 - return (our_rhs && expression_ == our_rhs->expression_);
michael@0 177 + if (rhs.getTag() != CFIR_EXPRESSION_RULE) return false;
michael@0 178 + const ExpressionRule *our_rhs = static_cast<const ExpressionRule *>(&rhs);
michael@0 179 + return (expression_ == our_rhs->expression_);
michael@0 180 }
michael@0 181 Rule *Copy() const { return new ExpressionRule(*this); }
michael@0 182 private:
michael@0 183 string expression_;
michael@0 184 };
michael@0 185
michael@0 186 // Rule: EXPRESSION evaluates to the address at which the register is saved.
michael@0 187 class CallFrameInfo::ValExpressionRule: public CallFrameInfo::Rule {
michael@0 188 public:
michael@0 189 explicit ValExpressionRule(const string &expression)
michael@0 190 : expression_(expression) { }
michael@0 191 ~ValExpressionRule() { }
michael@0 192 + CFIRTag getTag() const { return CFIR_VAL_EXPRESSION_RULE; }
michael@0 193 bool Handle(Handler *handler, uint64 address, int reg) const {
michael@0 194 return handler->ValExpressionRule(address, reg, expression_);
michael@0 195 }
michael@0 196 bool operator==(const Rule &rhs) const {
michael@0 197 - // dynamic_cast is allowed by the Google C++ Style Guide, if the use has
michael@0 198 - // been carefully considered; cheap RTTI-like workarounds are forbidden.
michael@0 199 + if (rhs.getTag() != CFIR_VAL_EXPRESSION_RULE) return false;
michael@0 200 const ValExpressionRule *our_rhs =
michael@0 201 - dynamic_cast<const ValExpressionRule *>(&rhs);
michael@0 202 - return (our_rhs && expression_ == our_rhs->expression_);
michael@0 203 + static_cast<const ValExpressionRule *>(&rhs);
michael@0 204 + return (expression_ == our_rhs->expression_);
michael@0 205 }
michael@0 206 Rule *Copy() const { return new ValExpressionRule(*this); }
michael@0 207 private:
michael@0 208 string expression_;
michael@0 209 };
michael@0 210
michael@0 211 // A map from register numbers to rules.
michael@0 212 class CallFrameInfo::RuleMap {

mercurial