Repository navigation
Expand file tree
/
Copy pathcmd_interrupt.cpp
More file actions
312 lines (296 loc) · 9.8 KB
/
Copy pathcmd_interrupt.cpp
File metadata and controls
312 lines (296 loc) · 9.8 KB
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#include "hphp/runtime/debugger/cmd/cmd_interrupt.h"
#include "hphp/runtime/debugger/cmd/cmd_break.h"
#include "hphp/runtime/debugger/cmd/cmd_print.h"
#include "hphp/runtime/base/array-init.h"
namespace HPHP { namespace Eval {
///////////////////////////////////////////////////////////////////////////////
TRACE_SET_MOD(debugger);
void CmdInterrupt::sendImpl(DebuggerThriftBuffer &thrift) {
DebuggerCommand::sendImpl(thrift);
assert(m_interrupt != ExceptionHandler); // Server-side only.
thrift.write(m_interrupt);
thrift.write(m_program);
thrift.write(m_errorMsg);
thrift.write(m_threadId);
// Used to be m_pendingJump, but that's been removed. Write false until
// we rev the protocol.
thrift.write(false);
if (m_site) {
thrift.write(true);
thrift.write(m_site->getFile());
thrift.write(m_site->getLine0());
thrift.write(m_site->getChar0());
thrift.write(m_site->getLine1());
thrift.write(m_site->getChar1());
thrift.write(m_site->getNamespace());
thrift.write(m_site->getClass());
thrift.write(m_site->getFunction());
Variant e = m_site->getError();
if (e.isNull()) {
thrift.write("");
} else if (e.isObject()) {
thrift.write(e.toObject()->o_getClassName());
} else {
String ex(BreakPointInfo::ErrorClassName);
thrift.write(ex);
}
thrift.write(e.toString());
} else {
thrift.write(false);
}
BreakPointInfo::SendImpl(0, m_matched, thrift);
}
void CmdInterrupt::recvImpl(DebuggerThriftBuffer &thrift) {
DebuggerCommand::recvImpl(thrift);
thrift.read(m_interrupt);
thrift.read(m_program);
thrift.read(m_errorMsg);
thrift.read(m_threadId);
// Used to be m_pendingJump, but that's been removed. Read a dummy bool until
// we rev the protocol.
bool dummy;
thrift.read(dummy);
m_bpi = BreakPointInfoPtr(new BreakPointInfo());
bool site; thrift.read(site);
if (site) {
thrift.read(m_bpi->m_file);
thrift.read(m_bpi->m_line1);
thrift.read(m_bpi->m_char1);
thrift.read(m_bpi->m_line2);
thrift.read(m_bpi->m_char2);
DFunctionInfoPtr func(new DFunctionInfo());
thrift.read(func->m_namespace);
thrift.read(func->m_class);
thrift.read(func->m_function);
m_bpi->m_funcs.push_back(func);
thrift.read(m_bpi->m_exceptionClass);
thrift.read(m_bpi->m_exceptionObject);
}
BreakPointInfo::RecvImpl(0, m_matched, thrift);
}
std::string CmdInterrupt::desc() const {
switch (m_interrupt) {
case SessionStarted:
if (!m_program.empty()) {
return m_program + " loaded.";
}
return "Program loaded.";
case SessionEnded:
if (!m_program.empty()) {
return m_program + " exited normally.";
}
return "Program exited normally.";
case RequestStarted:
if (!m_program.empty()) {
return m_program + " started.";
}
return "Web request started.";
case RequestEnded:
if (!m_program.empty()) {
return m_program + " ended.";
}
return "Web request ended.";
case PSPEnded:
if (!m_program.empty()) {
return "Post-Send Processing for " + m_program + " was ended.";
}
return "Post-Send Processing was ended.";
case HardBreakPoint:
case BreakPointReached:
case ExceptionThrown: {
assert(m_site);
if (m_site) {
return m_site->desc();
}
return "Breakpoint reached.";
}
}
assert(false);
return "";
}
void CmdInterrupt::onClient(DebuggerClient &client) {
client.setCurrentLocation(m_threadId, m_bpi);
if (!client.getDebuggerClientSmallStep()) {
// Adjust line and char if it's not small stepping
if (m_bpi->m_line1 == m_bpi->m_line2) {
m_bpi->m_char1 = 1;
m_bpi->m_char2 = 100;
}
}
client.setMatchedBreakPoints(m_matched);
switch (m_interrupt) {
case SessionStarted:
if (!m_program.empty()) {
client.info("Program %s loaded. Type '[r]un' or '[c]ontinue' to go.",
m_program.c_str());
m_bpi->m_file = m_program;
}
break;
case SessionEnded:
if (!m_program.empty()) {
client.info("Program %s exited normally.", m_program.c_str());
}
break;
case RequestStarted:
if (!m_program.empty()) {
client.info("Web request %s started.", m_program.c_str());
}
break;
case RequestEnded:
if (!m_program.empty()) {
client.info("Web request %s ended.", m_program.c_str());
}
break;
case PSPEnded:
if (!m_program.empty()) {
client.info("Post-Send Processing for %s was ended.",
m_program.c_str());
}
break;
case HardBreakPoint:
case BreakPointReached:
case ExceptionThrown: {
bool found = false;
bool toggled = false;
BreakPointInfoPtrVec *bps = client.getBreakPoints();
for (unsigned int i = 0; i < m_matched.size(); i++) {
BreakPointInfoPtr bpm = m_matched[i];
BreakPointInfoPtr bp;
int index = 0;
for (; index < (int)bps->size(); index++) {
if (bpm->same((*bps)[index])) {
bp = (*bps)[index];
break;
}
}
if (bp) {
found = true;
if (bp->m_state == BreakPointInfo::Once) {
bp->m_state = BreakPointInfo::Disabled;
toggled = true;
}
if (m_interrupt == BreakPointReached ||
m_interrupt == HardBreakPoint) {
client.info("Breakpoint %d reached %s", bp->index(),
m_bpi->site().c_str());
client.shortCode(m_bpi);
} else {
if (m_bpi->m_exceptionClass == BreakPointInfo::ErrorClassName) {
client.info("Breakpoint %d reached: An error occurred %s",
bp->index(), m_bpi->site().c_str());
client.shortCode(m_bpi);
client.error("Error Message: %s",
m_bpi->m_exceptionObject.c_str());
} else {
client.info("Breakpoint %d reached: Throwing %s %s",
bp->index(),
m_bpi->m_exceptionClass.c_str(),
m_bpi->site().c_str());
client.shortCode(m_bpi);
if (client.getLogFileHandler()) {
client.output(m_bpi->m_exceptionObject);
}
}
}
if (!bpm->m_output.empty()) {
client.print(bpm->m_output);
}
}
}
if (toggled) {
CmdBreak::SendClientBreakpointListToServer(client);
}
if (!found) {
if (m_interrupt == HardBreakPoint) {
// for HardBreakPoint, default the frame to the caller
client.setFrame(1);
}
client.info("Break %s", m_bpi->site().c_str());
client.shortCode(m_bpi);
}
break;
}
}
if (!m_errorMsg.empty()) {
client.error(m_errorMsg);
}
// watches
switch (m_interrupt) {
case SessionStarted:
case RequestStarted:
break;
default: {
DebuggerClient::WatchPtrVec &watches = client.getWatches();
for (int i = 0; i < (int)watches.size(); i++) {
if (i > 0) client.output("%s", "");
client.info("Watch %d: %s =", i + 1, watches[i]->second.c_str());
Variant v = CmdPrint().processWatch(client, watches[i]->first,
watches[i]->second);
client.output(CmdPrint::FormatResult(watches[i]->first, v));
}
}
}
}
bool CmdInterrupt::onServer(DebuggerProxy &proxy) {
return proxy.sendToClient(this);
}
bool CmdInterrupt::shouldBreak(DebuggerProxy &proxy,
const BreakPointInfoPtrVec &bps,
int stackDepth) {
switch (m_interrupt) {
case SessionStarted:
case SessionEnded:
case HardBreakPoint:
return true; // always break
case RequestStarted:
case RequestEnded:
case PSPEnded:
case BreakPointReached:
case ExceptionThrown:
m_matched.clear();
if (m_site) {
auto offset = m_site->getCurOffset();
for (unsigned int i = 0; i < bps.size(); i++) {
if (bps[i]->m_state != BreakPointInfo::Disabled &&
bps[i]->breakable(stackDepth, offset) &&
bps[i]->cmatch(proxy, getInterruptType(), *m_site)) {
BreakPointInfoPtr bp(new BreakPointInfo());
*bp = *bps[i]; // make a copy
m_matched.push_back(bp);
}
}
}
return !m_matched.empty();
case ExceptionHandler:
return false; // For flow control only at this time.
}
assert(false);
return false;
}
std::string CmdInterrupt::getFileLine() const {
string ret;
if (m_site) {
if (m_site->getFile()) {
ret = m_site->getFile();
}
ret += ":" + lexical_cast<string>(m_site->getLine0());
}
return ret;
}
///////////////////////////////////////////////////////////////////////////////
}}