aboutsummaryrefslogtreecommitdiffstats
path: root/source/Plugins/Process/POSIX/ProcessMessage.cpp
blob: 5c53627f9e0bdc37b5f980ec4ad6ca6c994a8890 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//===-- ProcessMessage.cpp --------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "ProcessMessage.h"

#include <sstream>

using namespace lldb_private;

namespace {

inline void AppendFaultAddr(std::string& str, lldb::addr_t addr)
{
    std::stringstream ss;
    ss << " (fault address: 0x" << std::hex << addr << ")";
    str += ss.str();
}

}

const char *
ProcessMessage::GetCrashReasonString(CrashReason reason, lldb::addr_t fault_addr)
{
    static std::string str;

    switch (reason)
    {
    default:
        assert(false && "invalid CrashReason");
        break;

    case eInvalidAddress:
        str = "invalid address";
        AppendFaultAddr(str, fault_addr);
        break;
    case ePrivilegedAddress:
        str = "address access protected";
        AppendFaultAddr(str, fault_addr);
        break;
    case eIllegalOpcode:
        str = "illegal instruction";
        break;
    case eIllegalOperand:
        str = "illegal instruction operand";
        break;
    case eIllegalAddressingMode:
        str = "illegal addressing mode";
        break;
    case eIllegalTrap:
        str = "illegal trap";
        break;
    case ePrivilegedOpcode:
        str = "privileged instruction";
        break;
    case ePrivilegedRegister:
        str = "privileged register";
        break;
    case eCoprocessorError:
        str = "coprocessor error";
        break;
    case eInternalStackError:
        str = "internal stack error";
        break;
    case eIllegalAlignment:
        str = "illegal alignment";
        break;
    case eIllegalAddress:
        str = "illegal address";
        break;
    case eHardwareError:
        str = "hardware error";
        break;
    case eIntegerDivideByZero:
        str = "integer divide by zero";
        break;
    case eIntegerOverflow:
        str = "integer overflow";
        break;
    case eFloatDivideByZero:
        str = "floating point divide by zero";
        break;
    case eFloatOverflow:
        str = "floating point overflow";
        break;
    case eFloatUnderflow:
        str = "floating point underflow";
        break;
    case eFloatInexactResult:
        str = "inexact floating point result";
        break;
    case eFloatInvalidOperation:
        str = "invalid floating point operation";
        break;
    case eFloatSubscriptRange:
        str = "invalid floating point subscript range";
        break;
    }

    return str.c_str();
}

const char *
ProcessMessage::PrintCrashReason(CrashReason reason)
{
#ifdef LLDB_CONFIGURATION_BUILDANDINTEGRATION
    // Just return the code in asci for integration builds.
    chcar str[8];
    sprintf(str, "%d", reason);
#else
    const char *str = NULL;

    switch (reason)
    {
        case eInvalidCrashReason:
            str = "eInvalidCrashReason";
            break;

        // SIGSEGV crash reasons.
        case eInvalidAddress:
            str = "eInvalidAddress";
            break;
        case ePrivilegedAddress:
            str = "ePrivilegedAddress";
            break;

        // SIGILL crash reasons.
        case eIllegalOpcode:
            str = "eIllegalOpcode";
            break;
        case eIllegalOperand:
            str = "eIllegalOperand";
            break;
        case eIllegalAddressingMode:
            str = "eIllegalAddressingMode";
            break;
        case eIllegalTrap:
            str = "eIllegalTrap";
            break;
        case ePrivilegedOpcode:
            str = "ePrivilegedOpcode";
            break;
        case ePrivilegedRegister:
            str = "ePrivilegedRegister";
            break;
        case eCoprocessorError:
            str = "eCoprocessorError";
            break;
        case eInternalStackError:
            str = "eInternalStackError";
            break;

        // SIGBUS crash reasons:
        case eIllegalAlignment:
            str = "eIllegalAlignment";
            break;
        case eIllegalAddress:
            str = "eIllegalAddress";
            break;
        case eHardwareError:
            str = "eHardwareError";
            break;

        // SIGFPE crash reasons:
        case eIntegerDivideByZero:
            str = "eIntegerDivideByZero";
            break;
        case eIntegerOverflow:
            str = "eIntegerOverflow";
            break;
        case eFloatDivideByZero:
            str = "eFloatDivideByZero";
            break;
        case eFloatOverflow:
            str = "eFloatOverflow";
            break;
        case eFloatUnderflow:
            str = "eFloatUnderflow";
            break;
        case eFloatInexactResult:
            str = "eFloatInexactResult";
            break;
        case eFloatInvalidOperation:
            str = "eFloatInvalidOperation";
            break;
        case eFloatSubscriptRange:
            str = "eFloatSubscriptRange";
            break;
    }
#endif

    return str;
}

const char *
ProcessMessage::PrintCrashReason() const
{
    return PrintCrashReason(m_crash_reason);
}

const char *
ProcessMessage::PrintKind(Kind kind)
{
#ifdef LLDB_CONFIGURATION_BUILDANDINTEGRATION
    // Just return the code in asci for integration builds.
    chcar str[8];
    sprintf(str, "%d", reason);
#else
    const char *str = NULL;

    switch (kind)
    {
    case eInvalidMessage:
        str = "eInvalidMessage";
        break;
    case eAttachMessage:
        str = "eAttachMessage";
        break;
    case eExitMessage:
        str = "eExitMessage";
        break;
    case eLimboMessage:
        str = "eLimboMessage";
        break;
    case eSignalMessage:
        str = "eSignalMessage";
        break;
    case eSignalDeliveredMessage:
        str = "eSignalDeliveredMessage";
        break;
    case eTraceMessage:
        str = "eTraceMessage";
        break;
    case eBreakpointMessage:
        str = "eBreakpointMessage";
        break;
    case eWatchpointMessage:
        str = "eWatchpointMessage";
        break;
    case eCrashMessage:
        str = "eCrashMessage";
        break;
    case eNewThreadMessage:
        str = "eNewThreadMessage";
        break;
    case eExecMessage:
        str = "eExecMessage";
        break;
    }
#endif

    return str;
}

const char *
ProcessMessage::PrintKind() const
{
    return PrintKind(m_kind);
}