Understanding XDebug using Message Sequence Charts (mscgen)
These Message Sequence charts will help us to better understand the communication that happens between the IDE and XDebug during a debugging session. These charts are generated using the awesome mscgen_js library.
Single User/Static IP
- IDE/Editor starts a debug client server on PORT 9000
- User sends session initiation command to the XDebug using GET/POST/COOKIE parameters or environment variables
- XDebug connects to remote IDE using
xdebug.remote_hostandxdebug.remote_portvalues. It sends aninitpacket and waits without executing any code. - IDE negotiates features or set any breakpoints
- IDE send commands to interactively walk through the code
- When finished, XDebug sends response back to browser.
Multi User/Unknown IP
- IDE/Editor starts a debug client server on PORT 9000
- User sends session initiation command to the XDebug using GET/POST/COOKIE parameters
- XDebug connects to remote IDE using
$_SERVER['HTTP_X_FORWARDED_FOR']or$_SERVER['REMOTE_ADDR']values. It sends aninitpacket and waits without executing any code. - IDE negotiates features or set any breakpoints
- IDE send commands to interactively walk through the code
- When finished, XDebug sends response back to browser.
DBGp Proxy
- IDE/Editor starts a debug client server on PORT 9002
- IDE sends a
proxyinitcommand to the proxy server on port9001along with aidekeyand an address to connect back to IDE on port9002 - Proxy server stores the
idekeyand the IDE address where deubg clien is listening - User sends session initiation command to the XDebug using GET/POST/COOKIE parameters
- XDebug connects to proxy server using
xdebug.remote_hostandxdebug.remote_portvalues. It sends aninitpacket withidekeyand waits without executing any code. - Proxy server looks up the
idekeyand finds the IDE address. It then sends the sameinitcommand to the IDE - IDE negotiates features or set any breakpoints with the proxy server and proxy server sends the same commands to the XDebug
- IDE send commands to proxy server to interactively walk through the code. Proxy server proxies all commands and response to XDebug
- When finished, XDebug sends response back to browser.
Just-in-time Debugging (JIT)
- IDE/Editor starts a debug client server on PORT 9000
- XDebug starts code execution and stops when an error occurs
- XDebug connects to remote IDE using
xdebug.remote_hostandxdebug.remote_portvalues. It sends aninitpacket withidekey - IDE negotiates features or set any breakpoints
- IDE send commands to interactively walk through the code
- When finished, XDebug sends response back to browser.