33cd0206fd052e6faf7ce4d6119442c6ce3a3c37
[platform/framework/web/crosswalk.git] / src / breakpad / src / google_breakpad / processor / minidump_processor.h
1 // Copyright (c) 2006, 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 #ifndef GOOGLE_BREAKPAD_PROCESSOR_MINIDUMP_PROCESSOR_H__
31 #define GOOGLE_BREAKPAD_PROCESSOR_MINIDUMP_PROCESSOR_H__
32
33 #include <assert.h>
34 #include <string>
35
36 #include "common/using_std_string.h"
37 #include "google_breakpad/common/breakpad_types.h"
38
39 namespace google_breakpad {
40
41 class Minidump;
42 class ProcessState;
43 class StackFrameSymbolizer;
44 class SourceLineResolverInterface;
45 class SymbolSupplier;
46 struct SystemInfo;
47 // Return type for Process()
48 enum ProcessResult {
49   PROCESS_OK,                                 // The minidump was
50                                               // processed
51                                               // successfully.
52
53   PROCESS_ERROR_MINIDUMP_NOT_FOUND,           // The minidump file
54                                               // was not found.
55
56   PROCESS_ERROR_NO_MINIDUMP_HEADER,           // The minidump file
57                                               // had no header
58
59   PROCESS_ERROR_NO_THREAD_LIST,               // The minidump file
60                                               // had no thread list.
61
62   PROCESS_ERROR_GETTING_THREAD,               // There was an error
63                                               // getting one
64                                               // thread's data from
65                                               // the minidump.
66
67   PROCESS_ERROR_GETTING_THREAD_ID,            // There was an error
68                                               // getting a thread id
69                                               // from the thread's
70                                               // data.
71
72   PROCESS_ERROR_DUPLICATE_REQUESTING_THREADS, // There was more than
73                                               // one requesting
74                                               // thread.
75
76   PROCESS_SYMBOL_SUPPLIER_INTERRUPTED         // The minidump
77                                               // processing was
78                                               // interrupted by the
79                                               // SymbolSupplier(not
80                                               // fatal)
81 };
82
83 class MinidumpProcessor {
84  public:
85   // Initializes this MinidumpProcessor.  supplier should be an
86   // implementation of the SymbolSupplier abstract base class.
87   MinidumpProcessor(SymbolSupplier* supplier,
88                     SourceLineResolverInterface* resolver);
89
90   // Initializes the MinidumpProcessor with the option of
91   // enabling the exploitability framework to analyze dumps
92   // for probable security relevance.
93   MinidumpProcessor(SymbolSupplier* supplier,
94                     SourceLineResolverInterface* resolver,
95                     bool enable_exploitability);
96
97   // Initializes the MinidumpProcessor with source line resolver helper, and
98   // the option of enabling the exploitability framework to analyze dumps
99   // for probable security relevance.
100   // Does not take ownership of resolver_helper, which must NOT be NULL.
101   MinidumpProcessor(StackFrameSymbolizer* stack_frame_symbolizer,
102                     bool enable_exploitability);
103
104   ~MinidumpProcessor();
105
106   // Processes the minidump file and fills process_state with the result.
107   ProcessResult Process(const string &minidump_file,
108                         ProcessState* process_state);
109
110   // Processes the minidump structure and fills process_state with the
111   // result.
112   ProcessResult Process(Minidump* minidump,
113                         ProcessState* process_state);
114   // Populates the cpu_* fields of the |info| parameter with textual
115   // representations of the CPU type that the minidump in |dump| was
116   // produced on.  Returns false if this information is not available in
117   // the minidump.
118   static bool GetCPUInfo(Minidump* dump, SystemInfo* info);
119
120   // Populates the os_* fields of the |info| parameter with textual
121   // representations of the operating system that the minidump in |dump|
122   // was produced on.  Returns false if this information is not available in
123   // the minidump.
124   static bool GetOSInfo(Minidump* dump, SystemInfo* info);
125
126   // Returns a textual representation of the reason that a crash occurred,
127   // if the minidump in dump was produced as a result of a crash.  Returns
128   // an empty string if this information cannot be determined.  If address
129   // is non-NULL, it will be set to contain the address that caused the
130   // exception, if this information is available.  This will be a code
131   // address when the crash was caused by problems such as illegal
132   // instructions or divisions by zero, or a data address when the crash
133   // was caused by a memory access violation.
134   static string GetCrashReason(Minidump* dump, uint64_t* address);
135
136   // This function returns true if the passed-in error code is
137   // something unrecoverable(i.e. retry should not happen).  For
138   // instance, if the minidump is corrupt, then it makes no sense to
139   // retry as we won't be able to glean additional information.
140   // However, as an example of the other case, the symbol supplier can
141   // return an error code indicating it was 'interrupted', which can
142   // happen of the symbols are fetched from a remote store, and a
143   // retry might be successful later on.
144   // You should not call this method with PROCESS_OK! Test for
145   // that separately before calling this.
146   static bool IsErrorUnrecoverable(ProcessResult p) {
147     assert(p !=  PROCESS_OK);
148     return (p != PROCESS_SYMBOL_SUPPLIER_INTERRUPTED);
149   }
150
151   // Returns a textual representation of an assertion included
152   // in the minidump.  Returns an empty string if this information
153   // does not exist or cannot be determined.
154   static string GetAssertion(Minidump* dump);
155
156  private:
157   StackFrameSymbolizer* frame_symbolizer_;
158   // Indicate whether resolver_helper_ is owned by this instance.
159   bool own_frame_symbolizer_;
160
161   // This flag enables the exploitability scanner which attempts to
162   // guess how likely it is that the crash represents an exploitable
163   // memory corruption issue.
164   bool enable_exploitability_;
165 };
166
167 }  // namespace google_breakpad
168
169 #endif  // GOOGLE_BREAKPAD_PROCESSOR_MINIDUMP_PROCESSOR_H__