Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breakpoints in multiple files in VS Code?

I have a Python project with multiple files/modules, that I'm trying to debug. I have the Python extension installed, and I put a bunch of breakpoints in - some in the current file and some in another file/module. Breakpoints in the current file are working fine, however, the breakpoints in other file(s) are not. Is there a step I'm missing in setting the debugger up? Couldn't find anything on Google for this specific problem, the tutorials only show debugging in one file and that is working fine. If I try to right click and go to the definition of any function in another module, that also works fine so the project is aware of the multiple modules (I have the whole directory open in VS Code), the breakpoints don't.

like image 632
lte__ Avatar asked Mar 07 '19 09:03

lte__


People also ask

How do I Debug multiple files in Visual Studio Code?

To debug multiple services at the same timeOpen the folder corresponding to your first service in VS Code. In VS Code, select File > Add Folder to Workspace…, and pick the folder corresponding to your other service.

How do I add a breakpoint to all methods in visual studio?

Press F3 and then press F9 to add a breakpoint.

How do you show all breakpoints in VS Code?

Breakpoints can be toggled by clicking on the editor margin or using F9 on the current line. Finer breakpoint control (enable/disable/reapply) can be done in the Run and Debug view's BREAKPOINTS section.

How do I select multiple files in VS Code?

Multi-selection#Use the Ctrl/Cmd key with click to select individual files and Shift + click to select a range. If you select two items, you can now use the context menu Compare Selected command to quickly diff two files.


1 Answers

Ran into the same issue. In case you still need to know, this is how I resolved it.

  1. Create a workspace in vscode
  2. Add the folders you want into the workspace with all the files you need. We need to do this to create the launch.json file
  3. Click on the Debug Icon or Ctrl+Shift+D
  4. Click the gear icon in the debug sidebar at the top. It will say open launch.json
  5. If one is not created, it will automatically create it for and it should look like:
{
    // 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"
        }
    ]
}

  1. Add in justMyCode, but set to false
{
    // 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",
            "justMyCode": false
        }
    ]
}

  1. Save and start debugging. You should be able to step into other modules now.

A screenshot of what the debug screen configuration should now look like: Python debug configuration

You can create different configs if you don't want to debug other modules or do things as well.

like image 95
Matt Avatar answered Sep 27 '22 19:09

Matt