Wed, 31 Dec 2014 06:09:35 +0100
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) 2012 Google Inc. |
michael@0 | 2 | // All rights reserved. |
michael@0 | 3 | // |
michael@0 | 4 | // Redistribution and use in source and binary forms, with or without |
michael@0 | 5 | // modification, are permitted provided that the following conditions are |
michael@0 | 6 | // met: |
michael@0 | 7 | // |
michael@0 | 8 | // * Redistributions of source code must retain the above copyright |
michael@0 | 9 | // notice, this list of conditions and the following disclaimer. |
michael@0 | 10 | // * Redistributions in binary form must reproduce the above |
michael@0 | 11 | // copyright notice, this list of conditions and the following disclaimer |
michael@0 | 12 | // in the documentation and/or other materials provided with the |
michael@0 | 13 | // distribution. |
michael@0 | 14 | // * Neither the name of Google Inc. nor the names of its |
michael@0 | 15 | // contributors may be used to endorse or promote products derived from |
michael@0 | 16 | // this software without specific prior written permission. |
michael@0 | 17 | // |
michael@0 | 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
michael@0 | 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@0 | 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 29 | |
michael@0 | 30 | // Implementation of StackFrameSymbolizer, which encapsulates the logic of how |
michael@0 | 31 | // SourceLineResolverInterface interacts with SymbolSupplier to fill source |
michael@0 | 32 | // line information in a stack frame, and also looks up WindowsFrameInfo or |
michael@0 | 33 | // CFIFrameInfo for a stack frame. |
michael@0 | 34 | |
michael@0 | 35 | #include "google_breakpad/processor/stack_frame_symbolizer.h" |
michael@0 | 36 | |
michael@0 | 37 | #include <assert.h> |
michael@0 | 38 | |
michael@0 | 39 | #include "common/scoped_ptr.h" |
michael@0 | 40 | #include "google_breakpad/processor/code_module.h" |
michael@0 | 41 | #include "google_breakpad/processor/code_modules.h" |
michael@0 | 42 | #include "google_breakpad/processor/source_line_resolver_interface.h" |
michael@0 | 43 | #include "google_breakpad/processor/stack_frame.h" |
michael@0 | 44 | #include "google_breakpad/processor/symbol_supplier.h" |
michael@0 | 45 | #include "google_breakpad/processor/system_info.h" |
michael@0 | 46 | #include "processor/linked_ptr.h" |
michael@0 | 47 | #include "common/logging.h" |
michael@0 | 48 | |
michael@0 | 49 | namespace google_breakpad { |
michael@0 | 50 | |
michael@0 | 51 | StackFrameSymbolizer::StackFrameSymbolizer( |
michael@0 | 52 | SymbolSupplier* supplier, |
michael@0 | 53 | SourceLineResolverInterface* resolver) : supplier_(supplier), |
michael@0 | 54 | resolver_(resolver) { } |
michael@0 | 55 | |
michael@0 | 56 | StackFrameSymbolizer::SymbolizerResult StackFrameSymbolizer::FillSourceLineInfo( |
michael@0 | 57 | const CodeModules* modules, |
michael@0 | 58 | const SystemInfo* system_info, |
michael@0 | 59 | StackFrame* frame) { |
michael@0 | 60 | assert(frame); |
michael@0 | 61 | |
michael@0 | 62 | if (!modules) return kError; |
michael@0 | 63 | const CodeModule* module = modules->GetModuleForAddress(frame->instruction); |
michael@0 | 64 | if (!module) return kError; |
michael@0 | 65 | frame->module = module; |
michael@0 | 66 | |
michael@0 | 67 | if (!resolver_) return kError; // no resolver. |
michael@0 | 68 | // If module is known to have missing symbol file, return. |
michael@0 | 69 | if (no_symbol_modules_.find(module->code_file()) != |
michael@0 | 70 | no_symbol_modules_.end()) { |
michael@0 | 71 | return kError; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | // If module is already loaded, go ahead to fill source line info and return. |
michael@0 | 75 | if (resolver_->HasModule(frame->module)) { |
michael@0 | 76 | resolver_->FillSourceLineInfo(frame); |
michael@0 | 77 | return kNoError; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | // Module needs to fetch symbol file. First check to see if supplier exists. |
michael@0 | 81 | if (!supplier_) { |
michael@0 | 82 | return kError; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | // Start fetching symbol from supplier. |
michael@0 | 86 | string symbol_file; |
michael@0 | 87 | char* symbol_data = NULL; |
michael@0 | 88 | SymbolSupplier::SymbolResult symbol_result = supplier_->GetCStringSymbolData( |
michael@0 | 89 | module, system_info, &symbol_file, &symbol_data); |
michael@0 | 90 | |
michael@0 | 91 | switch (symbol_result) { |
michael@0 | 92 | case SymbolSupplier::FOUND: { |
michael@0 | 93 | bool load_success = resolver_->LoadModuleUsingMemoryBuffer(frame->module, |
michael@0 | 94 | symbol_data); |
michael@0 | 95 | if (resolver_->ShouldDeleteMemoryBufferAfterLoadModule()) { |
michael@0 | 96 | supplier_->FreeSymbolData(module); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | if (load_success) { |
michael@0 | 100 | resolver_->FillSourceLineInfo(frame); |
michael@0 | 101 | return kNoError; |
michael@0 | 102 | } else { |
michael@0 | 103 | BPLOG(ERROR) << "Failed to load symbol file in resolver."; |
michael@0 | 104 | no_symbol_modules_.insert(module->code_file()); |
michael@0 | 105 | return kError; |
michael@0 | 106 | } |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | case SymbolSupplier::NOT_FOUND: |
michael@0 | 110 | no_symbol_modules_.insert(module->code_file()); |
michael@0 | 111 | return kError; |
michael@0 | 112 | |
michael@0 | 113 | case SymbolSupplier::INTERRUPT: |
michael@0 | 114 | return kInterrupt; |
michael@0 | 115 | |
michael@0 | 116 | default: |
michael@0 | 117 | BPLOG(ERROR) << "Unknown SymbolResult enum: " << symbol_result; |
michael@0 | 118 | return kError; |
michael@0 | 119 | } |
michael@0 | 120 | return kError; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | WindowsFrameInfo* StackFrameSymbolizer::FindWindowsFrameInfo( |
michael@0 | 124 | const StackFrame* frame) { |
michael@0 | 125 | return resolver_ ? resolver_->FindWindowsFrameInfo(frame) : NULL; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | CFIFrameInfo* StackFrameSymbolizer::FindCFIFrameInfo( |
michael@0 | 129 | const StackFrame* frame) { |
michael@0 | 130 | return resolver_ ? resolver_->FindCFIFrameInfo(frame) : NULL; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | } // namespace google_breakpad |