question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support remote Python debugging

See original GitHub issue

After thinking about this some more, this approach locks cocotb into debuggers that use the Debug Adapter Protocol such as VSCode or Theia (used by GitPod). There are a variety of ways to do remote debugging:

  • VSCode/GitPod uses debugpy.
  • Pycharm Professional uses pydevd-pycharm.
  • PyDev in Eclipse uses plain pydevd.
  • Our docs recommend remote-pdb.

This may be a good candidate for cocotb extensions that provide a setuptools entry point that can be selected by COCOTB_PY_ATTACH.

So for example, a new extension cocotbext-debugpy could provide an entry point:

setup(
    name = 'cocotbext-debugpy',
    entry_points = {"cocotb.remote_debugger": "debugpy = cocotbext.debugpy:debug_attach"}
    ...
)

And the user would select it with COCOTB_PY_ATTACH=debugpy,localhost:5678

_Originally posted by @garmin-mjames in https://github.com/cocotb/cocotb/pull/2103#issuecomment-705050127_


This issue is to discuss the best approach to support remote debugging.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

3reactions
ktbarrettcommented, Oct 13, 2020
  1. Is supporting remote debugging on Python initialization desirable?

Yes IMO.

  1. If so, can we settle on an approach to enable it?

Of course!

I like the simplicity of a single environment variable, but it may make sense to split it up.

  • COCOTB_PY_DEBUGGER - debugpy, pydevd-pycharm, etc
  • COCOTB_PY_ATTACH - host:port or just port if localhost

The number of point solutions and environment variables we are using for those point solutions is already a lot IMO, and adding more is only going to decrease maintainability. I think it’s time to step back and abstract the problem. To me the best solution to abstract all the behaviors we want at startup, as well as support user customization points, as “custom entry points” (#1225). To me, these are more of a startup routine. Attaching a Python debugger can be one of those startup routines, and so could other existing aspects of _initialize_testbench (like enabling coverage).

For example, in your PR you have encapsulated the behavior into a function. Now we can do COCOTB_STARTUP_ROUTINES += ',cocotb:_check_debug_attach'. The remote debugger initialization could live in this repo, or not. Whether it can exist or not is then divorced from everyone else’s approval. I think this is the path forward for new features that must run during initialization. There are also a host of other issues that can be solved using this generalized approach.

P.S. Maybe there is a way to support passing simple literal values safely to these routines? So that you don’t even need the additional environment variable for the port #.

1reaction
eric-wiesercommented, Oct 14, 2020

@garmin-mjames: Note in principle that cocotb could support only entry_points, and we could provide a cocotb-plugin-hacks package that provides an entry point that reads COCOTB_STARTUP_ROUTINES (or vice versa)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging configurations for Python apps in Visual Studio Code
This article mainly addresses Python-specific debugging configurations, including the necessary steps for specific app types and remote debugging.
Read more >
Remotely debug Python code on Linux - Microsoft Learn
Visual Studio can launch and debug Python applications locally and remotely on a Windows computer (see Remote debugging). It can also debug ......
Read more >
Remote Debugging Guide for Python | Codementor
Learn how to go beyond print and logging to debug tough problems efficiently using remote debugging in python.
Read more >
PythonDebuggingTools - Python Wiki
PyCharm's integrated debugger works for Python and Jython, supports debugging of multiple threads, remote debugging, allows debugging Django, ...
Read more >
Remote Python Debugging - Komodo 12 Documentation
Using the Python Remote Debugger. When debugging a Python program remotely, the program is executed on the remote machine, and the debug output...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found