/ src / processor / microdump_processor.cc
microdump_processor.cc
  1  // Copyright 2014 Google LLC
  2  //
  3  // Redistribution and use in source and binary forms, with or without
  4  // modification, are permitted provided that the following conditions are
  5  // met:
  6  //
  7  //     * Redistributions of source code must retain the above copyright
  8  // notice, this list of conditions and the following disclaimer.
  9  //     * Redistributions in binary form must reproduce the above
 10  // copyright notice, this list of conditions and the following disclaimer
 11  // in the documentation and/or other materials provided with the
 12  // distribution.
 13  //    * Neither the name of Google LLC nor the names of its
 14  // contributors may be used to endorse or promote products derived from
 15  // this software without specific prior written permission.
 16  //
 17  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 19  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 20  // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 21  // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 22  // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 23  // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 24  // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 25  // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26  // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 27  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28  
 29  // microdump_processor.cc: A microdump processor.
 30  //
 31  // See microdump_processor.h for documentation.
 32  
 33  #ifdef HAVE_CONFIG_H
 34  #include <config.h>  // Must come first
 35  #endif
 36  
 37  #include "google_breakpad/processor/microdump_processor.h"
 38  
 39  #include <assert.h>
 40  
 41  #include <string>
 42  
 43  #include "common/using_std_string.h"
 44  #include "google_breakpad/processor/call_stack.h"
 45  #include "google_breakpad/processor/microdump.h"
 46  #include "google_breakpad/processor/process_state.h"
 47  #include "google_breakpad/processor/stackwalker.h"
 48  #include "google_breakpad/processor/stack_frame_symbolizer.h"
 49  #include "processor/logging.h"
 50  
 51  namespace google_breakpad {
 52  
 53  MicrodumpProcessor::MicrodumpProcessor(StackFrameSymbolizer* frame_symbolizer)
 54      : frame_symbolizer_(frame_symbolizer) {
 55    assert(frame_symbolizer);
 56  }
 57  
 58  MicrodumpProcessor::~MicrodumpProcessor() {}
 59  
 60  ProcessResult MicrodumpProcessor::Process(Microdump *microdump,
 61                                            ProcessState* process_state) {
 62    assert(process_state);
 63  
 64    process_state->Clear();
 65  
 66    process_state->modules_ = microdump->GetModules()->Copy();
 67    scoped_ptr<Stackwalker> stackwalker(
 68        Stackwalker::StackwalkerForCPU(
 69                              &process_state->system_info_,
 70                              microdump->GetContext(),
 71                              microdump->GetMemory(),
 72                              process_state->modules_,
 73                              /* unloaded_modules= */ NULL,
 74                              frame_symbolizer_));
 75  
 76    scoped_ptr<CallStack> stack(new CallStack());
 77    if (stackwalker.get()) {
 78      if (!stackwalker->Walk(stack.get(),
 79                             &process_state->modules_without_symbols_,
 80                             &process_state->modules_with_corrupt_symbols_)) {
 81        BPLOG(INFO) << "Processing was interrupted.";
 82        return PROCESS_SYMBOL_SUPPLIER_INTERRUPTED;
 83      }
 84    } else {
 85      BPLOG(ERROR) << "No stackwalker found for microdump.";
 86      return PROCESS_ERROR_NO_THREAD_LIST;
 87    }
 88  
 89    process_state->threads_.push_back(stack.release());
 90    process_state->thread_memory_regions_.push_back(microdump->GetMemory());
 91    process_state->crashed_ = true;
 92    process_state->requesting_thread_ = 0;
 93    process_state->system_info_ = *microdump->GetSystemInfo();
 94    process_state->crash_reason_ = microdump->GetCrashReason();
 95    process_state->crash_address_ = microdump->GetCrashAddress();
 96  
 97    return PROCESS_OK;
 98  }
 99  
100  }  // namespace google_breakpad