toolkit/crashreporter/google-breakpad/src/common/dwarf/dwarf2diehandler_unittest.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // -*- mode: c++ -*-
michael@0 2
michael@0 3 // Copyright (c) 2010 Google Inc. All Rights Reserved.
michael@0 4 //
michael@0 5 // Redistribution and use in source and binary forms, with or without
michael@0 6 // modification, are permitted provided that the following conditions are
michael@0 7 // met:
michael@0 8 //
michael@0 9 // * Redistributions of source code must retain the above copyright
michael@0 10 // notice, this list of conditions and the following disclaimer.
michael@0 11 // * Redistributions in binary form must reproduce the above
michael@0 12 // copyright notice, this list of conditions and the following disclaimer
michael@0 13 // in the documentation and/or other materials provided with the
michael@0 14 // distribution.
michael@0 15 // * Neither the name of Google Inc. nor the names of its
michael@0 16 // contributors may be used to endorse or promote products derived from
michael@0 17 // this software without specific prior written permission.
michael@0 18 //
michael@0 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
michael@0 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@0 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 30
michael@0 31 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
michael@0 32
michael@0 33 // dwarf2diehander_unittest.cc: Unit tests for google_breakpad::DIEDispatcher.
michael@0 34
michael@0 35 #include <string>
michael@0 36 #include <utility>
michael@0 37
michael@0 38 #include "breakpad_googletest_includes.h"
michael@0 39
michael@0 40 #include "common/dwarf/dwarf2diehandler.h"
michael@0 41 #include "common/using_std_string.h"
michael@0 42
michael@0 43 using std::make_pair;
michael@0 44
michael@0 45 using ::testing::_;
michael@0 46 using ::testing::ContainerEq;
michael@0 47 using ::testing::ElementsAreArray;
michael@0 48 using ::testing::Eq;
michael@0 49 using ::testing::InSequence;
michael@0 50 using ::testing::Return;
michael@0 51 using ::testing::Sequence;
michael@0 52 using ::testing::StrEq;
michael@0 53
michael@0 54 using dwarf2reader::DIEDispatcher;
michael@0 55 using dwarf2reader::DIEHandler;
michael@0 56 using dwarf2reader::DwarfAttribute;
michael@0 57 using dwarf2reader::DwarfForm;
michael@0 58 using dwarf2reader::DwarfTag;
michael@0 59 using dwarf2reader::RootDIEHandler;
michael@0 60
michael@0 61 class MockDIEHandler: public DIEHandler {
michael@0 62 public:
michael@0 63 MOCK_METHOD3(ProcessAttributeUnsigned,
michael@0 64 void(DwarfAttribute, DwarfForm, uint64));
michael@0 65 MOCK_METHOD3(ProcessAttributeSigned,
michael@0 66 void(DwarfAttribute, DwarfForm, int64));
michael@0 67 MOCK_METHOD3(ProcessAttributeReference,
michael@0 68 void(DwarfAttribute, DwarfForm, uint64));
michael@0 69 MOCK_METHOD4(ProcessAttributeBuffer,
michael@0 70 void(DwarfAttribute, DwarfForm, const char *, uint64));
michael@0 71 MOCK_METHOD3(ProcessAttributeString,
michael@0 72 void(DwarfAttribute, DwarfForm, const string &));
michael@0 73 MOCK_METHOD3(ProcessAttributeSignature,
michael@0 74 void(DwarfAttribute, DwarfForm, uint64));
michael@0 75 MOCK_METHOD0(EndAttributes, bool());
michael@0 76 MOCK_METHOD2(FindChildHandler, DIEHandler *(uint64, DwarfTag));
michael@0 77 MOCK_METHOD0(Finish, void());
michael@0 78 };
michael@0 79
michael@0 80 class MockRootDIEHandler: public RootDIEHandler {
michael@0 81 public:
michael@0 82 MOCK_METHOD3(ProcessAttributeUnsigned,
michael@0 83 void(DwarfAttribute, DwarfForm, uint64));
michael@0 84 MOCK_METHOD3(ProcessAttributeSigned,
michael@0 85 void(DwarfAttribute, DwarfForm, int64));
michael@0 86 MOCK_METHOD3(ProcessAttributeReference,
michael@0 87 void(DwarfAttribute, DwarfForm, uint64));
michael@0 88 MOCK_METHOD4(ProcessAttributeBuffer,
michael@0 89 void(DwarfAttribute, DwarfForm, const char *, uint64));
michael@0 90 MOCK_METHOD3(ProcessAttributeString,
michael@0 91 void(DwarfAttribute, DwarfForm, const string &));
michael@0 92 MOCK_METHOD3(ProcessAttributeSignature,
michael@0 93 void(DwarfAttribute, DwarfForm, uint64));
michael@0 94 MOCK_METHOD0(EndAttributes, bool());
michael@0 95 MOCK_METHOD2(FindChildHandler, DIEHandler *(uint64, DwarfTag));
michael@0 96 MOCK_METHOD0(Finish, void());
michael@0 97 MOCK_METHOD5(StartCompilationUnit, bool(uint64, uint8, uint8, uint64, uint8));
michael@0 98 MOCK_METHOD2(StartRootDIE, bool(uint64, DwarfTag));
michael@0 99 };
michael@0 100
michael@0 101 // If the handler elects to skip the compilation unit, the dispatcher
michael@0 102 // should tell the reader so.
michael@0 103 TEST(Dwarf2DIEHandler, SkipCompilationUnit) {
michael@0 104 Sequence s;
michael@0 105 MockRootDIEHandler mock_root_handler;
michael@0 106 DIEDispatcher die_dispatcher(&mock_root_handler);
michael@0 107
michael@0 108 EXPECT_CALL(mock_root_handler,
michael@0 109 StartCompilationUnit(0x8d42aed77cfccf3eLL,
michael@0 110 0x89, 0xdc,
michael@0 111 0x2ecb4dc778a80f21LL,
michael@0 112 0x66))
michael@0 113 .InSequence(s)
michael@0 114 .WillOnce(Return(false));
michael@0 115
michael@0 116 EXPECT_FALSE(die_dispatcher.StartCompilationUnit(0x8d42aed77cfccf3eLL,
michael@0 117 0x89, 0xdc,
michael@0 118 0x2ecb4dc778a80f21LL,
michael@0 119 0x66));
michael@0 120 }
michael@0 121
michael@0 122 // If the handler elects to skip the root DIE, the dispatcher should
michael@0 123 // tell the reader so.
michael@0 124 TEST(Dwarf2DIEHandler, SkipRootDIE) {
michael@0 125 Sequence s;
michael@0 126 MockRootDIEHandler mock_root_handler;
michael@0 127 DIEDispatcher die_dispatcher(&mock_root_handler);
michael@0 128
michael@0 129 EXPECT_CALL(mock_root_handler,
michael@0 130 StartCompilationUnit(0xde8994029fc8b999LL, 0xf4, 0x02,
michael@0 131 0xb00febffa76e2b2bLL, 0x5c))
michael@0 132 .InSequence(s)
michael@0 133 .WillOnce(Return(true));
michael@0 134 EXPECT_CALL(mock_root_handler,
michael@0 135 StartRootDIE(0x7d08242b4b510cf2LL, (DwarfTag) 0xb4f98da6))
michael@0 136 .InSequence(s)
michael@0 137 .WillOnce(Return(false));
michael@0 138
michael@0 139 EXPECT_TRUE(die_dispatcher.StartCompilationUnit(0xde8994029fc8b999LL,
michael@0 140 0xf4, 0x02,
michael@0 141 0xb00febffa76e2b2bLL, 0x5c));
michael@0 142 EXPECT_FALSE(die_dispatcher.StartDIE(0x7d08242b4b510cf2LL,
michael@0 143 (DwarfTag) 0xb4f98da6));
michael@0 144 die_dispatcher.EndDIE(0x7d08242b4b510cf2LL);
michael@0 145 }
michael@0 146
michael@0 147 // If the handler elects to skip the root DIE's children, the
michael@0 148 // dispatcher should tell the reader so --- and avoid deleting the
michael@0 149 // root handler.
michael@0 150 TEST(Dwarf2DIEHandler, SkipRootDIEChildren) {
michael@0 151 MockRootDIEHandler mock_root_handler;
michael@0 152 DIEDispatcher die_dispatcher(&mock_root_handler);
michael@0 153
michael@0 154 {
michael@0 155 InSequence s;
michael@0 156
michael@0 157 EXPECT_CALL(mock_root_handler,
michael@0 158 StartCompilationUnit(0x15d6897480cc65a7LL, 0x26, 0xa0,
michael@0 159 0x09f8bf0767f91675LL, 0xdb))
michael@0 160 .WillOnce(Return(true));
michael@0 161 EXPECT_CALL(mock_root_handler,
michael@0 162 StartRootDIE(0x7d08242b4b510cf2LL, (DwarfTag) 0xb4f98da6))
michael@0 163 .WillOnce(Return(true));
michael@0 164 // Please don't tell me about my children.
michael@0 165 EXPECT_CALL(mock_root_handler, EndAttributes())
michael@0 166 .WillOnce(Return(false));
michael@0 167 EXPECT_CALL(mock_root_handler, Finish())
michael@0 168 .WillOnce(Return());
michael@0 169 }
michael@0 170
michael@0 171 EXPECT_TRUE(die_dispatcher.StartCompilationUnit(0x15d6897480cc65a7LL,
michael@0 172 0x26, 0xa0,
michael@0 173 0x09f8bf0767f91675LL, 0xdb));
michael@0 174 EXPECT_TRUE(die_dispatcher.StartDIE(0x7d08242b4b510cf2LL,
michael@0 175 (DwarfTag) 0xb4f98da6));
michael@0 176 EXPECT_FALSE(die_dispatcher.StartDIE(0x435150ceedccda18LL,
michael@0 177 (DwarfTag) 0xc3a17bba));
michael@0 178 die_dispatcher.EndDIE(0x435150ceedccda18LL);
michael@0 179 die_dispatcher.EndDIE(0x7d08242b4b510cf2LL);
michael@0 180 }
michael@0 181
michael@0 182 // The dispatcher should pass attribute values through to the die
michael@0 183 // handler accurately.
michael@0 184 TEST(Dwarf2DIEHandler, PassAttributeValues) {
michael@0 185 MockRootDIEHandler mock_root_handler;
michael@0 186 DIEDispatcher die_dispatcher(&mock_root_handler);
michael@0 187
michael@0 188 const char buffer[10] = { 0x24, 0x24, 0x35, 0x9a, 0xca,
michael@0 189 0xcf, 0xa8, 0x84, 0xa7, 0x18 };
michael@0 190 string str = "\xc8\x26\x2e\x0d\xa4\x9c\x37\xd6\xfb\x1d";
michael@0 191
michael@0 192 // Set expectations.
michael@0 193 {
michael@0 194 InSequence s;
michael@0 195
michael@0 196 // We'll like the compilation unit header.
michael@0 197 EXPECT_CALL(mock_root_handler,
michael@0 198 StartCompilationUnit(0x8d42aed77cfccf3eLL, 0x89, 0xdc,
michael@0 199 0x2ecb4dc778a80f21LL, 0x66))
michael@0 200 .WillOnce(Return(true));
michael@0 201
michael@0 202 // We'll like the root DIE.
michael@0 203 EXPECT_CALL(mock_root_handler,
michael@0 204 StartRootDIE(0xe2222da01e29f2a9LL, (DwarfTag) 0x9829445c))
michael@0 205 .WillOnce(Return(true));
michael@0 206
michael@0 207 // Expect some attribute values.
michael@0 208 EXPECT_CALL(mock_root_handler,
michael@0 209 ProcessAttributeUnsigned((DwarfAttribute) 0x1cc0bfed,
michael@0 210 (DwarfForm) 0x424f1468,
michael@0 211 0xa592571997facda1ULL))
michael@0 212 .WillOnce(Return());
michael@0 213 EXPECT_CALL(mock_root_handler,
michael@0 214 ProcessAttributeSigned((DwarfAttribute) 0x43694dc9,
michael@0 215 (DwarfForm) 0xf6f78901L,
michael@0 216 0x92602a4e3bf1f446LL))
michael@0 217 .WillOnce(Return());
michael@0 218 EXPECT_CALL(mock_root_handler,
michael@0 219 ProcessAttributeReference((DwarfAttribute) 0x4033e8cL,
michael@0 220 (DwarfForm) 0xf66fbe0bL,
michael@0 221 0x50fddef44734fdecULL))
michael@0 222 .WillOnce(Return());
michael@0 223 EXPECT_CALL(mock_root_handler,
michael@0 224 ProcessAttributeBuffer((DwarfAttribute) 0x25d7e0af,
michael@0 225 (DwarfForm) 0xe99a539a,
michael@0 226 buffer, sizeof(buffer)))
michael@0 227 .WillOnce(Return());
michael@0 228 EXPECT_CALL(mock_root_handler,
michael@0 229 ProcessAttributeString((DwarfAttribute) 0x310ed065,
michael@0 230 (DwarfForm) 0x15762fec,
michael@0 231 StrEq(str)))
michael@0 232 .WillOnce(Return());
michael@0 233 EXPECT_CALL(mock_root_handler,
michael@0 234 ProcessAttributeSignature((DwarfAttribute) 0x58790d72,
michael@0 235 (DwarfForm) 0x4159f138,
michael@0 236 0x94682463613e6a5fULL))
michael@0 237 .WillOnce(Return());
michael@0 238 EXPECT_CALL(mock_root_handler, EndAttributes())
michael@0 239 .WillOnce(Return(true));
michael@0 240 EXPECT_CALL(mock_root_handler, FindChildHandler(_, _))
michael@0 241 .Times(0);
michael@0 242 EXPECT_CALL(mock_root_handler, Finish())
michael@0 243 .WillOnce(Return());
michael@0 244 }
michael@0 245
michael@0 246 // Drive the dispatcher.
michael@0 247
michael@0 248 // Report the CU header.
michael@0 249 EXPECT_TRUE(die_dispatcher.StartCompilationUnit(0x8d42aed77cfccf3eLL,
michael@0 250 0x89, 0xdc,
michael@0 251 0x2ecb4dc778a80f21LL,
michael@0 252 0x66));
michael@0 253 // Report the root DIE.
michael@0 254 EXPECT_TRUE(die_dispatcher.StartDIE(0xe2222da01e29f2a9LL,
michael@0 255 (DwarfTag) 0x9829445c));
michael@0 256
michael@0 257 // Report some attribute values.
michael@0 258 die_dispatcher.ProcessAttributeUnsigned(0xe2222da01e29f2a9LL,
michael@0 259 (DwarfAttribute) 0x1cc0bfed,
michael@0 260 (DwarfForm) 0x424f1468,
michael@0 261 0xa592571997facda1ULL);
michael@0 262 die_dispatcher.ProcessAttributeSigned(0xe2222da01e29f2a9LL,
michael@0 263 (DwarfAttribute) 0x43694dc9,
michael@0 264 (DwarfForm) 0xf6f78901,
michael@0 265 0x92602a4e3bf1f446LL);
michael@0 266 die_dispatcher.ProcessAttributeReference(0xe2222da01e29f2a9LL,
michael@0 267 (DwarfAttribute) 0x4033e8c,
michael@0 268 (DwarfForm) 0xf66fbe0b,
michael@0 269 0x50fddef44734fdecULL);
michael@0 270 die_dispatcher.ProcessAttributeBuffer(0xe2222da01e29f2a9LL,
michael@0 271 (DwarfAttribute) 0x25d7e0af,
michael@0 272 (DwarfForm) 0xe99a539a,
michael@0 273 buffer, sizeof(buffer));
michael@0 274 die_dispatcher.ProcessAttributeString(0xe2222da01e29f2a9LL,
michael@0 275 (DwarfAttribute) 0x310ed065,
michael@0 276 (DwarfForm) 0x15762fec,
michael@0 277 str);
michael@0 278 die_dispatcher.ProcessAttributeSignature(0xe2222da01e29f2a9LL,
michael@0 279 (DwarfAttribute) 0x58790d72,
michael@0 280 (DwarfForm) 0x4159f138,
michael@0 281 0x94682463613e6a5fULL);
michael@0 282
michael@0 283 // Finish the root DIE (and thus the CU).
michael@0 284 die_dispatcher.EndDIE(0xe2222da01e29f2a9LL);
michael@0 285 }
michael@0 286
michael@0 287 TEST(Dwarf2DIEHandler, FindAndSkipChildren) {
michael@0 288 MockRootDIEHandler mock_root_handler;
michael@0 289 MockDIEHandler *mock_child1_handler = new(MockDIEHandler);
michael@0 290 MockDIEHandler *mock_child3_handler = new(MockDIEHandler);
michael@0 291 DIEDispatcher die_dispatcher(&mock_root_handler);
michael@0 292
michael@0 293 {
michael@0 294 InSequence s;
michael@0 295
michael@0 296 // We'll like the compilation unit header.
michael@0 297 EXPECT_CALL(mock_root_handler,
michael@0 298 StartCompilationUnit(0x9ec1e6d05e434a0eLL, 0xeb, 0x21,
michael@0 299 0x47dd3c764275a216LL, 0xa5))
michael@0 300 .WillOnce(Return(true));
michael@0 301
michael@0 302 // Root DIE.
michael@0 303 {
michael@0 304 EXPECT_CALL(mock_root_handler,
michael@0 305 StartRootDIE(0x15f0e06bdfe3c372LL, (DwarfTag) 0xf5d60c59))
michael@0 306 .WillOnce(Return(true));
michael@0 307 EXPECT_CALL(mock_root_handler,
michael@0 308 ProcessAttributeSigned((DwarfAttribute) 0xf779a642,
michael@0 309 (DwarfForm) 0x2cb63027,
michael@0 310 0x18e744661769d08fLL))
michael@0 311 .WillOnce(Return());
michael@0 312 EXPECT_CALL(mock_root_handler, EndAttributes())
michael@0 313 .WillOnce(Return(true));
michael@0 314
michael@0 315 // First child DIE.
michael@0 316 EXPECT_CALL(mock_root_handler,
michael@0 317 FindChildHandler(0x149f644f8116fe8cLL,
michael@0 318 (DwarfTag) 0xac2cbd8c))
michael@0 319 .WillOnce(Return(mock_child1_handler));
michael@0 320 {
michael@0 321 EXPECT_CALL(*mock_child1_handler,
michael@0 322 ProcessAttributeSigned((DwarfAttribute) 0xa6fd6f65,
michael@0 323 (DwarfForm) 0xe4f64c41,
michael@0 324 0x1b04e5444a55fe67LL))
michael@0 325 .WillOnce(Return());
michael@0 326 EXPECT_CALL(*mock_child1_handler, EndAttributes())
michael@0 327 .WillOnce(Return(false));
michael@0 328 // Skip first grandchild DIE and first great-grandchild DIE.
michael@0 329 EXPECT_CALL(*mock_child1_handler, Finish())
michael@0 330 .WillOnce(Return());
michael@0 331 }
michael@0 332
michael@0 333 // Second child DIE. Root handler will decline to return a handler
michael@0 334 // for this child.
michael@0 335 EXPECT_CALL(mock_root_handler,
michael@0 336 FindChildHandler(0x97412be24875de9dLL,
michael@0 337 (DwarfTag) 0x505a068b))
michael@0 338 .WillOnce(Return((DIEHandler *) NULL));
michael@0 339
michael@0 340 // Third child DIE.
michael@0 341 EXPECT_CALL(mock_root_handler,
michael@0 342 FindChildHandler(0x753c964c8ab538aeLL,
michael@0 343 (DwarfTag) 0x8c22970e))
michael@0 344 .WillOnce(Return(mock_child3_handler));
michael@0 345 {
michael@0 346 EXPECT_CALL(*mock_child3_handler,
michael@0 347 ProcessAttributeSigned((DwarfAttribute) 0x4e2b7cfb,
michael@0 348 (DwarfForm) 0x610b7ae1,
michael@0 349 0x3ea5c609d7d7560fLL))
michael@0 350 .WillOnce(Return());
michael@0 351 EXPECT_CALL(*mock_child3_handler, EndAttributes())
michael@0 352 .WillOnce(Return(true));
michael@0 353 EXPECT_CALL(*mock_child3_handler, Finish())
michael@0 354 .WillOnce(Return());
michael@0 355 }
michael@0 356
michael@0 357 EXPECT_CALL(mock_root_handler, Finish())
michael@0 358 .WillOnce(Return());
michael@0 359 }
michael@0 360 }
michael@0 361
michael@0 362
michael@0 363 // Drive the dispatcher.
michael@0 364
michael@0 365 // Report the CU header.
michael@0 366 EXPECT_TRUE(die_dispatcher
michael@0 367 .StartCompilationUnit(0x9ec1e6d05e434a0eLL, 0xeb, 0x21,
michael@0 368 0x47dd3c764275a216LL, 0xa5));
michael@0 369 // Report the root DIE.
michael@0 370 {
michael@0 371 EXPECT_TRUE(die_dispatcher.StartDIE(0x15f0e06bdfe3c372LL,
michael@0 372 (DwarfTag) 0xf5d60c59));
michael@0 373 die_dispatcher.ProcessAttributeSigned(0x15f0e06bdfe3c372LL,
michael@0 374 (DwarfAttribute) 0xf779a642,
michael@0 375 (DwarfForm) 0x2cb63027,
michael@0 376 0x18e744661769d08fLL);
michael@0 377
michael@0 378 // First child DIE.
michael@0 379 {
michael@0 380 EXPECT_TRUE(die_dispatcher.StartDIE(0x149f644f8116fe8cLL,
michael@0 381 (DwarfTag) 0xac2cbd8c));
michael@0 382 die_dispatcher.ProcessAttributeSigned(0x149f644f8116fe8cLL,
michael@0 383 (DwarfAttribute) 0xa6fd6f65,
michael@0 384 (DwarfForm) 0xe4f64c41,
michael@0 385 0x1b04e5444a55fe67LL);
michael@0 386
michael@0 387 // First grandchild DIE. Will be skipped.
michael@0 388 {
michael@0 389 EXPECT_FALSE(die_dispatcher.StartDIE(0xd68de1ee0bd29419LL,
michael@0 390 (DwarfTag) 0x22f05a15));
michael@0 391 // First great-grandchild DIE. Will be skipped without being
michael@0 392 // mentioned to any handler.
michael@0 393 {
michael@0 394 EXPECT_FALSE(die_dispatcher
michael@0 395 .StartDIE(0xb3076285d25cac25LL,
michael@0 396 (DwarfTag) 0xcff4061b));
michael@0 397 die_dispatcher.EndDIE(0xb3076285d25cac25LL);
michael@0 398 }
michael@0 399 die_dispatcher.EndDIE(0xd68de1ee0bd29419LL);
michael@0 400 }
michael@0 401 die_dispatcher.EndDIE(0x149f644f8116fe8cLL);
michael@0 402 }
michael@0 403
michael@0 404 // Second child DIE. Root handler will decline to find a handler for it.
michael@0 405 {
michael@0 406 EXPECT_FALSE(die_dispatcher.StartDIE(0x97412be24875de9dLL,
michael@0 407 (DwarfTag) 0x505a068b));
michael@0 408 die_dispatcher.EndDIE(0x97412be24875de9dLL);
michael@0 409 }
michael@0 410
michael@0 411 // Third child DIE.
michael@0 412 {
michael@0 413 EXPECT_TRUE(die_dispatcher.StartDIE(0x753c964c8ab538aeLL,
michael@0 414 (DwarfTag) 0x8c22970e));
michael@0 415 die_dispatcher.ProcessAttributeSigned(0x753c964c8ab538aeLL,
michael@0 416 (DwarfAttribute) 0x4e2b7cfb,
michael@0 417 (DwarfForm) 0x610b7ae1,
michael@0 418 0x3ea5c609d7d7560fLL);
michael@0 419 die_dispatcher.EndDIE(0x753c964c8ab538aeLL);
michael@0 420 }
michael@0 421
michael@0 422 // Finish the root DIE (and thus the CU).
michael@0 423 die_dispatcher.EndDIE(0x15f0e06bdfe3c372LL);
michael@0 424 }
michael@0 425 }
michael@0 426
michael@0 427 // The DIEDispatcher destructor is supposed to delete all handlers on
michael@0 428 // the stack, except for the root.
michael@0 429 TEST(Dwarf2DIEHandler, FreeHandlersOnStack) {
michael@0 430 MockRootDIEHandler mock_root_handler;
michael@0 431 MockDIEHandler *mock_child_handler = new(MockDIEHandler);
michael@0 432 MockDIEHandler *mock_grandchild_handler = new(MockDIEHandler);
michael@0 433
michael@0 434 {
michael@0 435 InSequence s;
michael@0 436
michael@0 437 // We'll like the compilation unit header.
michael@0 438 EXPECT_CALL(mock_root_handler,
michael@0 439 StartCompilationUnit(0x87b41ba8381cd71cLL, 0xff, 0x89,
michael@0 440 0x76d392ff393ddda2LL, 0xbf))
michael@0 441 .WillOnce(Return(true));
michael@0 442
michael@0 443 // Root DIE.
michael@0 444 {
michael@0 445 EXPECT_CALL(mock_root_handler,
michael@0 446 StartRootDIE(0xbf13b761691ddc91LL, (DwarfTag) 0x98980361))
michael@0 447 .WillOnce(Return(true));
michael@0 448 EXPECT_CALL(mock_root_handler, EndAttributes())
michael@0 449 .WillOnce(Return(true));
michael@0 450
michael@0 451 // Child DIE.
michael@0 452 EXPECT_CALL(mock_root_handler,
michael@0 453 FindChildHandler(0x058f09240c5fc8c9LL,
michael@0 454 (DwarfTag) 0x898bf0d0))
michael@0 455 .WillOnce(Return(mock_child_handler));
michael@0 456 {
michael@0 457 EXPECT_CALL(*mock_child_handler, EndAttributes())
michael@0 458 .WillOnce(Return(true));
michael@0 459
michael@0 460 // Grandchild DIE.
michael@0 461 EXPECT_CALL(*mock_child_handler,
michael@0 462 FindChildHandler(0x32dc00c9945dc0c8LL,
michael@0 463 (DwarfTag) 0x2802d007))
michael@0 464 .WillOnce(Return(mock_grandchild_handler));
michael@0 465 {
michael@0 466 EXPECT_CALL(*mock_grandchild_handler,
michael@0 467 ProcessAttributeSigned((DwarfAttribute) 0x4e2b7cfb,
michael@0 468 (DwarfForm) 0x610b7ae1,
michael@0 469 0x3ea5c609d7d7560fLL))
michael@0 470 .WillOnce(Return());
michael@0 471
michael@0 472 // At this point, we abandon the traversal, so none of the
michael@0 473 // usual stuff should get called.
michael@0 474 EXPECT_CALL(*mock_grandchild_handler, EndAttributes())
michael@0 475 .Times(0);
michael@0 476 EXPECT_CALL(*mock_grandchild_handler, Finish())
michael@0 477 .Times(0);
michael@0 478 }
michael@0 479
michael@0 480 EXPECT_CALL(*mock_child_handler, Finish())
michael@0 481 .Times(0);
michael@0 482 }
michael@0 483
michael@0 484 EXPECT_CALL(mock_root_handler, Finish())
michael@0 485 .Times(0);
michael@0 486 }
michael@0 487 }
michael@0 488
michael@0 489 // The dispatcher.
michael@0 490 DIEDispatcher die_dispatcher(&mock_root_handler);
michael@0 491
michael@0 492 // Report the CU header.
michael@0 493 EXPECT_TRUE(die_dispatcher
michael@0 494 .StartCompilationUnit(0x87b41ba8381cd71cLL, 0xff, 0x89,
michael@0 495 0x76d392ff393ddda2LL, 0xbf));
michael@0 496 // Report the root DIE.
michael@0 497 {
michael@0 498 EXPECT_TRUE(die_dispatcher.StartDIE(0xbf13b761691ddc91LL,
michael@0 499 (DwarfTag) 0x98980361));
michael@0 500
michael@0 501 // Child DIE.
michael@0 502 {
michael@0 503 EXPECT_TRUE(die_dispatcher.StartDIE(0x058f09240c5fc8c9LL,
michael@0 504 (DwarfTag) 0x898bf0d0));
michael@0 505
michael@0 506 // Grandchild DIE.
michael@0 507 {
michael@0 508 EXPECT_TRUE(die_dispatcher.StartDIE(0x32dc00c9945dc0c8LL,
michael@0 509 (DwarfTag) 0x2802d007));
michael@0 510 die_dispatcher.ProcessAttributeSigned(0x32dc00c9945dc0c8LL,
michael@0 511 (DwarfAttribute) 0x4e2b7cfb,
michael@0 512 (DwarfForm) 0x610b7ae1,
michael@0 513 0x3ea5c609d7d7560fLL);
michael@0 514
michael@0 515 // Stop the traversal abruptly, so that there will still be
michael@0 516 // handlers on the stack when the dispatcher is destructed.
michael@0 517
michael@0 518 // No EndDIE call...
michael@0 519 }
michael@0 520 // No EndDIE call...
michael@0 521 }
michael@0 522 // No EndDIE call...
michael@0 523 }
michael@0 524 }

mercurial