void DummySandbox::run() { while (!m_stopped) { try { char *argv[] = {"", NULL}; execute_command_line_begin(1, argv, 0); DECLARE_THREAD_INFO; FRAME_INJECTION_FLAGS(empty_string, _, FrameInjection::PseudoMain); DSandboxInfo sandbox = m_proxy->getSandbox(); string msg; if (m_inited) { SystemGlobals *g = (SystemGlobals *)get_global_variables(); SourceRootInfo sri(sandbox.m_user, sandbox.m_name); if (sandbox.m_path.empty()) { sandbox.m_path = sri.path(); } if (!sri.sandboxOn()) { msg = "Invalid sandbox was specified. " "PHP files may not be loaded properly.\n"; // force HPHP_SANDBOX_ID to be set, so we can still talk to client g->GV(_SERVER).set("HPHP_SANDBOX_ID", sandbox.id()); } else { sri.setServerVariables(g->GV(_SERVER)); } std::string doc = getStartupDoc(sandbox); bool error; string errorMsg; bool ret = hphp_invoke(g_context.get(), doc, false, null_array, null, "", "", "", error, errorMsg); if (!ret || error) { msg += "Unable to pre-load " + doc; if (!errorMsg.empty()) { msg += ": " + errorMsg; } } } m_inited = true; Debugger::RegisterSandbox(sandbox); Debugger::InterruptSessionStarted(NULL, msg.c_str()); // Blocking until Ctrl-C is issued by end user and DebuggerProxy cannot // find a real sandbox thread to handle it. { Lock lock(this); while (!m_stopped && m_signum != CmdSignal::SignalBreak) { wait(1); } m_signum = CmdSignal::SignalNone; } } catch (const DebuggerException &e) {} execute_command_line_end(0, false, NULL); } }
void DummySandbox::run() { TRACE(2, "DummySandbox::run\n"); RequestInfo *ti = RequestInfo::s_requestInfo.getNoCheck(); while (!m_stopped) { try { CLISession hphpSession; DSandboxInfo sandbox = m_proxy->getSandbox(); std::string msg; if (sandbox.valid()) { SourceRootInfo sri(sandbox.m_user, sandbox.m_name); if (sandbox.m_path.empty()) { sandbox.m_path = sri.path(); } if (!sri.sandboxOn()) { msg = "Invalid sandbox was specified. " "PHP files may not be loaded properly.\n"; } else { auto server = php_global_exchange(s__SERVER, init_null()); forceToArray(server); Array arr = server.toArrRef(); server.unset(); php_global_set(s__SERVER, sri.setServerVariables(std::move(arr))); } Debugger::RegisterSandbox(sandbox); g_context->setSandboxId(sandbox.id()); std::string doc = getStartupDoc(sandbox); if (!doc.empty()) { char cwd[PATH_MAX]; getcwd(cwd, sizeof(cwd)); Logger::Info("Start loading startup doc '%s', pwd = '%s'", doc.c_str(), cwd); bool error; std::string errorMsg; bool ret = hphp_invoke(g_context.getNoCheck(), doc, false, null_array, uninit_null(), "", "", error, errorMsg, true, false, true, RuntimeOption::EvalPreludePath); if (!ret || error) { msg += "Unable to pre-load " + doc; if (!errorMsg.empty()) { msg += ": " + errorMsg; } } Logger::Info("Startup doc " + doc + " loaded"); } } else { g_context->setSandboxId(m_proxy->getDummyInfo().id()); } if (!DebuggerHook::attach<HphpdHook>(ti)) { const char* fail = "Could not attach hphpd to request: another debugger" " is already attached."; Logger::Error("%s", fail); Debugger::InterruptSessionStarted(nullptr, fail); throw DebuggerClientAttachFailureException(); } { DebuggerDummyEnv dde; // This is really the entire point of having the dummy sandbox. This // fires the initial session started interrupt to the client after // it first attaches. Debugger::InterruptSessionStarted(nullptr, msg.c_str()); } // Blocking until Ctrl-C is issued by end user and DebuggerProxy cannot // find a real sandbox thread to handle it. { Lock lock(this); while (!m_stopped && m_signum != CmdSignal::SignalBreak) { wait(1); } if (m_stopped) { // stopped by worker thread break; } m_signum = CmdSignal::SignalNone; } } catch (const DebuggerClientExitException& e) { // stopped by the dummy sandbox thread itself break; } catch (const DebuggerException& e) { } } }
void DummySandbox::run() { TRACE(2, "DummySandbox::run\n"); ThreadInfo *ti = ThreadInfo::s_threadInfo.getNoCheck(); Debugger::RegisterThread(); while (!m_stopped) { try { CLISession hphpSession; DSandboxInfo sandbox = m_proxy->getSandbox(); string msg; if (sandbox.valid()) { GlobalVariables *g = get_global_variables(); SourceRootInfo sri(sandbox.m_user, sandbox.m_name); if (sandbox.m_path.empty()) { sandbox.m_path = sri.path(); } if (!sri.sandboxOn()) { msg = "Invalid sandbox was specified. " "PHP files may not be loaded properly.\n"; } else { sri.setServerVariables(g->getRef(s__SERVER)); } Debugger::RegisterSandbox(sandbox); g_context->setSandboxId(sandbox.id()); std::string doc = getStartupDoc(sandbox); if (!doc.empty()) { char cwd[PATH_MAX]; getcwd(cwd, sizeof(cwd)); Logger::Info("Start loading startup doc '%s', pwd = '%s'", doc.c_str(), cwd); bool error; string errorMsg; bool ret = hphp_invoke(g_context.getNoCheck(), doc, false, null_array, uninit_null(), "", "", error, errorMsg, true, false, true); if (!ret || error) { msg += "Unable to pre-load " + doc; if (!errorMsg.empty()) { msg += ": " + errorMsg; } } Logger::Info("Startup doc " + doc + " loaded"); } } else { g_context->setSandboxId(m_proxy->getDummyInfo().id()); } ti->m_reqInjectionData.setDebugger(true); { DebuggerDummyEnv dde; // This is really the entire point of having the dummy sandbox. This // fires the initial session started interrupt to the client after // it first attaches. Debugger::InterruptSessionStarted(nullptr, msg.c_str()); } // Blocking until Ctrl-C is issued by end user and DebuggerProxy cannot // find a real sandbox thread to handle it. { Lock lock(this); while (!m_stopped && m_signum != CmdSignal::SignalBreak) { wait(1); } if (m_stopped) { // stopped by worker thread break; } m_signum = CmdSignal::SignalNone; } } catch (const DebuggerClientExitException &e) { // stopped by the dummy sandbox thread itself break; } catch (const DebuggerException &e) { } } }
double Bchart:: parse() { alreadyPopedNum = 0; SentRepIter sri(sentence_); bool haveS = false; int locTimeout = ruleiCountTimeout_; int count = 0; for (;; count ++) { //check(); if( ruleiCounts_ > locTimeout ) { break; } if(get_S() && !haveS) { // once we have found a parse, the total edes is set to edges * 3.5; haveS = true; if(printDebug(10)) cerr << "Found S " << popedEdgeCount_ << endl; popedEdgeCountAtS_ = popedEdgeCount_; totEdgeCountAtS_ = ruleiCounts_; int newTime = (int)(ruleiCounts_ * timeFactor); if(newTime < ruleiCountTimeout_) locTimeout = newTime; } // We keep track of number of ruleis to decide when time out on parsing.; /* get best thing off of keylist */ Edge* edge = heap->pop(); if (!edge) { break; } int stus = edge->status(); int cD = curDemerits_[edge->start()][edge->loc()]; if(edge->demerits() < cD - 5 && !haveS) { edge->demerits() = cD; edge->setmerit(); heap->insert(edge); continue; } if(alreadyPopedNum >= 400000) { cerr << "alreadyPoped got too large" << endl; break; } if(printDebug() > 10) { cerr << popedEdgeCount_ << "\tPop"; if(stus == 0) cerr << "< "; else if(stus == 2) cerr << ". "; else cerr << "> "; cerr << *edge << "\t" << edge->prob() << "\t" << edge->merit(); cerr << endl; } popedEdgeCount_++; alreadyPoped[alreadyPopedNum++] = edge; if(!haveS) addToDemerits(edge); /* and add it to chart */ //heap->check(); switch (stus) { case 0 : add_edge(edge, 0); break; //0 => continuing left; case 1 : add_edge(edge, 1); break; //1 => continung right; case 2 : addFinishedEdge(edge); } } /* at this point we are done looking for edges etc. */ Item *snode = get_S(); /* No "S" node means the sentence was unparsable. */ if (!snode) return badParse; double ans = snode->prob(); if (ans <= 0.0L) error("zero probability parse?"); /* ans = -log2(ans); if (ans == quiet_nan(0L)) error("log returned quiet_nan()"); */ static double nat_log_2 = log( 2.0 ); ans = -log( ans )/ nat_log_2; crossEntropy_ = ans; return ans; }
void DummySandbox::run() { ThreadInfo *ti = ThreadInfo::s_threadInfo.getNoCheck(); Debugger::RegisterThread(); ti->m_reqInjectionData.dummySandbox = true; while (!m_stopped) { try { CLISession hphpSession; FUNCTION_INJECTION_FS("_", FrameInjection::PseudoMain); DSandboxInfo sandbox = m_proxy->getSandbox(); string msg; if (sandbox.valid()) { SystemGlobals *g = (SystemGlobals *)get_global_variables(); SourceRootInfo sri(sandbox.m_user, sandbox.m_name); if (sandbox.m_path.empty()) { sandbox.m_path = sri.path(); } if (!sri.sandboxOn()) { msg = "Invalid sandbox was specified. " "PHP files may not be loaded properly.\n"; } else { sri.setServerVariables(g->GV(_SERVER)); } Debugger::RegisterSandbox(sandbox); g_context->setSandboxId(sandbox.id()); Logger::Info("Start loading startup doc"); std::string doc = getStartupDoc(sandbox); bool error; string errorMsg; bool ret = hphp_invoke(g_context.getNoCheck(), doc, false, null_array, null, "", "", error, errorMsg, true, false, true); if (!ret || error) { msg += "Unable to pre-load " + doc; if (!errorMsg.empty()) { msg += ": " + errorMsg; } } Logger::Info("Startup doc " + doc + " loaded"); } else { g_context->setSandboxId(m_proxy->getDummyInfo().id()); } ti->m_reqInjectionData.debugger = true; { DebuggerDummyEnv dde; Debugger::InterruptSessionStarted(NULL, msg.c_str()); } // Blocking until Ctrl-C is issued by end user and DebuggerProxy cannot // find a real sandbox thread to handle it. { Lock lock(this); while (!m_stopped && m_signum != CmdSignal::SignalBreak) { wait(1); } if (m_stopped) { // stopped by worker thread break; } m_signum = CmdSignal::SignalNone; } } catch (const DebuggerClientExitException &e) { // stopped by the dummy sandbox thread itself break; } catch (const DebuggerException &e) { } } }