• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
MicrodumpProcessor(StackFrameSymbolizer * frame_symbolizer)50 MicrodumpProcessor::MicrodumpProcessor(StackFrameSymbolizer* frame_symbolizer)
51     : frame_symbolizer_(frame_symbolizer) {
52   assert(frame_symbolizer);
53 }
54 
~MicrodumpProcessor()55 MicrodumpProcessor::~MicrodumpProcessor() {}
56 
Process(Microdump * microdump,ProcessState * process_state)57 ProcessResult MicrodumpProcessor::Process(Microdump *microdump,
58                                           ProcessState* process_state) {
59   assert(process_state);
60 
61   process_state->Clear();
62 
63   process_state->modules_ = microdump->GetModules()->Copy();
64   scoped_ptr<Stackwalker> stackwalker(
65       Stackwalker::StackwalkerForCPU(
66                             &process_state->system_info_,
67                             microdump->GetContext(),
68                             microdump->GetMemory(),
69                             process_state->modules_,
70                             /* unloaded_modules= */ NULL,
71                             frame_symbolizer_));
72 
73   scoped_ptr<CallStack> stack(new CallStack());
74   if (stackwalker.get()) {
75     if (!stackwalker->Walk(stack.get(),
76                            &process_state->modules_without_symbols_,
77                            &process_state->modules_with_corrupt_symbols_)) {
78       BPLOG(INFO) << "Processing was interrupted.";
79       return PROCESS_SYMBOL_SUPPLIER_INTERRUPTED;
80     }
81   } else {
82     BPLOG(ERROR) << "No stackwalker found for microdump.";
83     return PROCESS_ERROR_NO_THREAD_LIST;
84   }
85 
86   process_state->threads_.push_back(stack.release());
87   process_state->thread_memory_regions_.push_back(microdump->GetMemory());
88   process_state->crashed_ = true;
89   process_state->requesting_thread_ = 0;
90   process_state->system_info_ = *microdump->GetSystemInfo();
91   process_state->crash_reason_ = microdump->GetCrashReason();
92   process_state->crash_address_ = microdump->GetCrashAddress();
93 
94   return PROCESS_OK;
95 }
96 
97 }  // namespace google_breakpad
98