Setup
I have an embedded device that runs a version of Ubuntu Server 18. On it is some Python code that was specifically written for Python 3.6.8. I need to debug pieces of this code quite regularly and so far I did this with pdb. While this is fine and works, its a bit cumbersome and I would prefer a solution that is integrated with VS Code, since I'm using the Remote Development extension for development.
The unfortunate part is that the debugger that comes with the Python Extension Pack has dropped Python 3.6.8 support quite a while ago. Now according to this github issue and this comment in particular, by downgrading to a specific version of the debugger it should be possible to debug Python 3.6. So I tried this on my host machine (not the embedded device) and indeed, if you downgrade debugpy to 2023.1.12492010 one can debug Python 3.6 without issues.
Installing this specific version of the debugger into the remote development environment is tricky (read impossible to do and one needs to copy stuff over scp and modify the .vscode-server/extensions/extensions.json by hand), but once this was done I still cant get the debugger to run as expected on the device. If I look in the Debug Console in the Python section I get a message that looks something like this:
2023-12-03 15:10:42.318 [info] DAP Server launched with command: /usr/bin/python3 ~/.vscode-server/extensions/ms-python.python-2023.20.0/pythonFiles/lib/python/debugpy/adapter
and I see nothing else. So, according to google, vscode still launches the debugger that comes with the extension pack. Unfortunately, it seems impossible to specify the debugger in the launch.json (see all the options listed here).
Unsatisfying solution
I was able to find a workaround the issue. Namely, install the debugpy pip-package (you need to be careful here to get the correct version, for Python 3.6 this would be debugpy==1.5.1) on the embedded device and then start the python code over
sudo python3 -m debugpy --listen 1.2.3.4:5678 --wait-for-client my_code.py
Then over the Remote Development open the code my_code.py that is on the device and run the following configuration
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "1.2.3.4",
"port": 5678
}
}
With this you then can debug the code in VS Code. Unfortunately, this two-step process cannot be automated with the task-framework of vscode, i.e. create a task that executes the above python script and add it as preLaunchTask to the above attach-configuration due to the sudo. I.e. tasks in vscode cannot be executed with sudo privileges...
Question
Does anybody have a solution on how to get all of this working in a single VS Code configuration?