Komodo IDE debugger proxy "pydbgpproxy"

Posted by toddw on 2007-11-05 16:45
OS: All / Any | Product: Komodo | tags: debugging proxy
Question: 
  • Why would I want to use the proxy service for debugging?
  • So how does debugger proxing work?
  • How do I setup the Komodo DBGP proxy service for remote debugging?
  • How do I start debugging with my selected Komodo application?
  • What alternatives do I have when the two machines cannot see (connect to) each other?
Answer: 
  • Why would I want to use the proxy service for debugging?
    Note that it is *not* a requirement to use the DBGP proxy for remote debugging applications with Komodo. The proxy is useful when:
    • you have multiple users running the same server/application who wish to be able to debug independantly
    • the network requirements do not allow a direct TCP/IP connection between the application being debugged and the Komodo IDE, so you need to channel through a common proxy.
  • So how does debugger proxing work?
    • The proxy is started first, and listens on two separate ports.
    • Komodo connects to the proxy on one port to tell it the specific proxy key Komodo is using, as well as the IP address and port number Komodo is listening on.
    • The application being debugged connects to the proxy on the other proxy port when it starts a debugging session, sending the required ide key.
    • The proxy service checks the idekey (proxy key) given by the application being debugged and tries to match it to the connected Komodo session(s). If one matches, then the proxy tries to initiate a connection to this Komodo application and if successful the debug session is passed on to Komodo. When no match is found, the debug session is ignored.
  • How do I setup the Komodo DBGP proxy service for remote debugging?
    • You'll need Python installed.
    • pydbgpproxy.exe
    • Start the proxy by navigating to the containing folder of pydbgpproxy.exe, note that the DBGP proxy service can be running anywhere (a linux machine, windows, mac...), as long as both the application/server to
      be debugged and Komodo IDE have TCP/IP access to connect to this proxy instance and vice-versa. I'll call the machine "mymachine" in the examples below.
      Here is the command to start the proxy "dbgpproxy -i IDE-PORT -d DEBUG-PORT":
      pydbgpproxy -i 9001 -d 9000

      The IDE-PORT is where Komodo will to connect with the proxy and the DEBUG-PORT is where the application being debugged will connect to the proxy (see details below).

    • Komodo IDE will need to be configured and connect to this proxy service. Go to Komodo's preferences, then select the "Debugger->Connection" category, it does not matter what port Komodo is configured to listen upon (either a system-provided free port or a specific port is fine). Check the "I am running a debugger proxy and Komodo should use it." checkbox, then fill in the Proxy Listener Address, which is the IP address of where the proxy is running, i.e. "mymachine:9001". Set the proxy key to any string value you wish, I'll use "myname" (without the quotes) for the example.
    • Configure the application/server settings to connect to the proxy server, the details of this will be different between languages, but here are some examples:
        # Python
        pydbgp -d myname:9000 -k myname my_python_code.py
        # Perl
        export PERLDB_OPTS=RemotePort=mymachine:9000
        export DBGP_IDEKEY=myname
        # PHP, uses the Xdebug php.ini settings, like:
        xdebug.remote_host=mymachine
        xdebug.remote_port=9000
        xdebug.idekey=myname
        # Start your PHP debug session in your browser as you normally would, appending the xdebug string to the url "?XDEBUG_SESSION_START=myname"
       
    • Note that if you do not specify an proxy/IDE key when debugging, the user/username of the debugging process will be used.
  • How do I start debugging with my selected Komodo application?
    • You'll need to define your IDE key, this sets the Komodo application you wish to connect to and must match the Proxy Key setting you have placed in your Komodo debugging preferences. The key is defined and passed to the debugging proxy differently, depending upon the language your debugging. Some examples below:
        # Python, -k sets the proxy key
        pydbgp -d myname:9000 -k myname my_python_code.py
        # PHP, start your PHP debug session in your browser as you normally would, appending the xdebug string to the url:
        ?XDEBUG_SESSION_START=myname
        # the name after the equals sign "myname" represents the IDE key
       
    • When you do not define the ide key, the debugging client will use the username as the key, making use of the "USER" and "USERNAME" environment variables as necessary.
  • What alternatives do I have when the two machines cannot see (connect to) each other?

    If you have machine A and machine B that cannot connect to each other, you may be able to use ssh port forwarding to pass the connection along between the two (often useful in the case of a vpn/private network, or where you have only access to an intermediate machine). The actual technique used is what is called a reverse SSH port forwarding, see http://toic.org/2009/01/18/reverse-ssh-port-forwarding/.

    • Run the following code on the client machine (Note: the client machine is where the code is actually running):
      ssh -R 9000:localhost:9000 komodo.machine.com

      if using an intermediate host, replace the localhost with the client address like this:

      ssh -R 9000:client.machine.com:9000 komodo.machine.com
    • Once setup, you should be able to set Komodo to listen for connections locally on port 9000, and set the client to connect to the debugger on it's locally on port 9000 and the ssh tunnel will pass the connection between the two (three for intermediate) machines.

Additional configurations and settings for remote debugging can be found in Komodo's application help menu.