bool CmdMachine::AttachSandbox(DebuggerClient &client, DSandboxInfoPtr sandbox, bool force /* = false */) { if (client.isLocal()) { client.error("Local script doesn't have sandbox to attach to."); return false; } CmdMachine cmd; cmd.m_body = "attach"; cmd.m_sandboxes.push_back(sandbox); cmd.m_force = force; client.info("Attaching to %s and pre-loading, please wait...", sandbox->desc().c_str()); CmdMachinePtr cmdMachine = client.xend<CmdMachine>(&cmd); if (cmdMachine->m_succeed) { client.playMacro("startup"); } else { // Note: it would be nice to give them more info about the process we think // is debugging this sandbox: what machine it's on, what it's pid is, etc. // Unfortunately, we don't have any of that data. We'd need a protocol // change to have the client give us more info when it attaches. client.error( "Failed to attach to the sandbox. Maybe another client is debugging, \n" "or a client failed to detach cleanly.\n" "You can attach to another sandbox, or exit the other attached client, \n" "or force this client to take over the sandbox with: \n" "\n" "\t[m]achine [a]ttach [f]orce %s %s" "\n", sandbox->m_user.c_str(), sandbox->m_name.c_str()); } return cmdMachine->m_succeed; }
bool CmdMachine::AttachSandbox(DebuggerClient &client, DSandboxInfoPtr sandbox, bool force /* = false */) { if (client.isLocal()) { client.error("Local script doesn't have sandbox to attach to."); return false; } CmdMachine cmd; cmd.m_body = "attach"; cmd.m_sandboxes.push_back(sandbox); cmd.m_force = force; client.info("Attaching to %s and pre-loading, please wait...", sandbox->desc().c_str()); CmdMachinePtr cmdMachine = client.xend<CmdMachine>(&cmd); if (cmdMachine->m_succeed) { client.playMacro("startup"); } else { client.error("failed to attach to sandbox, maybe another client is " "debugging, \nattach to another sandbox, exit the " "attached hphpd client, or try \n" "[m]achine [a]ttach [f]orce [%s] [%s]", sandbox->m_user.c_str(), sandbox->m_name.c_str()); } return cmdMachine->m_succeed; }
// Callback made by Debugger::SwitchSandbox() when the switch is successful. // NB: this is called with a read lock on the corresponding entry in the sandbox // map. void DebuggerProxy::updateSandbox(DSandboxInfoPtr sandbox) { TRACE(2, "DebuggerProxy::updateSandbox\n"); Lock lock(this); if (sandbox) { if (m_sandbox.id() != sandbox->id()) { m_sandbox = *sandbox; } else { m_sandbox.update(*sandbox); } } }
void Debugger::addSandbox(const DSandboxInfo &sandbox) { WriteLock lock(m_mutex); string id = sandbox.id(); ThreadInfo *ti = ThreadInfo::s_threadInfo.get(); m_threadInfos[(int64)pthread_self()] = ti; if (m_proxies[id]) { ti->m_reqInjectionData.debugger = true; m_sandboxThreads[id].erase(ti); } else { m_sandboxThreads[id].insert(ti); } DSandboxInfoPtr old = m_sandboxes[id]; if (old) { old->update(sandbox); } else { DSandboxInfoPtr sb(new DSandboxInfo()); *sb = sandbox; m_sandboxes[id] = sb; } }
bool CmdMachine::AttachSandbox(DebuggerClient *client, DSandboxInfoPtr sandbox) { if (client->isLocal()) { client->error("Local script doesn't have sandbox to attach to."); return true; } CmdMachine cmd; cmd.m_body = "attach"; cmd.m_sandboxes.push_back(sandbox); client->send(&cmd); client->info("Pre-loading %s, please wait...", sandbox->desc().c_str()); throw DebuggerConsoleExitException(); }