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