diff options
author | Adrian Herrmann <adrian.herrmann@qt.io> | 2022-07-21 16:16:11 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-08-10 10:31:47 +0000 |
commit | 34aab820c9c73e519d348306201d12a5099e7035 (patch) | |
tree | 2c28375184364159eac987971cbb2561e3cd31e0 /sources | |
parent | 4082286dd9a12c6ccec309e1bb9fd9440e0d143e (diff) |
Update the VS Code debugging tutorial for Windows
Update the "Debugging PySide with VSCode" tutorial so it applies to
Windows as well.
Task-number: PYSIDE-2000
Change-Id: I487534f3094e2b9a1c2b60733ffe599afe7b39b4
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit 7e1c05339cdd1e457646f27e939d50f6ccbc25ae)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'sources')
-rw-r--r-- | sources/pyside6/doc/tutorials/debugging/vscode/python_set_interpreter.png | bin | 0 -> 4664 bytes | |||
-rw-r--r-- | sources/pyside6/doc/tutorials/debugging/vscode/vscode.rst | 116 |
2 files changed, 85 insertions, 31 deletions
diff --git a/sources/pyside6/doc/tutorials/debugging/vscode/python_set_interpreter.png b/sources/pyside6/doc/tutorials/debugging/vscode/python_set_interpreter.png Binary files differnew file mode 100644 index 000000000..1a26c9d9c --- /dev/null +++ b/sources/pyside6/doc/tutorials/debugging/vscode/python_set_interpreter.png diff --git a/sources/pyside6/doc/tutorials/debugging/vscode/vscode.rst b/sources/pyside6/doc/tutorials/debugging/vscode/vscode.rst index 2563b4377..bb91b5b99 100644 --- a/sources/pyside6/doc/tutorials/debugging/vscode/vscode.rst +++ b/sources/pyside6/doc/tutorials/debugging/vscode/vscode.rst @@ -1,9 +1,9 @@ -Debugging PySide with VSCode (Linux) -************************************ +Debugging PySide with VSCode (Linux + Windows) +********************************************** VSCode enables you to use more than one debugger in a single debugging session. -This means that we can use GDB and Python PDB in a single session. With VSCode -you would be able to do the following: +This means that we can use Python PDB and GDB (or the MSVC debugger for Windows) +in a single session. With VSCode you would be able to do the following: * See the call stacks for both Python and C++ together. * Put breakpoints in both the Python and the C++ code. @@ -11,6 +11,26 @@ you would be able to do the following: Let's get started with setting up everything and debugging a Python process. +Setting the Python interpreter +------------------------------ + +In order to debug Python code, it is necessary to set the correct Python +interpreter in VSCode - this will ensure that all Python integrations of VSCode +use the same interpreter. However, this does not affect C++ debugging, and the +Python executable path must be set for the corresponding launch target +separately (see the section below). + +To set the Python interpreter, open a Python file and click the corresponding +option on the right side of the VSCode status bar, which should look similar to +this: + +.. image:: python_set_interpreter.png + :alt: set Python interpreter + :align: center + +Alternatively, open the VSCode command palette (F1 or Ctrl + Shift + P) and +search for "Python: Select Interpreter". + Creating Configurations in launch.json -------------------------------------- @@ -36,13 +56,22 @@ This should create a launch.json file which looks like this: ] } -It should already consist of a configuration named "Python: Current File", which -allows us to debug the current open Python file. With a Python virtual -environment, make sure to change the value of "program" to refer to the path of the Python -interpreter inside the virtual environment. +It should already consist of a configuration named "Python: Current File", +which allows us to debug the current open Python file. -Now, we need to add a configuration to attach the GDB debugger to the Python -process that is already running in debug mode. Let's call it "(gdb) Attach" +Now, we need to add a configuration to attach the C++ debugger to the Python +process that is already running in debug mode. If you have the C/C++ extension +installed and the appropriate debugger for your system, VSCode should be able +to automatically offer to add a configuration. On Linux, this is suggested with +the name + +* "C/C++: (gdb) Attach" + +and on Windows with the name + +* "C/C++: (Windows) Attach" + +Your launch.json should now look like this on Linux: .. code-block:: javascript @@ -58,7 +87,8 @@ process that is already running in debug mode. Let's call it "(gdb) Attach" "request": "launch", "program": "${file}", "console": "integratedTerminal" - }, { + }, + { "name": "(gdb) Attach", "type": "cppdbg", "request": "attach", @@ -75,8 +105,35 @@ process that is already running in debug mode. Let's call it "(gdb) Attach" ] } -Here also make sure that the value of "program" refers to your Python interpreter. We need the -processId to attach the gdb debugger to the process. With +And like this on Windows: + +.. code-block:: javascript + + { + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + }, + { + "name": "(Windows) Attach", + "type": "cppvsdbg", + "request": "attach", + "processId": "${command:pickProcess}", + } + ] + } + +For Linux, also make sure that the value of "program" refers to your Python +interpreter inside your virtual environment (for Windows this is not needed). +We need the processId to attach the gdb debugger to the process. With "${command:pickProcess}", we find the processId on the go, as we will see later. Now, we are ready to debug. @@ -86,28 +143,30 @@ Debug The Process 1. Set a breakpoint in the Python code. -2. Go to `Run And Debug` (Ctrl + Shift + D) and run the "python: Current File" - by clicking the run symbol (green right-arrow). This will hit the breakpoint and - will halt the Python debugger. +2. Go to `Run And Debug` (Ctrl + Shift + D) and run the "Python: Current File" + by clicking the run symbol (green right-arrow). This will hit the breakpoint + and will halt the Python debugger. -3. Using the drop-down menu change from "python: - Current File" to "(gdb) Attach". Your setup should now look like this. +3. Using the drop-down menu change from "Python: + Current File" to "(gdb) Attach" or "(Windows) Attach". Your setup should now + look like this. .. image:: breakpoint_gdb.png :alt: breakpoint before attach gdb :align: center -4. Run "(gdb) Attach" and this should ask you for the processId of the Python - process to which you want to attach gdb. VSCode also lets you to search for the - process by its name. .. tip:: You can find the processId by running `ps aux | - grep python` +4. Run "(gdb) Attach" or "(Windows) Attach" and this should ask you for the + processId of the Python process to which you want to attach the C++ debugger. + VSCode also lets you search for the process by its name. + + .. tip:: You can find the processId by running `ps aux | grep python` .. image:: find_process_gdb.png :alt: find process vscode :align: center -5. VSCode will now ask you for superuser permissions. Type 'y' and enter your - password. +5. VSCode might now ask you for superuser permissions. In that case, type 'y' + and enter your password. .. code-block:: bash @@ -122,15 +181,10 @@ Debug The Process :alt: Breakpoint set on the shiboken wrapper class :align: left - Breakpoint set on the shiboken wrapper class + Breakpoint set on the shiboken wrapper class .. figure:: audioformat_cpp.png :alt: Breakpoint set on C++ implementation :align: left - Breakpoint set on C++ implementation - - - - - + Breakpoint set on C++ implementation |