Repository navigation
Expand file tree
/
Copy pathdebugger.cpp
More file actions
675 lines (597 loc) · 23.8 KB
/
Copy pathdebugger.cpp
File metadata and controls
675 lines (597 loc) · 23.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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
/*
+----------------------------------------------------------------------+
| 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/debugger.h"
#include "hphp/runtime/debugger/debugger_server.h"
#include "hphp/runtime/debugger/debugger_client.h"
#include "hphp/runtime/debugger/cmd/cmd_interrupt.h"
#include "hphp/runtime/base/hphp-system.h"
#include "hphp/runtime/vm/jit/translator-x64.h"
#include "hphp/runtime/vm/jit/translator-inline.h"
#include "hphp/util/text-color.h"
#include "hphp/util/util.h"
#include "hphp/util/logger.h"
namespace HPHP { namespace Eval {
///////////////////////////////////////////////////////////////////////////////
TRACE_SET_MOD(debugger);
Debugger Debugger::s_debugger;
bool Debugger::s_clientStarted = false;
bool Debugger::StartServer() {
TRACE(2, "Debugger::StartServer\n");
return DebuggerServer::Start();
}
DebuggerProxyPtr Debugger::StartClient(const DebuggerClientOptions &options) {
TRACE(2, "Debugger::StartClient\n");
SmartPtr<Socket> localProxy = DebuggerClient::Start(options);
if (localProxy.get()) {
s_clientStarted = true;
return CreateProxy(localProxy, true);
}
return DebuggerProxyPtr();
}
void Debugger::Stop() {
TRACE(2, "Debugger::Stop\n");
LogShutdown(ShutdownKind::Normal);
s_debugger.m_proxyMap.clear();
DebuggerServer::Stop();
CleanupRetiredProxies();
if (s_clientStarted) {
DebuggerClient::Stop();
}
}
///////////////////////////////////////////////////////////////////////////////
void Debugger::RegisterSandbox(const DSandboxInfo &sandbox) {
TRACE(2, "Debugger::RegisterSandbox\n");
s_debugger.registerSandbox(sandbox);
}
void Debugger::UnregisterSandbox(const String& id) {
TRACE(2, "Debugger::UnregisterSandbox\n");
s_debugger.unregisterSandbox(id.get());
}
DebuggerProxyPtr Debugger::CreateProxy(SmartPtr<Socket> socket, bool local) {
TRACE(2, "Debugger::CreateProxy\n");
return s_debugger.createProxy(socket, local);
}
void Debugger::RemoveProxy(DebuggerProxyPtr proxy) {
TRACE(2, "Debugger::RemoveProxy\n");
s_debugger.removeProxy(proxy);
}
int Debugger::CountConnectedProxy() {
TRACE(7, "Debugger::CountConnectedProxy\n");
return s_debugger.countConnectedProxy();
}
DebuggerProxyPtr Debugger::GetProxy() {
TRACE(7, "Debugger::GetProxy\n");
const String& sandboxId = g_context->getSandboxId();
return s_debugger.findProxy(sandboxId.get());
}
bool Debugger::SwitchSandbox(DebuggerProxyPtr proxy,
const std::string &newId,
bool force) {
TRACE(2, "Debugger::SwitchSandbox\n");
return s_debugger.switchSandbox(proxy, newId, force);
}
void Debugger::GetRegisteredSandboxes(DSandboxInfoPtrVec &sandboxes) {
TRACE(2, "Debugger::GetRegisteredSandboxes\n");
s_debugger.getSandboxes(sandboxes);
}
bool Debugger::IsThreadDebugging(int64_t id) {
TRACE(2, "Debugger::IsThreadDebugging\n");
return s_debugger.isThreadDebugging(id);
}
void Debugger::RequestInterrupt(DebuggerProxyPtr proxy) {
TRACE(2, "Debugger::RequestInterrupt\n");
s_debugger.requestInterrupt(proxy);
}
void Debugger::RetireProxy(DebuggerProxyPtr proxy) {
s_debugger.retireProxy(proxy);
}
void Debugger::CleanupRetiredProxies() {
s_debugger.cleanupRetiredProxies();
}
void Debugger::DebuggerSession(const DebuggerClientOptions& options,
bool restart) {
TRACE(2, "Debugger::DebuggerSession: restart=%d\n", restart);
if (options.extension.empty()) {
// even if it's empty, still need to call for warmup
hphp_invoke_simple("", true); // not to run the 1st file if compiled
} else {
hphp_invoke_simple(options.extension);
}
ThreadInfo *ti = ThreadInfo::s_threadInfo.getNoCheck();
ti->m_reqInjectionData.setDebugger(true);
if (!restart) {
DebuggerDummyEnv dde;
Debugger::InterruptSessionStarted(options.fileName.c_str());
}
if (!options.fileName.empty()) {
hphp_invoke_simple(options.fileName);
}
{
DebuggerDummyEnv dde;
Debugger::InterruptSessionEnded(options.fileName.c_str());
}
}
void Debugger::LogShutdown(ShutdownKind shutdownKind) {
int proxyCount = s_debugger.countConnectedProxy();
if (proxyCount > 0) {
Logger::Warning(DEBUGGER_LOG_TAG "%s with connected debuggers!",
shutdownKind == ShutdownKind::Normal ?
"Normal shutdown" : "Unexpected crash");
for (const auto& proxyEntry: s_debugger.m_proxyMap) {
auto sid = proxyEntry.first;
auto proxy = proxyEntry.second;
auto dummySid = makeStaticString(proxy->getDummyInfo().id());
if (sid != dummySid) {
auto sandbox = proxy->getSandbox();
if (sandbox.valid()) {
Logger::Warning(DEBUGGER_LOG_TAG "Debugging %s\n",
sandbox.desc().c_str());
}
}
}
}
}
///////////////////////////////////////////////////////////////////////////////
void Debugger::InterruptSessionStarted(const char *file,
const char *error /* = NULL */) {
TRACE(2, "Debugger::InterruptSessionStarted\n");
ThreadInfo::s_threadInfo->m_reqInjectionData.setDebugger(true);
s_debugger.registerThread(); // Register this thread as being debugged
Interrupt(SessionStarted, file, nullptr, error);
}
void Debugger::InterruptSessionEnded(const char *file) {
TRACE(2, "Debugger::InterruptSessionEnded\n");
Interrupt(SessionEnded, file);
}
void Debugger::InterruptWithUrl(int type, const char *url) {
// Build a site to represent the URL. Note it won't have any source info
// in it, because this event is raised with no PHP on the stack.
InterruptSite site(false, null_variant);
site.url() = url ? url : "";
Interrupt(type, url, &site);
}
void Debugger::InterruptRequestStarted(const char *url) {
TRACE(2, "Debugger::InterruptRequestStarted\n");
if (ThreadInfo::s_threadInfo->m_reqInjectionData.getDebugger()) {
s_debugger.registerThread(); // Register this thread as being debugged
InterruptWithUrl(RequestStarted, url);
}
}
void Debugger::InterruptRequestEnded(const char *url) {
TRACE(2, "Debugger::InterruptRequestEnded: url=%s\n", url);
if (ThreadInfo::s_threadInfo->m_reqInjectionData.getDebugger()) {
InterruptWithUrl(RequestEnded, url);
}
const String& sandboxId = g_context->getSandboxId();
s_debugger.unregisterSandbox(sandboxId.get());
}
void Debugger::InterruptPSPEnded(const char *url) {
TRACE(2, "Debugger::InterruptPSPEnded\n");
if (ThreadInfo::s_threadInfo->m_reqInjectionData.getDebugger()) {
InterruptWithUrl(PSPEnded, url);
}
}
// Primary entrypoint for the debugger from the VM. Called in response to a host
// of VM events that the debugger is interested in. The debugger will execute
// any logic needed to handle the event, and will block below this to wait for
// and process more commands from the debugger client. This function will only
// return when the debugger is letting the thread continue execution, e.g., for
// flow control command like continue, next, etc.
void Debugger::Interrupt(int type, const char *program,
InterruptSite *site /* = NULL */,
const char *error /* = NULL */) {
assert(RuntimeOption::EnableDebugger);
TRACE_RB(2, "Debugger::Interrupt type %d\n", type);
DebuggerProxyPtr proxy = GetProxy();
if (proxy) {
TRACE(3, "proxy != null\n");
RequestInjectionData &rjdata = ThreadInfo::s_threadInfo->m_reqInjectionData;
// The proxy will only service an interrupt if we've previously setup some
// form of flow control command (steps, breakpoints, etc.) or if it's
// an interrupt related to something like the session or request.
if (proxy->needInterrupt() || type != BreakPointReached) {
// Interrupts may execute some PHP code, causing another interruption.
std::stack<void *> &interrupts = rjdata.interrupts;
CmdInterrupt cmd((InterruptType)type, program, site, error);
interrupts.push(&cmd);
proxy->interrupt(cmd);
interrupts.pop();
}
// Some cmds require us to interpret all instructions until the cmd
// completes. Setting this will ensure we stay out of JIT code and in the
// interpreter so phpDebuggerOpcodeHook has a chance to work.
rjdata.setDebuggerIntr(proxy->needVMInterrupts());
} else {
TRACE(3, "proxy == null\n");
// Debugger clients are disconnected abnormally, or this sandbox is not
// being debugged.
if (type == SessionStarted || type == SessionEnded) {
// For command line programs, we need this exception to exit from
// the infinite execution loop.
throw DebuggerClientExitException();
}
}
}
// Primary entrypoint from the set of "debugger hooks", which the VM calls in
// response to various events. While this function is quite general wrt. the
// type of interrupt, practically the type will be one of the following:
// - ExceptionThrown
// - ExceptionHandler
// - BreakPointReached
// - HardBreakPoint
//
// Note: it is indeed a bit odd that interrupts due to single stepping come in
// as "BreakPointReached". Currently this results in spurious work in the
// debugger.
void Debugger::InterruptVMHook(int type /* = BreakPointReached */,
CVarRef e /* = null_variant */) {
TRACE(2, "Debugger::InterruptVMHook\n");
// Computing the interrupt site here pulls in more data from the Unit to
// describe the current execution point.
InterruptSite site(type == HardBreakPoint, e);
if (!site.valid()) {
// An invalid site is missing something like an ActRec, a func, or a
// Unit. Currently the debugger has no action to take at such sites.
return;
}
Interrupt(type, nullptr, &site);
}
///////////////////////////////////////////////////////////////////////////////
void Debugger::SetTextColors() {
TRACE(2, "Debugger::SetTextColors\n");
s_stdout_color = ANSI_COLOR_CYAN;
s_stderr_color = ANSI_COLOR_RED;
}
String Debugger::ColorStdout(const String& s) {
TRACE(2, "Debugger::ColorStdout\n");
if (s_stdout_color) {
return String(s_stdout_color) + s + String(ANSI_COLOR_END);
}
return s;
}
String Debugger::ColorStderr(const String& s) {
TRACE(2, "Debugger::ColorStderr\n");
if (s_stderr_color) {
return String(s_stderr_color) + s + String(ANSI_COLOR_END);
}
return s;
}
///////////////////////////////////////////////////////////////////////////////
// The flag for this is in the VM's normal ThreadInfo, but we don't
// have a way to get that given just a tid. Use our own map to find it
// and answer the question.
bool Debugger::isThreadDebugging(int64_t tid) {
TRACE(2, "Debugger::isThreadDebugging tid=%" PRIx64 "\n", tid);
ThreadInfoMap::const_accessor acc;
if (m_threadInfos.find(acc, tid)) {
ThreadInfo* ti = acc->second;
auto isDebugging = ti->m_reqInjectionData.getDebugger();
TRACE(2, "Is thread debugging? %d\n", isDebugging);
return isDebugging;
}
TRACE(2, "Thread was never registered, assuming it is not debugging\n");
return false;
}
// Remeber this thread's VM ThreadInfo so we can find it later via
// isThreadDebugging(). This is called when a thread interrupts for
// either session- or request-started, as these each signal the start
// of debugging for request and other threads.
void Debugger::registerThread() {
TRACE(2, "Debugger::registerThread\n");
ThreadInfo* ti = ThreadInfo::s_threadInfo.getNoCheck();
int64_t tid = (int64_t)Process::GetThreadId();
ThreadInfoMap::accessor acc;
m_threadInfos.insert(acc, tid);
acc->second = ti;
}
void Debugger::addOrUpdateSandbox(const DSandboxInfo &sandbox) {
TRACE(2, "Debugger::addOrUpdateSandbox\n");
const StringData* sd = makeStaticString(sandbox.id());
SandboxMap::accessor acc;
if (m_sandboxMap.insert(acc, sd)) {
DSandboxInfoPtr sb(new DSandboxInfo());
*sb = sandbox;
acc->second = sb;
} else {
acc->second->update(sandbox);
}
}
void Debugger::getSandboxes(DSandboxInfoPtrVec &sandboxes) {
TRACE(2, "Debugger::getSandboxes\n");
sandboxes.reserve(m_sandboxMap.size());
for (SandboxMap::const_iterator iter =
m_sandboxMap.begin(); iter != m_sandboxMap.end(); ++iter) {
if (!iter->second->m_user.empty()) {
DSandboxInfoPtr sandbox(new DSandboxInfo());
*sandbox = *iter->second;
sandboxes.push_back(sandbox);
}
}
}
// Notify the debugger that this thread is executing a request in the given
// sandbox. This ensures that the debugger knows about the sandbox, and adds
// the thread to the set of threads currently active in the sandbox.
void Debugger::registerSandbox(const DSandboxInfo &sandbox) {
TRACE(2, "Debugger::registerSandbox\n");
// update sandbox first
addOrUpdateSandbox(sandbox);
// add thread to m_sandboxThreadInfoMap
const StringData* sid = makeStaticString(sandbox.id());
ThreadInfo* ti = ThreadInfo::s_threadInfo.getNoCheck();
{
SandboxThreadInfoMap::accessor acc;
m_sandboxThreadInfoMap.insert(acc, sid);
ThreadInfoSet& set = acc->second;
set.insert(ti);
}
// find out whether this sandbox is being debugged
DebuggerProxyPtr proxy = findProxy(sid);
if (proxy) {
ti->m_reqInjectionData.setDebugger(true);
}
}
void Debugger::unregisterSandbox(const StringData* sandboxId) {
TRACE(2, "Debugger::unregisterSandbox\n");
ThreadInfo *ti = ThreadInfo::s_threadInfo.getNoCheck();
SandboxThreadInfoMap::accessor acc;
if (m_sandboxThreadInfoMap.find(acc, sandboxId)) {
ThreadInfoSet& set = acc->second;
set.erase(ti);
}
}
#define FOREACH_SANDBOX_THREAD_BEGIN(sid, ti) { \
SandboxThreadInfoMap::const_accessor acc; \
if (m_sandboxThreadInfoMap.find(acc, sid)) { \
const ThreadInfoSet& set = acc->second; \
for (std::set<ThreadInfo*>::iterator iter = set.begin(); \
iter != set.end(); ++iter) { \
ThreadInfo* ti = (*iter); \
assert(ThreadInfo::valid(ti)); \
#define FOREACH_SANDBOX_THREAD_END() } } } \
// Ask every thread in this proxy's sandbox and the dummy sandbox to
// "stop". Gaining control of these threads is the intention... the
// mechanism is to force them all to start interpreting all of their
// code in an effort to gain control in phpDebuggerOpcodeHook(). We
// set the "debugger interrupt" flag to ensure we interpret code
// rather than entering translated code, and we set the "debugger
// signal" surprise flag to pop out of loops in translated code.
void Debugger::requestInterrupt(DebuggerProxyPtr proxy) {
TRACE(2, "Debugger::requestInterrupt\n");
const StringData* sid = makeStaticString(proxy->getSandboxId());
FOREACH_SANDBOX_THREAD_BEGIN(sid, ti)
ti->m_reqInjectionData.setDebuggerIntr(true);
ti->m_reqInjectionData.setDebuggerSignalFlag();
FOREACH_SANDBOX_THREAD_END()
sid = makeStaticString(proxy->getDummyInfo().id());
FOREACH_SANDBOX_THREAD_BEGIN(sid, ti)
ti->m_reqInjectionData.setDebuggerIntr(true);
ti->m_reqInjectionData.setDebuggerSignalFlag();
FOREACH_SANDBOX_THREAD_END()
}
void Debugger::setDebuggerFlag(const StringData* sandboxId, bool flag) {
TRACE(2, "Debugger::setDebuggerFlag\n");
FOREACH_SANDBOX_THREAD_BEGIN(sandboxId, ti)
ti->m_reqInjectionData.setDebugger(flag);
FOREACH_SANDBOX_THREAD_END()
}
#undef FOREACH_SANDBOX_THREAD_BEGIN
#undef FOREACH_SANDBOX_THREAD_END
DebuggerProxyPtr Debugger::createProxy(SmartPtr<Socket> socket, bool local) {
TRACE(2, "Debugger::createProxy\n");
// Creates a proxy and threads needed to handle it. At this point, there is
// not enough information to attach a sandbox.
DebuggerProxyPtr proxy(new DebuggerProxy(socket, local));
{
// Place this new proxy into the proxy map keyed on the dummy sandbox id.
// This keeps the proxy alive in the server case, which drops the result of
// this function on the floor. It also makes the proxy findable when we a
// dummy sandbox thread needs to interrupt.
const StringData* sid =
makeStaticString(proxy->getDummyInfo().id());
assert(sid);
ProxyMap::accessor acc;
m_proxyMap.insert(acc, sid);
acc->second = proxy;
}
if (!local) {
proxy->startDummySandbox();
}
proxy->startSignalThread();
return proxy;
}
// Place the proxy onto the retired proxy queue. It will be cleaned up
// and destroyed later by another thread.
void Debugger::retireProxy(DebuggerProxyPtr proxy) {
TRACE(2, "Debugger::retireProxy %p\n", proxy.get());
m_retiredProxyQueue.push(proxy);
}
// Cleanup any proxies in our retired proxy queue. We'll pull a proxy
// out of the queue, ask it to cleanup which will wait for threads it
// owns to exit, then drop our shared reference to it. That may
// destroy the proxy here, or it may remain alive if there is a thread
// still processing an interrupt with it since such threads have their
// own shared reference.
void Debugger::cleanupRetiredProxies() {
TRACE(7, "Debugger::cleanupRetiredProxies\n");
DebuggerProxyPtr proxy;
while (m_retiredProxyQueue.try_pop(proxy)) {
try {
// We give the proxy a short period of time to wait for any
// threads it owns. If it doesn't succeed, we put it back and
// try again later.
TRACE(2, "Cleanup proxy %p\n", proxy.get());
if (!proxy->cleanup(1)) {
TRACE(2, "Proxy %p has not stopped yet\n", proxy.get());
m_retiredProxyQueue.push(proxy);
}
} catch (Exception &e) {
Logger::Error("Exception during proxy %p retirement: %s",
proxy.get(), e.getMessage().c_str());
}
}
}
// NB: when this returns, the Debugger class no longer has any references to the
// given proxy. It will likely be destroyed when the caller's reference goes out
// of scope.
void Debugger::removeProxy(DebuggerProxyPtr proxy) {
TRACE(2, "Debugger::removeProxy\n");
if (proxy->getSandbox().valid()) {
const StringData* sid = makeStaticString(proxy->getSandboxId());
setDebuggerFlag(sid, false);
m_proxyMap.erase(sid);
}
const StringData* dummySid =
makeStaticString(proxy->getDummyInfo().id());
m_proxyMap.erase(dummySid);
// Clear the debugger blacklist PC upon last detach if JIT is used
if (RuntimeOption::EvalJit && countConnectedProxy() == 0) {
JIT::tx64->clearDbgBL();
}
}
DebuggerProxyPtr Debugger::findProxy(const StringData* sandboxId) {
TRACE(7, "Debugger::findProxy\n");
if (sandboxId) {
ProxyMap::const_accessor acc;
if (m_proxyMap.find(acc, sandboxId)) {
return acc->second;
}
}
return DebuggerProxyPtr();
}
bool Debugger::switchSandbox(DebuggerProxyPtr proxy,
const std::string &newId,
bool force) {
TRACE(2, "Debugger::switchSandbox\n");
const StringData* newSid = makeStaticString(newId);
// Lock the proxy during the switch
Lock l(proxy.get());
if (proxy->getSandboxId() != newId) {
if (!switchSandboxImpl(proxy, newSid, force)) {
// failed to switch
return false;
}
}
updateProxySandbox(proxy, newSid);
return true;
}
bool Debugger::switchSandboxImpl(DebuggerProxyPtr proxy,
const StringData* newSid,
bool force) {
TRACE(2, "Debugger::switchSandboxImpl\n");
// Take the new sandbox
DebuggerProxyPtr otherProxy;
{
ProxyMap::accessor acc;
if (m_proxyMap.insert(acc, newSid)) {
acc->second = proxy;
} else {
// the sandbox indicated by newId is already attached by another proxy
if (!force) {
return false;
}
// Delay the destruction of the proxy originally attached to the sandbox
// to avoid calling a DebuggerProxy destructor (which can sleep) while
// holding m_mutex.
otherProxy = acc->second;
acc->second = proxy;
}
}
if (proxy->getSandbox().valid()) {
// Detach from the old sandbox
const StringData* oldSid =
makeStaticString(proxy->getSandboxId());
setDebuggerFlag(oldSid, false);
m_proxyMap.erase(oldSid);
}
setDebuggerFlag(newSid, true);
if (otherProxy) {
otherProxy->stop();
}
return true;
}
void Debugger::updateProxySandbox(DebuggerProxyPtr proxy,
const StringData* sandboxId) {
TRACE(2, "Debugger::updateProxySandbox\n");
// update proxy's sandbox info from what is on file
SandboxMap::const_accessor acc;
if (m_sandboxMap.find(acc, sandboxId)) {
proxy->updateSandbox(acc->second);
} else {
// don't have the sandbox on file yet. create a sandbox info with
// no path for now. Sandbox path will be updated upon first request
// with that sandbox arrives
DSandboxInfoPtr sb(new DSandboxInfo(sandboxId->toCPPString()));
proxy->updateSandbox(sb);
}
}
///////////////////////////////////////////////////////////////////////////////
// Helpers for usage logging
// NB: the usage logger is not owned by the Debugger. The caller will call this
// again with nullptr before destroying the given usage logger.
void Debugger::SetUsageLogger(DebuggerUsageLogger *usageLogger) {
TRACE(1, "Debugger::SetUsageLogger\n");
s_debugger.m_usageLogger = usageLogger;
}
void Debugger::InitUsageLogging() {
TRACE(1, "Debugger::InitUsageLogging\n");
if (s_debugger.m_usageLogger) s_debugger.m_usageLogger->init();
}
void Debugger::UsageLog(const std::string &mode, const std::string &sandboxId,
const std::string &cmd, const std::string &data) {
if (s_debugger.m_usageLogger) s_debugger.m_usageLogger->log(mode, sandboxId,
cmd, data);
}
const char *Debugger::InterruptTypeName(CmdInterrupt &cmd) {
switch (cmd.getInterruptType()) {
case SessionStarted: return "SessionStarted";
case SessionEnded: return "SessionEnded";
case RequestStarted: return "RequestStarted";
case RequestEnded: return "RequestEnded";
case PSPEnded: return "PSPEnded";
case HardBreakPoint: return "HardBreakPoint";
case BreakPointReached: return "BreakPointReached";
case ExceptionThrown: return "ExceptionThrown";
case ExceptionHandler: return "ExceptionHandler";
default:
return "unknown";
}
}
void Debugger::UsageLogInterrupt(const std::string &mode,
const std::string &sandboxId,
CmdInterrupt &cmd) {
UsageLog(mode, sandboxId, "interrupt", InterruptTypeName(cmd));
}
///////////////////////////////////////////////////////////////////////////////
DebuggerDummyEnv::DebuggerDummyEnv() {
TRACE(2, "DebuggerDummyEnv::DebuggerDummyEnv\n");
g_vmContext->enterDebuggerDummyEnv();
}
DebuggerDummyEnv::~DebuggerDummyEnv() {
TRACE(2, "DebuggerDummyEnv::~DebuggerDummyEnv\n");
g_vmContext->exitDebuggerDummyEnv();
}
///////////////////////////////////////////////////////////////////////////////
EvalBreakControl::EvalBreakControl(bool noBreak) {
TRACE(2, "EvalBreakControl::EvalBreakControl\n");
m_noBreakSave = g_vmContext->m_dbgNoBreak;
g_vmContext->m_dbgNoBreak = noBreak;
}
EvalBreakControl::~EvalBreakControl() {
TRACE(2, "EvalBreakControl::~EvalBreakControl\n");
g_vmContext->m_dbgNoBreak = m_noBreakSave;
}
///////////////////////////////////////////////////////////////////////////////
}}