toolkit/crashreporter/google-breakpad/src/common/dwarf/dwarf2diehandler.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 // Copyright (c) 2010 Google Inc. All Rights Reserved.
michael@0 2 //
michael@0 3 // Redistribution and use in source and binary forms, with or without
michael@0 4 // modification, are permitted provided that the following conditions are
michael@0 5 // met:
michael@0 6 //
michael@0 7 // * Redistributions of source code must retain the above copyright
michael@0 8 // notice, this list of conditions and the following disclaimer.
michael@0 9 // * Redistributions in binary form must reproduce the above
michael@0 10 // copyright notice, this list of conditions and the following disclaimer
michael@0 11 // in the documentation and/or other materials provided with the
michael@0 12 // distribution.
michael@0 13 // * Neither the name of Google Inc. nor the names of its
michael@0 14 // contributors may be used to endorse or promote products derived from
michael@0 15 // this software without specific prior written permission.
michael@0 16 //
michael@0 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
michael@0 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@0 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 28
michael@0 29 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
michael@0 30
michael@0 31 // dwarf2diehandler.cc: Implement the dwarf2reader::DieDispatcher class.
michael@0 32 // See dwarf2diehandler.h for details.
michael@0 33
michael@0 34 #include <assert.h>
michael@0 35
michael@0 36 #include <string>
michael@0 37
michael@0 38 #include "common/dwarf/dwarf2diehandler.h"
michael@0 39 #include "common/using_std_string.h"
michael@0 40
michael@0 41 namespace dwarf2reader {
michael@0 42
michael@0 43 DIEDispatcher::~DIEDispatcher() {
michael@0 44 while (!die_handlers_.empty()) {
michael@0 45 HandlerStack &entry = die_handlers_.top();
michael@0 46 if (entry.handler_ != root_handler_)
michael@0 47 delete entry.handler_;
michael@0 48 die_handlers_.pop();
michael@0 49 }
michael@0 50 }
michael@0 51
michael@0 52 bool DIEDispatcher::StartCompilationUnit(uint64 offset, uint8 address_size,
michael@0 53 uint8 offset_size, uint64 cu_length,
michael@0 54 uint8 dwarf_version) {
michael@0 55 return root_handler_->StartCompilationUnit(offset, address_size,
michael@0 56 offset_size, cu_length,
michael@0 57 dwarf_version);
michael@0 58 }
michael@0 59
michael@0 60 bool DIEDispatcher::StartDIE(uint64 offset, enum DwarfTag tag) {
michael@0 61 // The stack entry for the parent of this DIE, if there is one.
michael@0 62 HandlerStack *parent = die_handlers_.empty() ? NULL : &die_handlers_.top();
michael@0 63
michael@0 64 // Does this call indicate that we're done receiving the parent's
michael@0 65 // attributes' values? If so, call its EndAttributes member function.
michael@0 66 if (parent && parent->handler_ && !parent->reported_attributes_end_) {
michael@0 67 parent->reported_attributes_end_ = true;
michael@0 68 if (!parent->handler_->EndAttributes()) {
michael@0 69 // Finish off this handler now. and edit *PARENT to indicate that
michael@0 70 // we don't want to visit any of the children.
michael@0 71 parent->handler_->Finish();
michael@0 72 if (parent->handler_ != root_handler_)
michael@0 73 delete parent->handler_;
michael@0 74 parent->handler_ = NULL;
michael@0 75 return false;
michael@0 76 }
michael@0 77 }
michael@0 78
michael@0 79 // Find a handler for this DIE.
michael@0 80 DIEHandler *handler;
michael@0 81 if (parent) {
michael@0 82 if (parent->handler_)
michael@0 83 // Ask the parent to find a handler.
michael@0 84 handler = parent->handler_->FindChildHandler(offset, tag);
michael@0 85 else
michael@0 86 // No parent handler means we're not interested in any of our
michael@0 87 // children.
michael@0 88 handler = NULL;
michael@0 89 } else {
michael@0 90 // This is the root DIE. For a non-root DIE, the parent's handler
michael@0 91 // decides whether to visit it, but the root DIE has no parent
michael@0 92 // handler, so we have a special method on the root DIE handler
michael@0 93 // itself to decide.
michael@0 94 if (root_handler_->StartRootDIE(offset, tag))
michael@0 95 handler = root_handler_;
michael@0 96 else
michael@0 97 handler = NULL;
michael@0 98 }
michael@0 99
michael@0 100 // Push a handler stack entry for this new handler. As an
michael@0 101 // optimization, we don't push NULL-handler entries on top of other
michael@0 102 // NULL-handler entries; we just let the oldest such entry stand for
michael@0 103 // the whole subtree.
michael@0 104 if (handler || !parent || parent->handler_) {
michael@0 105 HandlerStack entry;
michael@0 106 entry.offset_ = offset;
michael@0 107 entry.handler_ = handler;
michael@0 108 entry.reported_attributes_end_ = false;
michael@0 109 die_handlers_.push(entry);
michael@0 110 }
michael@0 111
michael@0 112 return handler != NULL;
michael@0 113 }
michael@0 114
michael@0 115 void DIEDispatcher::EndDIE(uint64 offset) {
michael@0 116 assert(!die_handlers_.empty());
michael@0 117 HandlerStack *entry = &die_handlers_.top();
michael@0 118 if (entry->handler_) {
michael@0 119 // This entry had better be the handler for this DIE.
michael@0 120 assert(entry->offset_ == offset);
michael@0 121 // If a DIE has no children, this EndDIE call indicates that we're
michael@0 122 // done receiving its attributes' values.
michael@0 123 if (!entry->reported_attributes_end_)
michael@0 124 entry->handler_->EndAttributes(); // Ignore return value: no children.
michael@0 125 entry->handler_->Finish();
michael@0 126 if (entry->handler_ != root_handler_)
michael@0 127 delete entry->handler_;
michael@0 128 } else {
michael@0 129 // If this DIE is within a tree we're ignoring, then don't pop the
michael@0 130 // handler stack: that entry stands for the whole tree.
michael@0 131 if (entry->offset_ != offset)
michael@0 132 return;
michael@0 133 }
michael@0 134 die_handlers_.pop();
michael@0 135 }
michael@0 136
michael@0 137 void DIEDispatcher::ProcessAttributeUnsigned(uint64 offset,
michael@0 138 enum DwarfAttribute attr,
michael@0 139 enum DwarfForm form,
michael@0 140 uint64 data) {
michael@0 141 HandlerStack &current = die_handlers_.top();
michael@0 142 // This had better be an attribute of the DIE we were meant to handle.
michael@0 143 assert(offset == current.offset_);
michael@0 144 current.handler_->ProcessAttributeUnsigned(attr, form, data);
michael@0 145 }
michael@0 146
michael@0 147 void DIEDispatcher::ProcessAttributeSigned(uint64 offset,
michael@0 148 enum DwarfAttribute attr,
michael@0 149 enum DwarfForm form,
michael@0 150 int64 data) {
michael@0 151 HandlerStack &current = die_handlers_.top();
michael@0 152 // This had better be an attribute of the DIE we were meant to handle.
michael@0 153 assert(offset == current.offset_);
michael@0 154 current.handler_->ProcessAttributeSigned(attr, form, data);
michael@0 155 }
michael@0 156
michael@0 157 void DIEDispatcher::ProcessAttributeReference(uint64 offset,
michael@0 158 enum DwarfAttribute attr,
michael@0 159 enum DwarfForm form,
michael@0 160 uint64 data) {
michael@0 161 HandlerStack &current = die_handlers_.top();
michael@0 162 // This had better be an attribute of the DIE we were meant to handle.
michael@0 163 assert(offset == current.offset_);
michael@0 164 current.handler_->ProcessAttributeReference(attr, form, data);
michael@0 165 }
michael@0 166
michael@0 167 void DIEDispatcher::ProcessAttributeBuffer(uint64 offset,
michael@0 168 enum DwarfAttribute attr,
michael@0 169 enum DwarfForm form,
michael@0 170 const char* data,
michael@0 171 uint64 len) {
michael@0 172 HandlerStack &current = die_handlers_.top();
michael@0 173 // This had better be an attribute of the DIE we were meant to handle.
michael@0 174 assert(offset == current.offset_);
michael@0 175 current.handler_->ProcessAttributeBuffer(attr, form, data, len);
michael@0 176 }
michael@0 177
michael@0 178 void DIEDispatcher::ProcessAttributeString(uint64 offset,
michael@0 179 enum DwarfAttribute attr,
michael@0 180 enum DwarfForm form,
michael@0 181 const string& data) {
michael@0 182 HandlerStack &current = die_handlers_.top();
michael@0 183 // This had better be an attribute of the DIE we were meant to handle.
michael@0 184 assert(offset == current.offset_);
michael@0 185 current.handler_->ProcessAttributeString(attr, form, data);
michael@0 186 }
michael@0 187
michael@0 188 void DIEDispatcher::ProcessAttributeSignature(uint64 offset,
michael@0 189 enum DwarfAttribute attr,
michael@0 190 enum DwarfForm form,
michael@0 191 uint64 signature) {
michael@0 192 HandlerStack &current = die_handlers_.top();
michael@0 193 // This had better be an attribute of the DIE we were meant to handle.
michael@0 194 assert(offset == current.offset_);
michael@0 195 current.handler_->ProcessAttributeSignature(attr, form, signature);
michael@0 196 }
michael@0 197
michael@0 198 } // namespace dwarf2reader

mercurial