Remote Debbuging [NEW]
What is remote debbuging and why is it useful?
Remote Debugging allows to debug the program running on another system as long we have access to the source code and debugger port is present on the system running the application. We can describe this process in a few steps:
Configure application to debug.
Load the code into Visual Studio Code.
Configure Visual Studio Code to connect to the remote debugger.
Step by step
We can attach our debugger to remote program in a few simple steps:
Check if remote debbuging port is open
Remember that application has to be run in the debugging mode in order to connect our debbuger.
Debug mode in Java applications (LOCAL):
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=[PORT] -jar ~/[PROGRAM].jarFully Remote with wildcard:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:[PORT] -jar [PROGRAM].jarReconfigure bench (tool for Frappe applications)
Install ptvsd
/home/frappe/frappe-bench/env/bin/pip install ptvsdEdit Procfile file and comment out starting web server
nano /home/frappe/frappe-bench/ProcfileComment the line below:
#web: bench serve --port 8000Reconfigure the application and use ptvsd to open up a debugging port by editing app.py file
nano /home/frappe/frappe-bench/apps/frappe/frappe/app.pyAdd the following code to app.py contents (which adds debugging server on port 5678):
import ptvsd
ptvsd.enable_attach(redirect_output=True)
print("Now you can connect IDE debugger.")
ptvsd.wait_for_attach()When bench serve command from Procfile is executed the bench runs app.py file.
Run bench serve:
cd /home/frappe/frappe-bench/bench startStart web server (in another SSH session / different screen in TMUX)
Move to application folder:
Run server:
Download the code related to the program
You have to get the source code of the application that you want to debug. It does not need to be ready to run as long as we only want to remote debug the program.
SSH Way:
Windows Way:
Save decompiled sources to zip on the Desktop and host fileserver.
Create launch.json
In the Debbuger part in VSCode the option for creating the configuration file will show up.

After creating it, inside we should add "[Programming language] Attach to Remote Program option"

In the body of the template we have to specify hostname and port on which debbuging port is turned on.
Select Attach to Remote Program option
In the Run and Debug panel you have to check the following option:

Run the debugger
Right now the debugger should work and the selected breakpoints should trigger when interacting with the application.
Last updated