2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_EVAL_DEBUGGER_PROXY_H_
18 #define incl_HPHP_EVAL_DEBUGGER_PROXY_H_
25 #include "hphp/runtime/base/socket.h"
26 #include "hphp/runtime/debugger/break_point.h"
27 #include "hphp/runtime/debugger/debugger_base.h"
28 #include "hphp/runtime/debugger/debugger_thrift_buffer.h"
29 #include "hphp/util/async-func.h"
30 #include "hphp/util/synchronizable.h"
32 namespace HPHP
{ namespace Eval
{
33 ///////////////////////////////////////////////////////////////////////////////
35 struct CmdFlowControl
;
38 struct DebuggerCommand
;
41 using DebuggerProxyPtr
= std::shared_ptr
<DebuggerProxy
>;
42 using DebuggerCommandPtr
= std::shared_ptr
<DebuggerCommand
>;
45 * A DebuggerProxy provides a conection thru which a client may talk to a VM
46 * which is being debugged. The VM can also send messages to the client via the
47 * proxy, either in reponse to messages from the client, or to poll the client
50 * In an basic scenario where a client is debugging a remote VM, the VM will
51 * create a proxy when the client connects (via DebuggerServer) and listen for
52 * commands via this proxy. It will use this proxy when completing control flow
53 * commands to interrupt the client. The client sends and receives messages
54 * over a socket directly to this proxy. Thus we have:
56 * Client <---> Proxy <---> VM
58 * The client always creates its own "local proxy", which allows debugging any
59 * code running on the VM within the client. The two are easily confused.
61 struct DebuggerProxy
: Synchronizable
,
62 std::enable_shared_from_this
<DebuggerProxy
> {
69 static std::string
MakePHP(const std::string
&php
);
70 static std::string
MakePHPReturn(const std::string
&php
);
72 DebuggerProxy(req::ptr
<Socket
> socket
, bool local
);
74 bool isLocal() const { return m_local
; }
76 const char *getThreadType() const;
77 DSandboxInfo
getSandbox();
78 std::string
getSandboxId();
79 const DSandboxInfo
& getDummyInfo() const { return m_dummyInfo
; }
81 void getThreads(std::vector
<DThreadInfoPtr
> &threads
);
82 bool switchSandbox(const std::string
&newId
, bool force
);
83 void updateSandbox(DSandboxInfoPtr sandbox
);
84 bool switchThread(DThreadInfoPtr thread
);
85 void switchThreadMode(ThreadMode mode
, int64_t threadId
= 0);
87 void startDummySandbox();
88 void notifyDummySandbox();
90 void setBreakPoints(std::vector
<BreakPointInfoPtr
> &breakpoints
);
91 void getBreakPoints(std::vector
<BreakPointInfoPtr
> &breakpoints
);
93 void setBreakableForBreakpointsNotMatching(CmdInterrupt
& cmd
);
94 void unsetBreakableForBreakpointsMatching(CmdInterrupt
& cmd
);
97 bool needVMInterrupts();
98 void interrupt(CmdInterrupt
&cmd
);
99 bool sendToClient(DebuggerCommand
*cmd
);
100 CmdInterrupt
& currentInterruptCmd();
103 int getRealStackDepth();
105 void startSignalThread();
107 bool cleanup(int timeout
);
109 bool getClientConnectionInfo(VRefParam address
, VRefParam port
);
111 enum ExecutePHPFlags
{
112 ExecutePHPFlagsNone
= 0x0, // No logging, not at an interrupt
113 ExecutePHPFlagsLog
= 0x1, // Add logs to the output string
114 ExecutePHPFlagsAtInterrupt
= 0x02 // Called when stopped at an interrupt
117 std::pair
<bool,Variant
>
118 ExecutePHP(const std::string
&php
, String
&output
, int frame
, int flags
);
120 std::string
requestAuthToken();
121 std::string
requestSessionAuth();
124 bool blockUntilOwn(CmdInterrupt
&cmd
, bool check
);
125 bool checkBreakPoints(CmdInterrupt
&cmd
);
126 bool checkFlowBreak(CmdInterrupt
&cmd
);
127 void processInterrupt(CmdInterrupt
&cmd
);
128 void enableSignalPolling();
129 void disableSignalPolling();
131 void pollSignal(); // for signal polling thread
134 DThreadInfoPtr
createThreadInfo(const std::string
&desc
);
136 /////////////////////////////////////////////////////////////////////////////
137 bool m_stopped
{false};
140 bool m_hasBreakPoints
{false};
142 // Whether the polling thread can send polls to the client.
143 bool m_okayToPoll
{true};
145 DebuggerThriftBuffer m_thrift
;
146 DummySandbox
* m_dummySandbox
{nullptr};
148 ReadWriteMutex m_breakMutex
;
149 std::vector
<BreakPointInfoPtr
> m_breakpoints
;
150 DSandboxInfo m_sandbox
;
151 DSandboxInfo m_dummyInfo
;
153 ThreadMode m_threadMode
{Normal
};
154 int64_t m_thread
{0}; // Thread allowed to process interrupts
155 DThreadInfoPtr m_newThread
; // Used by CmdThread to switch threads
156 std::map
<int64_t, DThreadInfoPtr
> m_threads
; // Threads in blockUntilOwn
158 // c, s, n, o commands that can skip breakpoints
159 std::shared_ptr
<CmdFlowControl
> m_flow
;
161 AsyncFunc
<DebuggerProxy
> m_signalThread
; // polling signals from client
163 // This mutex gates who can talk to the client (signal polling
164 // thread vs. other threads who want to send an interrupt). Protects
165 // m_signum, m_okayToPoll.
169 // Last output hook for nested PHP evaluations.
170 ExecutionContext::StdoutHook
* m_evalOutputHook
{};
173 ///////////////////////////////////////////////////////////////////////////////
176 #endif // incl_HPHP_EVAL_DEBUGGER_PROXY_H_