Remote Debug skill

Remote Debug

Enable PTVSD - Python Tools for Visual Studio debug server

This skill adds PTVSD - Python Tools for Visual Studio debug server to make it posible to
debug running skills.
It is made as a companion to the THEIA IDE skill to enable debugging from there. But if you use another IDE like VS Code you can use this skill to inject the debug adaptor in the
mycroft.skills service and attach to it on port 5678.

When you activate debugging by saying “Run debug adaptor” the skill will change Settings for padatious single_thread = true so skills service runs in single thread.

THEIA IDE (latest version) should already be setup so you just have to start debug from debug menu after starting remote debug adaptor.

When finish debugging say “End debug adaptor” and skill restore single_thread settings and the skill will restart mycroft.skills service

https://github.com/Microsoft/ptvsd

This skills requeue using the dev branch !

launch.json

To use the debug adaptor from THEIA IDE or VS Code make sure you use Python
remote attach setting in launch.json

    {
        "name": "Python: Remote Attach",
        "type": "python",
        "request": "attach",
        "port": 5678,
        "host": "localhost",
    }

Examples

  • Start (remote|ptvsd|) debug adaptor
  • Enable (remote|ptvsd|) debug adaptor
  • Run (remote|ptvsd|) debug adaptor
  • Stop (remote|ptvsd|) debug adaptor
  • Exit (remote|ptvsd|) debug adaptor
  • End (remote|ptvsd|) debug adaptor

How to install Remote debug skill

use mycroft-msm to install the skill

mycroft-msm install https://github.com/andlo/remote-debug-skill.git

How to test Remote debug skill

  • Start remote debug adaptor by saying “hey mycroft - run remote debug adaptor”
  • in VS THEIA IDE or VS code (or maybe other IDE` start debug and atatch to remote
  • edit the init.py in the mycroft-hello-world.mycrofta skill
  • set breakpoint in line 46 `` self.speak_dialog(“how.are.you”)````
  • say “hey mycroft - thanks” and see that code is paused and debuger is active
  • step throu the code or stop debuging
  • say “hey mycroft - end remote debug adaptor”

If it works as expected th debugger stops and and you can go throu code step by step and see values in variables etc. you can step in and out of functions

When debug adaptor is running you can se that ptvsd is running

andlo@DESKTOP-D9EUQU6:/opt/mycroft/skills/mycroft-hello-world.mycroftai$ ps ax |grep " -m mycroft.skills"
17025 ?        Sl     5:36 python3 -m ptvsd --host 0.0.0.0 --port 5678 -m mycroft.skills
20565 pts/0    S      0:00 grep --color=auto  -m mycroft.skills

when debugger isnt running you see

andlo@DESKTOP-D9EUQU6:/opt/mycroft/skills/mycroft-hello-world.mycroftai$ ps ax |grep " -m mycroft.skills"
20696 ?        Rl     0:01 python3 -m mycroft.skills
20782 pts/0    S      0:00 grep --color=auto  -m mycroft.skills

Feedback on this Skill and debugging with PTVSD can be done through Issues on the skills GitHub page or here in the forum or via Mycroft Chat.

5 Likes

To use Remote debug from VS code I use plugin " Remote - SSH" ms-vscode-remote.remote-ssh and “Remote - SSH: Editing Configuration Files” ms-vscode-remote.remote-ssh-edit and ssh to picroft and go to folder /opt/mycroft/skills

To use Vscode and working on mycroft running in a WSL I use plugin “Remote - WSL” ms-vscode-remote.remote-wsl and go to folder /opt/mycroft/skills

both when conecting to picroft and WSL I also added the plugin “Python”
ms-python.python.

On WSL I had to add the venv location information in the python settings

To use it from THEIA IDE just install the latest THEIA IDE skill and it should be all setup to debug in skills folder and having right plugins installed.

To use from PyCharm I cant figure out how - PyCharm is for me a bit confusing. But as far as I can read PyCharm should be able to do the same as VS code and THEIA and connect to a remote system and debug adaptor running there.

1 Like

Helo @andlo , acording to mycrosoft git, ᴘᴛᴠsᴅ is now deprecated in flavor of debugpy. Will You update Your skill?

I tried it by myself, but I end up with:

 23:28:15.346 | INFO     | 350880 | RemoteDebug | Starting DEBUGPY - Python Tools for Visual Studio debug server.....
 23:28:15.346 | INFO     | 350880 | RemoteDebug | Debugserver port 5678 reddy for attatch.
 23:28:15.346 | INFO     | 350880 | RemoteDebug | THEIA IDE is already setup so you just have to start debug from debug menu
 23:28:15.347 | INFO     | 350880 | RemoteDebug | Setting padatious single_thread = True
 23:28:15.347 | INFO     | 350880 | RemoteDebug | Restarting skill-service
Stopping skills (350880)...Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/srv/mycroft-core/mycroft/skills/__main__.py", line 297, in <module>
    main()
  File "/srv/mycroft-core/mycroft/skills/__main__.py", line 233, in main
    time.sleep(0.1)
  File "/srv/mycroft-core/mycroft/lock/__init__.py", line 69, in __call__
    self.__previous_func(signame, sf)
KeyboardInterrupt
failed to stop.

Helo, I went a little ahead and made a necessary changes, they can be found in PR #1