Home > Net >  VS Code - Python Debugging - Step into internal functions
VS Code - Python Debugging - Step into internal functions

Time:07-22

In VS Code, the step-by-step debugger won't step into internal functions, and instead, after the function is called it immediately assign the return value. how should I change my configuration in launch.json for this to happen?

current launch.json file:

{
    ...,
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true
        }
    ]
}

I changed JustMyCode to false and as expected, it steps into some fundamental files I'm neither familiar with nor need.

The question is: What should I do so that my python debugger in VS Code steps into internal functions

For E.g. you have a function to calculate the factorial of the given number n. after selecting Run and Debug in VS Code, I press the pause sign on the top so the program does not continue after I give the input to it. after I give the input, the program continues step by step with my clicks only (line by line with each Step Over or F10 button. when the main program reaches where the internal factorial function is called and I press F10, the line-by-line execution does not go inside the factorial function. Instead, it assigns the returned value from the factorial function.

def factorial(n):
    ans = 1
    for i in range(1,n 1):
        ans*=i
    return ans

x = int(input())
answer = factorial(x)
print(answer)

Imagine the first line is def factorial(n). When the program starts, the step over debugging goes like this:

7,8,9

whereas I want it to go like this:

7,8,2,3,4,3,4,...,5,8,9

I hope I made myself clear.

CodePudding user response:

The operation of debug is clearly stated in the enter image description here

  • Continue / Pause F5
  • Step Over F10
  • Step Into F11
  • Step Out Shift F11
  • Restart Ctrl Shift F5
  • Stop Shift F5
  • Related