From 917fffb462b795d0b1368fe51cc025de7cedbf5b Mon Sep 17 00:00:00 2001 From: Herman Venter Date: Tue, 4 Jun 2013 16:06:50 -0700 Subject: [PATCH] Reduce redundant spew when breaking on an unhandled exception. Quit cleanly. Currently the debugger prints the line where an exception has been thrown, along with the type exception. Then it prints the source listing of the exception. Then it prints a serialization of the exception, which includes a full stack trace. Since the debugger has a command for printing stack traces, the latter bit information seems completely redundant when stopped in the command line client. This diff suppresses the stack trace in that case. It also suppresses redundant diagnostics that get generated during the debugger's attempt to find and print the source code in response to a list command. Finally, the quit command was too eager to let the client die after notifying the proxy, causing the proxy to get a pipe closed exception rather than the quit command, which often allowed the program to carry on running after the client has already quit. The quit command now waits for an acknowledgement from the proxy before shutting down. --- hphp/runtime/debugger/cmd/cmd_interrupt.cpp | 4 +++- hphp/runtime/debugger/cmd/cmd_list.cpp | 7 +++++-- hphp/runtime/debugger/cmd/cmd_quit.cpp | 13 ++++++++++++- hphp/runtime/debugger/cmd/cmd_quit.h | 5 +---- hphp/runtime/debugger/debugger_proxy.cpp | 1 + 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/hphp/runtime/debugger/cmd/cmd_interrupt.cpp b/hphp/runtime/debugger/cmd/cmd_interrupt.cpp index 5370d0449..226ed77ad 100644 --- a/hphp/runtime/debugger/cmd/cmd_interrupt.cpp +++ b/hphp/runtime/debugger/cmd/cmd_interrupt.cpp @@ -209,7 +209,9 @@ void CmdInterrupt::onClientImpl(DebuggerClient &client) { m_bpi->m_exceptionClass.c_str(), m_bpi->site().c_str()); client.shortCode(m_bpi); - client.output(m_bpi->m_exceptionObject); + if (client.isApiMode() || client.getLogFileHandler()) { + client.output(m_bpi->m_exceptionObject); + } } } if (!bpm->m_output.empty()) { diff --git a/hphp/runtime/debugger/cmd/cmd_list.cpp b/hphp/runtime/debugger/cmd/cmd_list.cpp index 071f59879..bd8965105 100644 --- a/hphp/runtime/debugger/cmd/cmd_list.cpp +++ b/hphp/runtime/debugger/cmd/cmd_list.cpp @@ -335,8 +335,10 @@ void CmdList::onClientImpl(DebuggerClient &client) { // The function returns false if the reply to the client fails during the // sending process. bool CmdList::onServer(DebuggerProxy &proxy) { + auto savedWarningFrequency = RuntimeOption::WarningFrequency; + RuntimeOption::WarningFrequency = 0; m_code = f_file_get_contents(m_file.c_str()); - if (!m_code && m_file[0] != '/') { + if (!proxy.isLocal() && !m_code && m_file[0] != '/') { DSandboxInfo info = proxy.getSandbox(); if (info.m_path.empty()) { raise_warning("path for sandbox %s is not setup, run a web request", @@ -346,11 +348,12 @@ bool CmdList::onServer(DebuggerProxy &proxy) { m_code = f_file_get_contents(full_path.c_str()); } } + RuntimeOption::WarningFrequency = savedWarningFrequency; return proxy.sendToClient((DebuggerCommand*)this); } // Sends a "list file" command to the proxy attached to the given client. -// Returns false if the file does not exist or could not be read or an +// Returns false if the file does not exist or could not be read as an // HPHP::String instance containing the contents of the file. Variant CmdList::GetSourceFile(DebuggerClient &client, const std::string &file) { diff --git a/hphp/runtime/debugger/cmd/cmd_quit.cpp b/hphp/runtime/debugger/cmd/cmd_quit.cpp index fff856008..aa714391f 100644 --- a/hphp/runtime/debugger/cmd/cmd_quit.cpp +++ b/hphp/runtime/debugger/cmd/cmd_quit.cpp @@ -41,12 +41,23 @@ void CmdQuit::onClientImpl(DebuggerClient &client) { if (DebuggerCommand::displayedHelp(client)) return; if (client.argCount() == 0) { - client.sendToServer(this); + client.xend(this); // Wait for server ack before closing pipe. client.quit(); } else { help(client); } } +// Sends an acknowledgment back to the client so that +// it can go ahead and terminate. It it were to do so +// before the server has received the command, the pipe +// will be closed and the proxy will carry on as if there +// were a communication failure, which is not as clean +// explicitly quitting. +bool CmdQuit::onServer(DebuggerProxy &proxy) { + TRACE(2, "CmdQuit::onServer\n"); + return proxy.sendToClient(this); +} + /////////////////////////////////////////////////////////////////////////////// }} diff --git a/hphp/runtime/debugger/cmd/cmd_quit.h b/hphp/runtime/debugger/cmd/cmd_quit.h index 39c3524f8..bae477b40 100644 --- a/hphp/runtime/debugger/cmd/cmd_quit.h +++ b/hphp/runtime/debugger/cmd/cmd_quit.h @@ -27,14 +27,11 @@ class CmdQuit : public DebuggerCommand { public: CmdQuit() : DebuggerCommand(KindOfQuit) {} - // The text to display when the debugger client processes "help quit". virtual void help(DebuggerClient &client); protected: - // Carries out the Quit command by informing the server the client - // is going away and then getting the client to quit. virtual void onClientImpl(DebuggerClient &client); - + virtual bool onServer(DebuggerProxy &proxy); }; /////////////////////////////////////////////////////////////////////////////// diff --git a/hphp/runtime/debugger/debugger_proxy.cpp b/hphp/runtime/debugger/debugger_proxy.cpp index ea8b38be5..ebc99bed6 100644 --- a/hphp/runtime/debugger/debugger_proxy.cpp +++ b/hphp/runtime/debugger/debugger_proxy.cpp @@ -625,6 +625,7 @@ void DebuggerProxy::processInterrupt(CmdInterrupt &cmd) { } if (res->is(DebuggerCommand::KindOfQuit)) { TRACE_RB(2, "Received quit command\n"); + res->onServer(*this); // acknowledge receipt so that client can quit. Debugger::RemoveProxy(shared_from_this()); forceQuit(); throw DebuggerClientExitException();