• vscode c++ 编译生成后,调试时无法命中断点


     1 //test.cpp
     2 #include <stdio.h>
     3 int g_var = 0;
     4 void print_line(char *str)
     5 {
     6     if (str != NULL)
     7         printf("%s
    ", str);
     8     else
     9         printf("null string
    ");
    10 }
    11 int main (int argc, char **argv)
    12 {
    13     int l_var = 1;
    14     print_line("hello world!");
    15     printf("g_var = %d, l_var = %d.
    ", g_var, l_var);
    16     return 0;
    17 }
    View Code

    launch.json

     1 {
     2         "version": "0.2.0",
     3         "configurations": [
     4             {
     5                 "name": "(gdb) Launch",
     6                 "type": "cppdbg",
     7                 "request": "launch",
     8                 "program": "${workspaceRoot}/test.exe",
     9                 "args": [],
    10                 "stopAtEntry": false,
    11                 "cwd": "${workspaceRoot}",
    12                 "environment": [],
    13                 "externalConsole": true,
    14                 "MIMode": "gdb",
    15                 "miDebuggerPath": "C:\MinGW\bin\gdb.exe",
    16                 "setupCommands": [
    17                     {
    18                         "description": "Enable pretty-printing for gdb",
    19                         "text": "-enable-pretty-printing",
    20                         "ignoreFailures": true
    21                     }
    22                 ]
    23             }
    24         ]
    25     }
    View Code

    tasks.json

     1 {
     2     // See https://go.microsoft.com/fwlink/?LinkId=733558
     3     // for the documentation about the tasks.json format
     4     "version": "2.0.0",
     5     "tasks": [
     6         {
     7             "taskName": "test",
     8             "type": "shell",
     9             "command": "g++",
    10             "args": ["-g", "${file}", "-o", "${workspaceRoot}/test.exe"]
    11         }
    12     ]
    13 }
    View Code

    编译成功后,在源码中设置断点,却无法命中断点。

    后来查看官方c++编译调试文档和尝试,在launch.json文件的

    "setupCommands": [
    {
    "description": "Enable pretty-printing for gdb",
    "text": "-enable-pretty-printing",
    "ignoreFailures": true
    }
    ]

    后面加上

    "preLaunchTask": "test" 配置,调试时就可以正常命中断点了。
    注意:别忘了"setupCommands"的中括号’ ] ‘后面加上一个逗号。
     
     
  • 相关阅读:
    实现响应式——Bootstrap的删格系统详解
    javascript-OOP基础详解
    简单又炫酷的two.js 二维动画教程
    AngularJS [ 快速入门教程 ]
    Js函数初学者练习(一)switch-case结构实现计算器。
    通过JS检测客户端是否禁用Cookie
    JavaScript数组去重多种方法
    前端页面灰白
    VUE 移动端只获取当前拍摄照片,不允许相册获取 及 input标签capture属性详解
    VUE 超好看气泡进度条组件
  • 原文地址:https://www.cnblogs.com/lisuyun/p/7604571.html
Copyright © 2020-2023  润新知