vscode launch

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "C/C++ Runner: Debug Session",
      "type": "cppdbg",
      "request": "launch",
      "args": [],
      "stopAtEntry": false,
      "externalConsole": true,
      "cwd": "d:/Project/leetcode",
      "program": "d:/Project/leetcode/build/Debug/outDebug",
      "MIMode": "gdb",
      "miDebuggerPath": "gdb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}

必选属性

  • type : type of debugger --- 每个debug扩展都有一个 type 名称
  • request : 请求类型 -- launch / attach
  • name : 自定义名称

可选属性

  • presentation : order, group,hidden , 用于 debug 侧边栏的展示
  "presentation": {
	"hidden": false,
	"group": "",
	"order": 1
  },
  • preLaunchTask : 在 debug 之前执行一个 task, 名称为 task.json 中的任务
  • postDebugTask : 在 debug 结束后执行一个 task
  • internalConsoleOptions : debug 期间的 终端面板控制选项
  • debugServer : 仅对debug扩展 : 此属性允许您连接到指定的端口,而不是启动调试适配器。
  • 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.

常见选项

  • 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)
  • envFile - path to dotenv file with environment variables
  • 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, internalConsoleintegratedTerminal, or externalTerminal

变量替换

[[vscode variable substitution]]

不同平台指定配置

![[vscode tasks#操作系统特定属性]]

断点

行内断点

shift - F9

一些其他断点

函数断点,数据断点

重定向输入或输出

两种方法 : 使用 attach 方法信息调试 ,或者使用管道(如果支持的话)

{
  "name": "launch program that reads a file from stdin",
  "type": "node",
  "request": "launch",
  "program": "program.js",
  "console": "integratedTerminal",
  "args": ["<", "in.txt"]
}

Multi-target debugging

同时启动多个 debug 程序

组合 launch 配置

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Server",
      "program": "${workspaceFolder}/server.js"
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Client",
      "program": "${workspaceFolder}/client.js"
    }
  ],
  "compounds": [
    {
      "name": "Server/Client",
      "configurations": ["Server", "Client"],
      "preLaunchTask": "${defaultBuildTask}",
      "stopAll": true
    }
  ]
}

自动打开URL -- need more use

{
  "type": "node",
  "request": "launch",
  "name": "Launch Program",
  "program": "${workspaceFolder}/app.js",

  "serverReadyAction": {
    "pattern": "listening on port ([0-9]+)",
    "uriFormat": "http://localhost:%s",
    "action": "openExternally"
  }
}

pattern 定义了一个正则,用于捕获终端的输出

uriFormat属性描述如何将端口号转换为URI,The first %s is substituted by the first capture group of the matching pattern.

Alternatively, the action can be set to debugWithEdge or debugWithChrome. In this mode, a webRoot property can be added that is passed to the Chrome or Edge debug session.

Triggering an Arbitrary Launch Config

In some cases, you may need to configure additional options for the browser debug session--or use a different debugger entirely. You can do this by setting action to startDebugging with a name property set to the name of the launch configuration to start when the pattern is matched.

The named launch configuration must be in the same file or folder as the one with the serverReadyAction.

作者:bigsharker

出处:https://www.cnblogs.com/bigsharker/p/18198547

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   big_shark  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
more_horiz
keyboard_arrow_up light_mode palette
选择主题
点击右上角即可分享
微信分享提示