1 //===-- ProcessMessage.cpp --------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "ProcessMessage.h"
11
12 #include <sstream>
13
14 using namespace lldb_private;
15
16 namespace {
17
AppendFaultAddr(std::string & str,lldb::addr_t addr)18 inline void AppendFaultAddr(std::string& str, lldb::addr_t addr)
19 {
20 std::stringstream ss;
21 ss << " (fault address: 0x" << std::hex << addr << ")";
22 str += ss.str();
23 }
24
25 }
26
27 const char *
GetCrashReasonString(CrashReason reason,lldb::addr_t fault_addr)28 ProcessMessage::GetCrashReasonString(CrashReason reason, lldb::addr_t fault_addr)
29 {
30 static std::string str;
31
32 switch (reason)
33 {
34 default:
35 assert(false && "invalid CrashReason");
36 break;
37
38 case eInvalidAddress:
39 str = "invalid address";
40 AppendFaultAddr(str, fault_addr);
41 break;
42 case ePrivilegedAddress:
43 str = "address access protected";
44 AppendFaultAddr(str, fault_addr);
45 break;
46 case eIllegalOpcode:
47 str = "illegal instruction";
48 break;
49 case eIllegalOperand:
50 str = "illegal instruction operand";
51 break;
52 case eIllegalAddressingMode:
53 str = "illegal addressing mode";
54 break;
55 case eIllegalTrap:
56 str = "illegal trap";
57 break;
58 case ePrivilegedOpcode:
59 str = "privileged instruction";
60 break;
61 case ePrivilegedRegister:
62 str = "privileged register";
63 break;
64 case eCoprocessorError:
65 str = "coprocessor error";
66 break;
67 case eInternalStackError:
68 str = "internal stack error";
69 break;
70 case eIllegalAlignment:
71 str = "illegal alignment";
72 break;
73 case eIllegalAddress:
74 str = "illegal address";
75 break;
76 case eHardwareError:
77 str = "hardware error";
78 break;
79 case eIntegerDivideByZero:
80 str = "integer divide by zero";
81 break;
82 case eIntegerOverflow:
83 str = "integer overflow";
84 break;
85 case eFloatDivideByZero:
86 str = "floating point divide by zero";
87 break;
88 case eFloatOverflow:
89 str = "floating point overflow";
90 break;
91 case eFloatUnderflow:
92 str = "floating point underflow";
93 break;
94 case eFloatInexactResult:
95 str = "inexact floating point result";
96 break;
97 case eFloatInvalidOperation:
98 str = "invalid floating point operation";
99 break;
100 case eFloatSubscriptRange:
101 str = "invalid floating point subscript range";
102 break;
103 }
104
105 return str.c_str();
106 }
107
108 const char *
PrintCrashReason(CrashReason reason)109 ProcessMessage::PrintCrashReason(CrashReason reason)
110 {
111 #ifdef LLDB_CONFIGURATION_BUILDANDINTEGRATION
112 // Just return the code in asci for integration builds.
113 chcar str[8];
114 sprintf(str, "%d", reason);
115 #else
116 const char *str = NULL;
117
118 switch (reason)
119 {
120 case eInvalidCrashReason:
121 str = "eInvalidCrashReason";
122 break;
123
124 // SIGSEGV crash reasons.
125 case eInvalidAddress:
126 str = "eInvalidAddress";
127 break;
128 case ePrivilegedAddress:
129 str = "ePrivilegedAddress";
130 break;
131
132 // SIGILL crash reasons.
133 case eIllegalOpcode:
134 str = "eIllegalOpcode";
135 break;
136 case eIllegalOperand:
137 str = "eIllegalOperand";
138 break;
139 case eIllegalAddressingMode:
140 str = "eIllegalAddressingMode";
141 break;
142 case eIllegalTrap:
143 str = "eIllegalTrap";
144 break;
145 case ePrivilegedOpcode:
146 str = "ePrivilegedOpcode";
147 break;
148 case ePrivilegedRegister:
149 str = "ePrivilegedRegister";
150 break;
151 case eCoprocessorError:
152 str = "eCoprocessorError";
153 break;
154 case eInternalStackError:
155 str = "eInternalStackError";
156 break;
157
158 // SIGBUS crash reasons:
159 case eIllegalAlignment:
160 str = "eIllegalAlignment";
161 break;
162 case eIllegalAddress:
163 str = "eIllegalAddress";
164 break;
165 case eHardwareError:
166 str = "eHardwareError";
167 break;
168
169 // SIGFPE crash reasons:
170 case eIntegerDivideByZero:
171 str = "eIntegerDivideByZero";
172 break;
173 case eIntegerOverflow:
174 str = "eIntegerOverflow";
175 break;
176 case eFloatDivideByZero:
177 str = "eFloatDivideByZero";
178 break;
179 case eFloatOverflow:
180 str = "eFloatOverflow";
181 break;
182 case eFloatUnderflow:
183 str = "eFloatUnderflow";
184 break;
185 case eFloatInexactResult:
186 str = "eFloatInexactResult";
187 break;
188 case eFloatInvalidOperation:
189 str = "eFloatInvalidOperation";
190 break;
191 case eFloatSubscriptRange:
192 str = "eFloatSubscriptRange";
193 break;
194 }
195 #endif
196
197 return str;
198 }
199
200 const char *
PrintCrashReason() const201 ProcessMessage::PrintCrashReason() const
202 {
203 return PrintCrashReason(m_crash_reason);
204 }
205
206 const char *
PrintKind(Kind kind)207 ProcessMessage::PrintKind(Kind kind)
208 {
209 #ifdef LLDB_CONFIGURATION_BUILDANDINTEGRATION
210 // Just return the code in asci for integration builds.
211 chcar str[8];
212 sprintf(str, "%d", reason);
213 #else
214 const char *str = NULL;
215
216 switch (kind)
217 {
218 case eInvalidMessage:
219 str = "eInvalidMessage";
220 break;
221 case eExitMessage:
222 str = "eExitMessage";
223 break;
224 case eLimboMessage:
225 str = "eLimboMessage";
226 break;
227 case eSignalMessage:
228 str = "eSignalMessage";
229 break;
230 case eSignalDeliveredMessage:
231 str = "eSignalDeliveredMessage";
232 break;
233 case eTraceMessage:
234 str = "eTraceMessage";
235 break;
236 case eBreakpointMessage:
237 str = "eBreakpointMessage";
238 break;
239 case eWatchpointMessage:
240 str = "eWatchpointMessage";
241 break;
242 case eCrashMessage:
243 str = "eCrashMessage";
244 break;
245 case eNewThreadMessage:
246 str = "eNewThreadMessage";
247 break;
248 }
249 #endif
250
251 return str;
252 }
253
254 const char *
PrintKind() const255 ProcessMessage::PrintKind() const
256 {
257 return PrintKind(m_kind);
258 }
259