简体   繁体   中英

How do I step through code when debugging in VSCode?

I'm very new to debugging. My whole programming "career" has been limited to inserting print statements to try to figure out why things aren't working the way I want them to. Now I'm trying to step through my Python code in Visual Studio Code, but when I try to step into the debugger, it jumps straight to the first exception (which is like 50 steps in to be clear).

I saw that there are debugging configurations, but surely I don't have to learn all about those just to step through the code. And I know you can set breakpoints, but I'd like to see each step for now. Is there something I'm missing? I was using IDLE to step through my somewhat simple function prior to trying VSCode, but all of the little tweaks made that way too slow. Thanks for any help you can provide.

As best I can tell, this is the configuration I'm using by default:

{
    // 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"
        }
    ]
}

You may try the module pdb . Run python -m pdb name.py to start Debugging in Terminal.

Type n to execute code step by step;

Type p <variable_name> to check its value;

Type q to stop and quit.

在此处输入图片说明

More information about python debugging please view the link i mentioned at start.

[UPDATE]

There's new release about VSCode-Python, please view Two new debugger features: step into targets and function breakpoints .

As indicated in the comments below the question, I eventually discovered adding a breakpoint to the first line of code allowed me to achieve the functionality I was looking for. Obviously, the execution stops at the break point, and then I am able to step all the way through to my exception, as desired. I'm not sure if a line 1 breakpoint is the correct way of doing this, but it's working for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM