title: How to debug C++ with MSYS2 (MSYS64) gdb.exe on VSCode?
body: <p>I can't get the C++ (GDB) debugger to work.
  So far, I'd instaled the extensions:</p>
  
  <ul>
  <li><a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner" rel="nofollow noreferrer">Code Runner</a> </li>
  <li><a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools" rel="nofollow noreferrer">C/C++</a></li>
  <li><a href="https://marketplace.visualstudio.com/items?itemName=austin.code-gnu-global" rel="nofollow noreferrer">C++ Intellisense</a></li>
  </ul>
  
  <p>MSYS2 is already in Windows PATH, and I can call gdb.exe from PowerShell with:</p>
  
  <pre><code>Start("gdb.exe")
  </code></pre>
  
  <p>By the first time I tried, I got a message that the <strong>crtexe.c</strong> didn't exists. I choose the option to create it. The file path is on <code>C:\repo\mingw-w64-crt-git\src\mingw-w64\mingw-w64-crt\crt\crtexe.c</code> and I've copied its contents from this <a href="https://github.com/msys2-contrib/mingw-w64/blob/master/mingw-w64-crt/crt/crtexe.c" rel="nofollow noreferrer">source</a>.</p>
  
  <p>The programs is compiling fine. And, when pressing <kbd>F5</kbd>, the debugger jumps to <em>crtexe.c</em> and stops after few <kbd>F11</kbd> steps. I'm really stuck at this point and any help will be, indeed, more than appreciated !</p>
  
  <p>This is my <strong>c_cpp_properties.json</strong>:
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
      "configurations": [{
              "name": "Mac",
              "includePath": [
                  "/usr/include",
                  "/usr/local/include",
                  "${workspaceRoot}"
              ],
              "defines": [],
              "intelliSenseMode": "clang-x64",
              "browse": {
                  "path": [
                      "/usr/include",
                      "/usr/local/include",
                      "${workspaceRoot}"
                  ],
                  "limitSymbolsToIncludedHeaders": true,
                  "databaseFilename": ""
              }
          },
          {
              "name": "Linux",
              "includePath": [
                  "/usr/include",
                  "/usr/local/include",
                  "${workspaceRoot}"
              ],
              "defines": [],
              "intelliSenseMode": "clang-x64",
              "browse": {
                  "path": [
                      "/usr/include",
                      "/usr/local/include",
                      "${workspaceRoot}"
                  ],
                  "limitSymbolsToIncludedHeaders": true,
                  "databaseFilename": ""
              }
          },
          {
              "name": "Win32",
              "includePath": [
                  "C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include",
                  "C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include-fixed",
                  "C:/msys64/mingw64/include/c++/7.1.0/x86_64-w64-mingw32",
                  "C:/msys64/mingw64/x86_64-w64-mingw32/include",
                  "C:/msys64/mingw64/x86_64-w64-mingw32/include/wrl",
                  "C:/msys64/mingw64/include/c++/7.1.0/tr1",
                  "C:/msys64/mingw64/include/c++/7.1.0/backward",
                  "C:/msys64/mingw64/include/c++/7.1.0",
                  "C:/msys64/mingw64/include",
                  "${workspaceRoot}"
              ],
              "defines": [
                  "_DEBUG",
                  "UNICODE",
                  "__GNUC__=7.1.0",
                  "__cdecl=__attribute__((__cdecl__))"
              ],
              "intelliSenseMode": "clang-x64",
              "browse": {
                  "path": [
                      "C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include",
                      "C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include-fixed",
                      "C:/msys64/mingw64/include/c++/7.1.0/x86_64-w64-mingw32",
                      "C:/msys64/mingw64/x86_64-w64-mingw32/include",
                      "C:/msys64/mingw64/x86_64-w64-mingw32/include/wrl",
                      "C:/msys64/mingw64/include/c++/7.1.0/tr1",
                      "C:/msys64/mingw64/include/c++/7.1.0/backward",
                      "C:/msys64/mingw64/include/c++/7.1.0",
                      "C:/msys64/mingw64/include",
                      "${workspaceRoot}"
                  ],
                  "limitSymbolsToIncludedHeaders": true,
                  "databaseFilename": ""
              }
          }
      ],
      "version": 2
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>And, my <strong>launch.json</strong> is like that:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
      "version": "0.2.0",
      "configurations": [{
          "name": "(gdb) Launch",
          "type": "cppdbg",
          "request": "launch",
          "program": "${workspaceRoot}/main.exe",
          "args": [],
          "stopAtEntry": false,
          "cwd": "${workspaceRoot}",
          "environment": [],
          "externalConsole": true,
          "MIMode": "gdb",
          "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
          "setupCommands": [{
              "description": "Enable pretty-printing for gdb",
              "text": "-enable-pretty-printing",
              "ignoreFailures": true
          }]
      }]
  }</code></pre>
  </div>
  </div>
  </p>