Author Topic: Remote debugging for python with "import pdb; pdb.set_trace" functionality  (Read 2430 times)

sliqedit

  • Junior Community Member
  • Posts: 9
  • Hero Points: 0
Can Slickedit's pydbg be invoked to enable remote debugging from within anywhere in a SCons build? Something similar to how adding "import pdb; pdb.set_trace()" allows you drop anywhere in a python script.

Background:
We use SCons as our build tool, so I've created a python project and listed *.scons as python extensions.
During a remote debug session I can set a breakpoint in the starting point of the build, however, breakpoints are not stopping in modules called later in the SCons build.
Instead of troubleshooting this issue, I'd like to have a way to just activate a remote debug session by calling pydbg from anywhere in the build scripts.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
There a way that works with simple test scripts here. 

In SlickEdit, with the python project open:

1) Go to Build -> Python Options, Debug tab, change the debugger connection port to "Specific port", and set it to something that will work on your system.  Default of 9000 should be good in most cases.

2) In the Debug menu, if the "pydbgp Listen in Background" item is not already checked, select it, otherwise leave it alone.

In the module you want to break in, you can import 'brk' from dbgp.client and call it with the host and port to break.  Here's an example test program:

Code: [Select]
from dbgp.client import brk

def check():
  for i in range(1, 10):
    if i == 5:
      brk(host='localhost', port=9000)
      brk(host='localhost', port=9000) # Repeated intentionally, see below.
    else:
      print(i)

  print("done")

check()

Adjust the break calls to use the port you gave to SlickEdit.  The brk() call is repeated to get around a bug, where we just continue the process after the initial break that starts the debugging session.  If you know which break you'll hit first, you can just double up that one. 

When running scons, you'll need to set the PYTHONPATH to include the pydbgp library we ship with.  My install is at /opt/se1702, so my command line for the test program was:

Code: [Select]
PYTHONPATH=/opt/se1702/resource/tools/pydbgp-1.1.0-1/python3lib python3 /tmp/test.py

If it's using Python2, adjust python path to ".../pydbgp-1.1.0-1/pythonlib"

This should work even if the scons modules are spawned in new processes.

sliqedit

  • Junior Community Member
  • Posts: 9
  • Hero Points: 0
Thanks Patrick, this works :)

Just to clarify, if a build command is passed to pydbgp.py, should it be capable of breaking within child processes that are forked during the build?
It would be great to just set a breakpoint in any SCons file without having to edit it first with the check() function.

Nonetheless, I'm very grateful for your check() function, and thank you again for help you've provided.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
It's a limitation of that version of the debugging backend.  All of the workarounds I found were some version of "change the code to trigger a breakpoint."

Our next release is updating the version of the Python debugging backend, and I need to do some more testing to see if workarounds will still be necessary in the future for this scenario. 

sliqedit

  • Junior Community Member
  • Posts: 9
  • Hero Points: 0
Is there a notification list I can be put on to find out when this is available?

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
There will be a beta that will be posted on the forums.  I'll ping this thread once the multiprocess scenario is tested.

sliqedit

  • Junior Community Member
  • Posts: 9
  • Hero Points: 0
Hi Patrick,
I see SlickEdit(v25) is out for beta testing. Would this be a good candidate to try multiprocess scenario for remote debugging?


patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
No, a similar workaround is needed for the moment.   Multiprocessing support went into an alpha of PTVSD sometime around Nov of 2019, but didn't make it into a release.  When I looked last week, there's a rc1 candidate for what's been announced as the successor to PTVSD which seems to have a lot of the same internals, so I expect it to have the support, but did not look closely enough to verify.  Even if it was released now, it would be too late to bump the version we support for v25, even if the protocol was identical, because there are some changes we'd need to make to take advantage of the feature.  So we'll have to revisit it for an upcoming SlickEdit release/point-release.

sliqedit

  • Junior Community Member
  • Posts: 9
  • Hero Points: 0
Quote
Our next release is updating the version of the Python debugging backend, and I need to do some more testing to see if workarounds will still be necessary in the future for this scenario.

Hi Patrick/SlickEdit team,
Can you please let me know the debugging backend now supports remote debugging of child processes?
Or do we still need to change the code to trigger a breakpoint?

Thanks!

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
You'll still need to change the code to trigger a breakpoint for that scenario, we haven't updated the Python debugger backend since v25.


sliqedit

  • Junior Community Member
  • Posts: 9
  • Hero Points: 0
Is there any ETA for when this feature would be available?
If not, is there anything we can do to help make this feature a part of the official roadmap?

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
It doesn't have a target release yet.  Just letting us know on the forums here is enough to let us know your interest, you don't need to open anything through a support channel.