/* +----------------------------------------------------------------------+ | 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. | +----------------------------------------------------------------------+ */ #ifndef incl_HPHP_EVAL_DEBUGGER_BASE_H_ #define incl_HPHP_EVAL_DEBUGGER_BASE_H_ #include "hphp/runtime/debugger/break_point.h" #include "hphp/runtime/base/util/string_buffer.h" #include "hphp/runtime/base/util/exceptions.h" #include "hphp/util/hdf.h" namespace HPHP { namespace Eval { /////////////////////////////////////////////////////////////////////////////// // startup options for debugger client struct DebuggerClientOptions { std::string host; int port; std::string extension; StringVec cmds; std::string sandbox; std::string user; bool apiMode; std::string configFName; std::string fileName; DebuggerClientOptions() : port(-1), apiMode(false) {} }; /////////////////////////////////////////////////////////////////////////////// // exceptions // Client-side exceptions class DebuggerClientException : public Exception {}; // Exception used to force the debugger client to exit the command prompt loop // implemented in DebuggerClient::console(). Commands throw this when they do // something that causes the server to start running code again, so we pop out // of the command prompt loop and go back to waiting for interrupt messages from // the server. class DebuggerConsoleExitException : public DebuggerClientException {}; // Exception thrown when the client detects an error in the communication // protocol with the server, but believes the connection is still alive. // I.e., bad command type back, missing fields, etc. class DebuggerProtocolException : public DebuggerClientException {}; // Exception thrown when the client loses its connection to the server. class DebuggerServerLostException : public DebuggerClientException {}; // Both client- and server-side exceptions class DebuggerException : public Exception { EXCEPTION_COMMON_IMPL(DebuggerException); }; // Exception thrown in two cases: // // Client-side: thrown in cases where the client should completely exit. This // will pop us out of both the command prompt loop and the message loop for the // server, and cause the client to quit. // // Server-side: thrown when the server detects that the client is exiting. This // causes a thread which is currently interrupted to terminate it's request with // this exception. The message attempts to reflect that a request which was // being debugged has been terminated. class DebuggerClientExitException : public DebuggerException { virtual const char *what() const throw() { return "Debugger client has just quit, request (if any) terminated."; } EXCEPTION_COMMON_IMPL(DebuggerClientExitException); }; class DebuggerRestartException : public DebuggerException { public: explicit DebuggerRestartException(StringVecPtr args) : m_args(args) {} ~DebuggerRestartException() throw() {} virtual const char *what() const throw() { return "Debugger restarting program or aborting web request."; } EXCEPTION_COMMON_IMPL(DebuggerRestartException); StringVecPtr m_args; }; /////////////////////////////////////////////////////////////////////////////// // utility functions enum CodeColor { CodeColorNone, CodeColorKeyword, CodeColorComment, CodeColorString, CodeColorVariable, CodeColorHtml, CodeColorTag, CodeColorDeclaration, CodeColorConstant, CodeColorLineNo }; /** * "line", starting line number, or 0 for no line number display. * "lineFocus", the line to highlight, with gray background. * highlight_code() doesn't need