toolkit/crashreporter/google-breakpad/src/processor/stack_frame_symbolizer.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/processor/stack_frame_symbolizer.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,133 @@
     1.4 +// Copyright (c) 2012 Google Inc.
     1.5 +// All rights reserved.
     1.6 +//
     1.7 +// Redistribution and use in source and binary forms, with or without
     1.8 +// modification, are permitted provided that the following conditions are
     1.9 +// met:
    1.10 +//
    1.11 +//     * Redistributions of source code must retain the above copyright
    1.12 +// notice, this list of conditions and the following disclaimer.
    1.13 +//     * Redistributions in binary form must reproduce the above
    1.14 +// copyright notice, this list of conditions and the following disclaimer
    1.15 +// in the documentation and/or other materials provided with the
    1.16 +// distribution.
    1.17 +//     * Neither the name of Google Inc. nor the names of its
    1.18 +// contributors may be used to endorse or promote products derived from
    1.19 +// this software without specific prior written permission.
    1.20 +//
    1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.32 +
    1.33 +// Implementation of StackFrameSymbolizer, which encapsulates the logic of how
    1.34 +// SourceLineResolverInterface interacts with SymbolSupplier to fill source
    1.35 +// line information in a stack frame, and also looks up WindowsFrameInfo or
    1.36 +// CFIFrameInfo for a stack frame.
    1.37 +
    1.38 +#include "google_breakpad/processor/stack_frame_symbolizer.h"
    1.39 +
    1.40 +#include <assert.h>
    1.41 +
    1.42 +#include "common/scoped_ptr.h"
    1.43 +#include "google_breakpad/processor/code_module.h"
    1.44 +#include "google_breakpad/processor/code_modules.h"
    1.45 +#include "google_breakpad/processor/source_line_resolver_interface.h"
    1.46 +#include "google_breakpad/processor/stack_frame.h"
    1.47 +#include "google_breakpad/processor/symbol_supplier.h"
    1.48 +#include "google_breakpad/processor/system_info.h"
    1.49 +#include "processor/linked_ptr.h"
    1.50 +#include "common/logging.h"
    1.51 +
    1.52 +namespace google_breakpad {
    1.53 +
    1.54 +StackFrameSymbolizer::StackFrameSymbolizer(
    1.55 +    SymbolSupplier* supplier,
    1.56 +    SourceLineResolverInterface* resolver) : supplier_(supplier),
    1.57 +                                             resolver_(resolver) { }
    1.58 +
    1.59 +StackFrameSymbolizer::SymbolizerResult StackFrameSymbolizer::FillSourceLineInfo(
    1.60 +    const CodeModules* modules,
    1.61 +    const SystemInfo* system_info,
    1.62 +    StackFrame* frame) {
    1.63 +  assert(frame);
    1.64 +
    1.65 +  if (!modules) return kError;
    1.66 +  const CodeModule* module = modules->GetModuleForAddress(frame->instruction);
    1.67 +  if (!module) return kError;
    1.68 +  frame->module = module;
    1.69 +
    1.70 +  if (!resolver_) return kError;  // no resolver.
    1.71 +  // If module is known to have missing symbol file, return.
    1.72 +  if (no_symbol_modules_.find(module->code_file()) !=
    1.73 +      no_symbol_modules_.end()) {
    1.74 +    return kError;
    1.75 +  }
    1.76 +
    1.77 +  // If module is already loaded, go ahead to fill source line info and return.
    1.78 +  if (resolver_->HasModule(frame->module)) {
    1.79 +    resolver_->FillSourceLineInfo(frame);
    1.80 +    return kNoError;
    1.81 +  }
    1.82 +
    1.83 +  // Module needs to fetch symbol file. First check to see if supplier exists.
    1.84 +  if (!supplier_) {
    1.85 +    return kError;
    1.86 +  }
    1.87 +
    1.88 +  // Start fetching symbol from supplier.
    1.89 +  string symbol_file;
    1.90 +  char* symbol_data = NULL;
    1.91 +  SymbolSupplier::SymbolResult symbol_result = supplier_->GetCStringSymbolData(
    1.92 +      module, system_info, &symbol_file, &symbol_data);
    1.93 +
    1.94 +  switch (symbol_result) {
    1.95 +    case SymbolSupplier::FOUND: {
    1.96 +      bool load_success = resolver_->LoadModuleUsingMemoryBuffer(frame->module,
    1.97 +                                                                 symbol_data);
    1.98 +      if (resolver_->ShouldDeleteMemoryBufferAfterLoadModule()) {
    1.99 +        supplier_->FreeSymbolData(module);
   1.100 +      }
   1.101 +
   1.102 +      if (load_success) {
   1.103 +        resolver_->FillSourceLineInfo(frame);
   1.104 +        return kNoError;
   1.105 +      } else {
   1.106 +        BPLOG(ERROR) << "Failed to load symbol file in resolver.";
   1.107 +        no_symbol_modules_.insert(module->code_file());
   1.108 +        return kError;
   1.109 +      }
   1.110 +    }
   1.111 +
   1.112 +    case SymbolSupplier::NOT_FOUND:
   1.113 +      no_symbol_modules_.insert(module->code_file());
   1.114 +      return kError;
   1.115 +
   1.116 +    case SymbolSupplier::INTERRUPT:
   1.117 +      return kInterrupt;
   1.118 +
   1.119 +    default:
   1.120 +      BPLOG(ERROR) << "Unknown SymbolResult enum: " << symbol_result;
   1.121 +      return kError;
   1.122 +  }
   1.123 +  return kError;
   1.124 +}
   1.125 +
   1.126 +WindowsFrameInfo* StackFrameSymbolizer::FindWindowsFrameInfo(
   1.127 +    const StackFrame* frame) {
   1.128 +  return resolver_ ? resolver_->FindWindowsFrameInfo(frame) : NULL;
   1.129 +}
   1.130 +
   1.131 +CFIFrameInfo* StackFrameSymbolizer::FindCFIFrameInfo(
   1.132 +    const StackFrame* frame) {
   1.133 +  return resolver_ ? resolver_->FindCFIFrameInfo(frame) : NULL;
   1.134 +}
   1.135 +
   1.136 +}  // namespace google_breakpad

mercurial