1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/dwarf/dwarf2diehandler.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,198 @@ 1.4 +// Copyright (c) 2010 Google Inc. All Rights Reserved. 1.5 +// 1.6 +// Redistribution and use in source and binary forms, with or without 1.7 +// modification, are permitted provided that the following conditions are 1.8 +// met: 1.9 +// 1.10 +// * Redistributions of source code must retain the above copyright 1.11 +// notice, this list of conditions and the following disclaimer. 1.12 +// * Redistributions in binary form must reproduce the above 1.13 +// copyright notice, this list of conditions and the following disclaimer 1.14 +// in the documentation and/or other materials provided with the 1.15 +// distribution. 1.16 +// * Neither the name of Google Inc. nor the names of its 1.17 +// contributors may be used to endorse or promote products derived from 1.18 +// this software without specific prior written permission. 1.19 +// 1.20 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.21 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.22 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.23 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.24 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.25 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.26 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.27 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.28 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.29 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.30 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.31 + 1.32 +// Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> 1.33 + 1.34 +// dwarf2diehandler.cc: Implement the dwarf2reader::DieDispatcher class. 1.35 +// See dwarf2diehandler.h for details. 1.36 + 1.37 +#include <assert.h> 1.38 + 1.39 +#include <string> 1.40 + 1.41 +#include "common/dwarf/dwarf2diehandler.h" 1.42 +#include "common/using_std_string.h" 1.43 + 1.44 +namespace dwarf2reader { 1.45 + 1.46 +DIEDispatcher::~DIEDispatcher() { 1.47 + while (!die_handlers_.empty()) { 1.48 + HandlerStack &entry = die_handlers_.top(); 1.49 + if (entry.handler_ != root_handler_) 1.50 + delete entry.handler_; 1.51 + die_handlers_.pop(); 1.52 + } 1.53 +} 1.54 + 1.55 +bool DIEDispatcher::StartCompilationUnit(uint64 offset, uint8 address_size, 1.56 + uint8 offset_size, uint64 cu_length, 1.57 + uint8 dwarf_version) { 1.58 + return root_handler_->StartCompilationUnit(offset, address_size, 1.59 + offset_size, cu_length, 1.60 + dwarf_version); 1.61 +} 1.62 + 1.63 +bool DIEDispatcher::StartDIE(uint64 offset, enum DwarfTag tag) { 1.64 + // The stack entry for the parent of this DIE, if there is one. 1.65 + HandlerStack *parent = die_handlers_.empty() ? NULL : &die_handlers_.top(); 1.66 + 1.67 + // Does this call indicate that we're done receiving the parent's 1.68 + // attributes' values? If so, call its EndAttributes member function. 1.69 + if (parent && parent->handler_ && !parent->reported_attributes_end_) { 1.70 + parent->reported_attributes_end_ = true; 1.71 + if (!parent->handler_->EndAttributes()) { 1.72 + // Finish off this handler now. and edit *PARENT to indicate that 1.73 + // we don't want to visit any of the children. 1.74 + parent->handler_->Finish(); 1.75 + if (parent->handler_ != root_handler_) 1.76 + delete parent->handler_; 1.77 + parent->handler_ = NULL; 1.78 + return false; 1.79 + } 1.80 + } 1.81 + 1.82 + // Find a handler for this DIE. 1.83 + DIEHandler *handler; 1.84 + if (parent) { 1.85 + if (parent->handler_) 1.86 + // Ask the parent to find a handler. 1.87 + handler = parent->handler_->FindChildHandler(offset, tag); 1.88 + else 1.89 + // No parent handler means we're not interested in any of our 1.90 + // children. 1.91 + handler = NULL; 1.92 + } else { 1.93 + // This is the root DIE. For a non-root DIE, the parent's handler 1.94 + // decides whether to visit it, but the root DIE has no parent 1.95 + // handler, so we have a special method on the root DIE handler 1.96 + // itself to decide. 1.97 + if (root_handler_->StartRootDIE(offset, tag)) 1.98 + handler = root_handler_; 1.99 + else 1.100 + handler = NULL; 1.101 + } 1.102 + 1.103 + // Push a handler stack entry for this new handler. As an 1.104 + // optimization, we don't push NULL-handler entries on top of other 1.105 + // NULL-handler entries; we just let the oldest such entry stand for 1.106 + // the whole subtree. 1.107 + if (handler || !parent || parent->handler_) { 1.108 + HandlerStack entry; 1.109 + entry.offset_ = offset; 1.110 + entry.handler_ = handler; 1.111 + entry.reported_attributes_end_ = false; 1.112 + die_handlers_.push(entry); 1.113 + } 1.114 + 1.115 + return handler != NULL; 1.116 +} 1.117 + 1.118 +void DIEDispatcher::EndDIE(uint64 offset) { 1.119 + assert(!die_handlers_.empty()); 1.120 + HandlerStack *entry = &die_handlers_.top(); 1.121 + if (entry->handler_) { 1.122 + // This entry had better be the handler for this DIE. 1.123 + assert(entry->offset_ == offset); 1.124 + // If a DIE has no children, this EndDIE call indicates that we're 1.125 + // done receiving its attributes' values. 1.126 + if (!entry->reported_attributes_end_) 1.127 + entry->handler_->EndAttributes(); // Ignore return value: no children. 1.128 + entry->handler_->Finish(); 1.129 + if (entry->handler_ != root_handler_) 1.130 + delete entry->handler_; 1.131 + } else { 1.132 + // If this DIE is within a tree we're ignoring, then don't pop the 1.133 + // handler stack: that entry stands for the whole tree. 1.134 + if (entry->offset_ != offset) 1.135 + return; 1.136 + } 1.137 + die_handlers_.pop(); 1.138 +} 1.139 + 1.140 +void DIEDispatcher::ProcessAttributeUnsigned(uint64 offset, 1.141 + enum DwarfAttribute attr, 1.142 + enum DwarfForm form, 1.143 + uint64 data) { 1.144 + HandlerStack ¤t = die_handlers_.top(); 1.145 + // This had better be an attribute of the DIE we were meant to handle. 1.146 + assert(offset == current.offset_); 1.147 + current.handler_->ProcessAttributeUnsigned(attr, form, data); 1.148 +} 1.149 + 1.150 +void DIEDispatcher::ProcessAttributeSigned(uint64 offset, 1.151 + enum DwarfAttribute attr, 1.152 + enum DwarfForm form, 1.153 + int64 data) { 1.154 + HandlerStack ¤t = die_handlers_.top(); 1.155 + // This had better be an attribute of the DIE we were meant to handle. 1.156 + assert(offset == current.offset_); 1.157 + current.handler_->ProcessAttributeSigned(attr, form, data); 1.158 +} 1.159 + 1.160 +void DIEDispatcher::ProcessAttributeReference(uint64 offset, 1.161 + enum DwarfAttribute attr, 1.162 + enum DwarfForm form, 1.163 + uint64 data) { 1.164 + HandlerStack ¤t = die_handlers_.top(); 1.165 + // This had better be an attribute of the DIE we were meant to handle. 1.166 + assert(offset == current.offset_); 1.167 + current.handler_->ProcessAttributeReference(attr, form, data); 1.168 +} 1.169 + 1.170 +void DIEDispatcher::ProcessAttributeBuffer(uint64 offset, 1.171 + enum DwarfAttribute attr, 1.172 + enum DwarfForm form, 1.173 + const char* data, 1.174 + uint64 len) { 1.175 + HandlerStack ¤t = die_handlers_.top(); 1.176 + // This had better be an attribute of the DIE we were meant to handle. 1.177 + assert(offset == current.offset_); 1.178 + current.handler_->ProcessAttributeBuffer(attr, form, data, len); 1.179 +} 1.180 + 1.181 +void DIEDispatcher::ProcessAttributeString(uint64 offset, 1.182 + enum DwarfAttribute attr, 1.183 + enum DwarfForm form, 1.184 + const string& data) { 1.185 + HandlerStack ¤t = die_handlers_.top(); 1.186 + // This had better be an attribute of the DIE we were meant to handle. 1.187 + assert(offset == current.offset_); 1.188 + current.handler_->ProcessAttributeString(attr, form, data); 1.189 +} 1.190 + 1.191 +void DIEDispatcher::ProcessAttributeSignature(uint64 offset, 1.192 + enum DwarfAttribute attr, 1.193 + enum DwarfForm form, 1.194 + uint64 signature) { 1.195 + HandlerStack ¤t = die_handlers_.top(); 1.196 + // This had better be an attribute of the DIE we were meant to handle. 1.197 + assert(offset == current.offset_); 1.198 + current.handler_->ProcessAttributeSignature(attr, form, signature); 1.199 +} 1.200 + 1.201 +} // namespace dwarf2reader