Problem with enabling remote debugging for both c++ and python

Operating system:windows10
Slicer version:slicer 4.6.2
Expected behavior: Expect the debug working for both c++ and python scripts
Actual behavior: the remote Debug is not working

Hi Slicer supporters, firstly I would like to ask some questions regarding the possibility of using slicer for my application, then I would ask some thing about setting the debug working.

I would like to use slicer in 3d application. In such application, I need to do the following:

-I would like to change the layout of 3D volume “Dual 3D” in to full screen, which means I need to change all the GUI and only show the left and right rendered volume without R, Y, G and any other panels. Is possible to do this and could you give some suggestions where I have to modify inside the slicer scripts?

-Then I would like to synchronize the the two views of the “Dual 3D”, currently only one is active and I have read in slicer 3 that is the limitation of the Slicer software. Here I have another question: Is possible to make the two view synchronized or two camera synchronized?

ISSUES WITH REMOTE DEBUGGING:
1.I have followed the build instructions to build Qt 4.8.7 debug mode successfully by using the following information :

Visual Studio 2013 with Update 5, as of commit 7160260: Slicer compilation is successful, with some caveats.
CMake >= 3.3.1
Build Qt 4.8.7 with SSL support using qt-easy-build.
For Debug mode, disable Slicer_USE_SimpleITK in CMake.

  1. Then I did the 3 steps listed in the checkout slicer source files
    https://www.slicer.org/wiki/Documentation/Nightly/Developers/Build_Instructions

  2. then followed Per-platform instructions (windows) to build the “ALL_BUILD” project successfully with debug mode.
    https://www.slicer.org/wiki/Documentation/Nightly/Developers/Build_Instructions

  3. Then I open Slicer.sln in visual studio and select debug as build configure, and build again, everything is fine.

Then use liclipse 3.6.0 with java 8, and Eclipse to Neon.3 (4.6.3). to set the debug tool by doing the following

  1. Slicer->Edit->Application settings->Modules->Additional module paths:
    1a. Add location of your .py file(s)
    1b. Restart Slicer
  2. In LiClipse, Start Debug Server (see module wiki page for instructions)
  3. In Slicer->Modules->Developer tools->Python debugger->Connect
  4. In LiClipse, Open the debug window: in the menu Window > Open Perspective > Other > Debug
    4a. MAKE SURE DEBUG TAB IS SHOWING!!!
  5. Resume when it pauses
  6. Open .py file(s) from Additional module paths: above in LiClipse
  7. Debug

However, I tried the HelloPython module from the slicer tutorial, it worked a couple of time, then does not work any more.

For Debugging in C++, I used the right version of pip, and ptvsd, and I also set TCP port (5678) of slicer.exe in fire wall, then I followed the following steps:
In Visual Studio, select Debug > Attach to Process to display the Attach to Process window, then:
Choose Python remote (ptvsd) as the Transport.
Enter “tcp://slicer@localhost” as the Qualifier. Here, “slicer” should match the secret specified in enable_attach().
Press Enter or click Refresh. The Slicer process should appear in the list below. Select the Slicer process and click Attach.

Once the debugger attaches, you can use breakpoints, step through the code, and examine variables in the Watch window.

However, the problem is that the debugger is never attached because the Slicer process did not appear in the list and the Attach button is not active.

I really hope you can help me with my first two questions and the debug issues.

Thanks !!

Best regards

zen

See this example how to switch between showing a single module / showing the usual Slicer user interface: SlicerIGT/Guidelet.py at master · SlicerIGT/SlicerIGT · GitHub

Use the same camera node for both views: Go to Cameras module. Select View: View2, Camera: the first “Default Scene Camera” in the list (unfortunately, by default both camera views have the same name).

If you need help with this then you have to describe what steps you do, what you expect, and what happens actually.

For Debugging in C++, you don’t need pip, ptvsd, etc. It will not be a remote debugging but a direct attachment to the process. In Visual Studio menu select: Debug / Attach process. In the window that is displayed all processes that are running on your computer are listed in “Available processes”, so if Slicer is running then you’ll see it. There are two processes for Slicer: Slicer.exe and SlicerApp-real.exe. Select SlicerApp-real.exe.

Hi Andras,

Thanks very much for your kind reply and detail explain.

For synchronizing the camera, I tried like this, go to module Cameras-> select view2, camera “I use Default Scene camera”, however, when I move one of the rendered volume, the other one is not moving. I expect the other one moves identically when I move one of them, such as rotating, zooming.

For the python debug:

What I did as follows:
1.Set remote debug in LiClipse by go to : Window-> Perspective->customize perspective-Action Set Availablity->tick python debug
2. Then Window->Perspective->Open perspective->Other…->Select Debug
3. Then I go to Edit->application setting->Module->add the fold directory contain the HelloPython script
4. go to LiClipse ->start the pydev server
5. go to Slicer->develop tool->python debugger
6. in the settings, I selete Eclise (since there are only two options, the other is Pycharm
7. then find the pydevd.py directory
8. the default port is 5678
9. then click connect to Eclipse debugger
10, then I open helloPython.py in LiClipse
11. add a break point
12. then I go to slicer, select the HelloPython from the example category, it happened one time, slicer paused and I see all debugged variables and slicer code completion. However, when I close the computer and I repeat again, it doesn’t work anymore.

If I did mistake or you have stable version that allow to debug python code, could you let me know?

Best regards

Zen

Hi Andras,

I have tried your suggestion in slicer for c++ debugging but I did not see slicer pause, or variables. The steps I did as follows:

I kept slicer open, then open VS 2013, then follow your instructions: go to Debug->attach to process->choose SlicerApp-real.exe, however I only saw some small watch window pop out and I do not see any variables and also slicer is not pause at all. I expect it will pause and show some variable values if I using a module.

Then for the camera synchronizing:

I did the following as you said but one of the camera is always static when I am moving the other one, the are not moving together and identically.

Best regards

Zhen

Put a breakpoint in your code. When Slicer executes that line it’ll pause and show all variables.

Can you record a screen capture video of how you do this and send a link to the video? On Windows, you can use PowerPoint to capture video of your screen (menu: Insert / Screen Recording).

Hi Slicer developers,

Sorry to bother you with the python remote debug question as I build my slicer again, it still has the same problem. Here I have a couple of questions:

-If anybody has made the remote debug working in LiClipse, could you tell me which Qt, Visual studio, and LiClipse version are you using?
-If the remote debug can not work in LiClipse, could you tell me any other tool that you are using makes the debug successful?
-If remote debug will not work with any tool, could you tell me how to effectively find the error of the scripted python module?

Best regards

Zen

Hi Zen -

I don’t use any of the IDE or remote debugging options - to debug python code in Slicer I start with a scripted module from the extension wizard, then with Slicer in developer mode I use the Reload and Test buttons and incrementally add functionality.

You can also use slicer.modules.Widget to access the module’s gui and from there you can typically inspect any variables and call any methods needed for debugging.

Hope that helps,
Steve

First of all: do you want to debug Python or C++ code? Python code is not visible to C++ debuggers, C++ code is not visible to Python debuggers.

You need to follow the instructions very accurately. If you run into any issue, then please create a screen capture of what you did, upload to dropbox/onedrive/gdrive and attach the link and we can then tell what went wrong.

Hi Steve,

Thanks very much! I am very new to slicer, what do you mean slicer in developer mode?

Do I still need to build slicer with Qt, visual studio or just download the slicer from official website is enough?

However, I will try your suggestion soon !

Thanks very much !

Zen

Get Outlook for iOShttps://aka.ms/o0ukef

Hi Zen -

In the Application Settings dialog (from the Edit menu):

Then your scripted modules will have these options:

Of course this is only for the python code, but you can use this with any Slicer, either a binary download or one you build yourself.

If you want/need to debug C++ code then you need to build your Slicer from source.

Hi Steve,

Thanks very much for your detail explain :slight_smile:

Best regards

Zen

Get Outlook for iOShttps://aka.ms/o0ukef

A post was split to a new topic: How reload module button works?