VSCode Debug

debug操作

行为快捷键
Continue / PauseF5
Step OverF10
Step IntoF11
Step OutShift+F11
RestartCtrl+Shift+F5 已经更改为Ctrl+F5
StopShift+F5

查看变量

在这里插入图片描述

1.Variables窗口可以查看当前内存中的变量值,并且可以进行设置
2.Watch窗口可以观察指定的变量

断点

在这里插入图片描述
1.普通断点
2.条件断点,当触发条件时才打断,经常用在循环里
3.日志断点,不打断,只输出

debug配置

https://code.visualstudio.com/docs/editor/debugging#_launchjson-attributes

debug所有配置文件都保存在.vscode/launch.json里,可以配置环境变量

{
    // 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: 当前文件",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

下面三个变量每个launch.json文件都包含

type - the type of debugger to use for this launch configuration. Every installed debug extension introduces a type: node for the built-in Node debugger, for example, or php and go for the PHP and Go extensions.
request - the request type of this launch configuration. Currently, launch and attach are supported.
name - the reader-friendly name to appear in the Debug launch configuration drop-down.

下面的是可选的变量

presentation - using the order, group, and hidden attributes in the presentation object you can sort, group, and hide configurations and compounds in the Debug configuration dropdown and in the Debug quick pick.
preLaunchTask - to launch a task before the start of a debug session, set this attribute to the name of a task specified in tasks.json (in the workspace’s .vscode folder). Or, this can be set to ${defaultBuildTask} to use your default build task.
postDebugTask - to launch a task at the very end of a debug session, set this attribute to the name of a task specified in tasks.json (in the workspace’s .vscode folder).
internalConsoleOptions - this attribute controls the visibility of the Debug Console panel during a debugging session.
debugServer - for debug extension authors only: this attribute allows you to connect to a specified port instead of launching the debug adapter.
serverReadyAction - if you want to open a URL in a web browser whenever the program under debugging outputs a specific message to the debug console or integrated terminal. For details see section Automatically open a URI when debugging a server program below.

很多的debug程序包含以下变量

program - executable or file to run when launching the debugger
args - arguments passed to the program to debug
env - environment variables (the value null can be used to “undefine” a variable)
cwd - current working directory for finding dependencies and other files
port - port when attaching to a running process
stopOnEntry - break immediately when the program launches
console - what kind of console to use, for example, internalConsole, integratedTerminal, or externalTerminal

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VS Code是一款开源的集成开发环境,它支持多种编程语言和框架,并且提供了强大的调试功能。在VS Code中,你可以使用调试器来查找和修复代码中的错误。 要在VS Code中进行调试,你可以使用内置的调试功能或者安装适用于特定语言或框架的调试扩展。通过调试功能,你可以设置断点、观察变量的值、单步执行代码等。 关于C++的调试,在VS Code中有一些特定的调试配置和设置。你可以按照以下步骤进行配置: 1. 确保你已经安装了C++扩展(可以在扩展市场中搜索并安装)。 2. 打开你的C++项目,并打开一个C++源文件。 3. 在左侧的侧边栏中,点击调试图标(调试面板)。 4. 点击顶部工具栏中的齿轮图标,选择“C++”作为调试环境。 5. 在调试面板中,点击“创建一个启动配置文件”,选择“C++ (GDB/LLDB)”作为启动配置。 6. 在生成的启动配置文件中,你可以设置调试器的路径、可执行文件的路径、工作目录等。 7. 设置好后,你可以在代码中设置断点,并点击调试面板中的“启动调试”按钮来开始调试。 关于调试的更多信息,你可以参考以下文档: - 【01】https://code.visualstudio.com/docs/editor/debugging - 【02】https://code.visualstudio.com/docs/cpp/cpp-debug 需要注意的是,输入/输出重定向是特定于调试器/运行时的,因此VS Code没有适用于所有调试器的内置解决方案。具体的输入/输出重定向方法需要根据你使用的调试器或运行时环境进行配置。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [如何用VsCode进行Debug](https://blog.csdn.net/weixin_42962086/article/details/123274273)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [【VSCode调试debugger详细使用手册](https://blog.csdn.net/shentian885/article/details/123896536)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值