简体   繁体   中英

Can not debug in VSCode with gdb

I was using vscode and gdb(mingw) for my cpp debugging on Windows. But one day it doesnot work, till now.

My previous workflow is : coding -> set breakpoint -> build -> start debug -> debug step by step, but now when I start debug, it stucks.

After I click Debug->start debug, the preLaunchTask is triggered normally. A .exe file is generated and it work appropriately if run from outside the vscode. Then the launch procedure begin and a terminal is open, a float bar on the top shows and a command is running in the terminal.

But the project doesnot run and not block at my breakpoint and of course donot give my output. What I got is a termainal with a command that never output anything and never receive any input except ctrl-c,

ying@DESKTOP-5GV0Q9R MINGW64 /d/project/leetcode (master)$ 
env c:\\Users\\ying\\.vscode\\extensions\\ms-vscode.cpptools-0.23.1\\debugAdapters\\bin\\WindowsDebugLauncher.exe 
--stdin=Microsoft-MIEngine-In-hm3amha1.us3 
--stdout=Microsoft-MIEngine-Out-vlas2vht.meb 
--stderr=Mi crosoft-MIEngine-Error-c1e3oyr5.kel 
--pid=Microsoft-MIEngine-Pid-ij4mrymv.zxl 
--dbgExe=C:\\mingw-w64\\x86_64\\mingw64\\bin\\gdb.exe 
--interpreter=mi


a float bar with three gray buttons, and something fly from left to right forever,

When I try to use ctrl-c to stop the program, VSCode gives a warning like this:

Undefined command "". Try "help".

I think maybe the .exe is not passed to gdb, but dont know how to know what really happened.

I am using:

  • windows10 1903 18362.145
  • vscode 1.35.0 (update today but it happens weeks before)
  • gdb8.1 (mingw-w64 x86_64-posix-seh-rev0)

Here is my launch.json. Most copy from https://code.visualstudio.com/docs/cpp/config-mingw#_configure-debug-settings

"configurations": [
    {
      "name": "g++.exe build and debug active file",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "miDebuggerPath": "C:\\mingw-w64\\x86_64\\mingw64\\bin\\gdb.exe",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ],
      "preLaunchTask": "g++.exe build active file"
    }
  ]

Trying to convert externalConsole from false to true don't solve this and the console do not show as I wish. I am using a default helloworld.cpp and a breakpoint in the cout line. It cannot be the code's fault. But for all my code, the debugging behaves the same.

Please give me the reason and/or the solution of my case, or where I can find it by myself. Any help will be appreciated.

I had exactly the same problem as you, the same output and the same performance. I happened to type 'help' in that console and the output was garbled character. So I realized that there was something wrong with my system encoding since I just changed some settings on it before. Now vscode debug is working for me after I readjusted those settings.

It seems you are Chinese according to your ID, so I guess you can read the image below. I can translate it for you if you ask, anyway. setting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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