简体   繁体   English

VS Code - Python 调试 - 进入内部函数

[英]VS Code - Python Debugging - Step into internal functions

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.在 VS Code 中,分步调试器不会单步执行内部函数,而是在调用函数后立即分配返回值。 how should I change my configuration in launch.json for this to happen?我应该如何更改我在launch.json中的配置才能发生这种情况?

current launch.json file:当前的launch.json文件:

{
    ...,
    "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.我将JustMyCode更改为false并且正如预期的那样,它会进入一些我既不熟悉也不需要的基本文件。

The question is: What should I do so that my python debugger in VS Code steps into internal functions问题是:我应该怎么做才能让我在 VS Code 中的 python 调试器进入内部函数

For Eg you have a function to calculate the factorial of the given number n .例如,您有一个函数来计算给定数字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.在 VS Code 中选择Run and Debug后,我按下顶部的暂停符号,这样程序在我给它输入后就不会继续。 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.在我给出输入后,程序仅通过我的点击逐步继续(逐行每个Step OverF10按钮。当主程序到达调用内部阶乘函数的位置并且我按F10时,逐行 -行执行不进入阶乘函数内部,而是分配阶乘函数的返回值。

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) .想象第一行是def factorial(n) When the program starts, the step over debugging goes like this:当程序启动时,调试步骤如下:

7,8,9 7,8,9

whereas I want it to go like this:而我希望它像这样:

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

I hope I made myself clear.我希望我说清楚了。

The operation of debug is clearly stated in the document . debug的操作在文档中有明确的说明。 "step into" is F11 . “步入”是F11

在此处输入图像描述

  • Continue / Pause F5继续/暂停F5
  • Step Over F10跨过F10
  • Step Into F11步入F11
  • Step Out Shift+F11跳出Shift+F11
  • Restart Ctrl+Shift+F5重启Ctrl+Shift+F5
  • Stop Shift+F5停止Shift+F5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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