microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.45k stars 1.53k forks source link

GDB hangs when pasting into the terminal before a `scanf` call #10834

Open palapapa opened 1 year ago

palapapa commented 1 year ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: When using the GDB from MinGW-W64 and debugging a program, if I paste some input into the terminal before the control flow reaches a scanf call, the debugger hangs after the scanf call as if it's stuck in an infinite loop.

Steps to reproduce:

  1. Download GCC 12.2.0 + LLVM/Clang/LLD/LLDB 16.0.0 + MinGW-w64 10.0.0 (UCRT) - release 5 for Win64 from winlibs.com.
  2. Debug this program
    
    #include <stdio.h>

int main(void) { size_t height = 0, width = 0; scanf("%zu %zu", &height, &width); int maze[height][width]; }

with the play button and select the compiler you just downloaded, with a breakpoint at line 6(at the `scanf`). No `launch.json` or `task.json` required.

3. When the execution stops at line 6, paste this line into the terminal:

1 1

4. Press step over and observe that the debugger just hangs.

### Debugger Configurations

```shell
None

Debugger Logs

=thread-group-added,id="i1"
GNU gdb (GDB for MinGW-W64 x86_64, built by Brecht Sanders) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
[New Thread 14560.0x49dc]

Thread 1 hit Breakpoint 1, 0x00007ff6fdaf17ea in main () at D:\Desktop\C\College\Portal\Portal1.c:4
4   {
Loaded 'C:\WINDOWS\SYSTEM32\ntdll.dll'. Symbols loaded.
Loaded 'C:\WINDOWS\System32\kernel32.dll'. Symbols loaded.
Loaded 'C:\WINDOWS\System32\KernelBase.dll'. Symbols loaded.
Loaded 'C:\WINDOWS\System32\ucrtbase.dll'. Symbols loaded.

Thread 1 hit Breakpoint 2, main () at D:\Desktop\C\College\Portal\Portal1.c:6
6       scanf("%zu %zu", &height, &width);
Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)

Other Extensions

No response

Additional Information

This problem doesn't occur if I use the GDB that came with TDM-GCC 10.3.0. settings.json:

{
  "editor.formatOnPaste": false,
  "editor.formatOnSave": false,
  "editor.formatOnType": false,
  "editor.cursorSmoothCaretAnimation": "on",
  "editor.fontFamily": "Monocraft",
  "editor.fontSize": 15,
  "editor.fontLigatures": true,
  "files.autoSave": "afterDelay",
  "files.autoSaveDelay": 0,
  "terminal.integrated.fontFamily": "Monocraft",
  "terminal.integrated.fontSize": 11,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.suggestSelection": "first",
  "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
  "python.languageServer": "Pylance",
  "python.linting.enabled": true,
  "workbench.statusBar.visible": true,
  "editor.smoothScrolling": true,
  "editor.cursorBlinking": "smooth",
  "security.workspace.trust.untrustedFiles": "open",
  "workbench.editor.untitled.hint": "hidden",
  "files.autoGuessEncoding": true,
  "python.analysis.typeCheckingMode": "strict",
  "powermode.enabled": false,
  "redhat.telemetry.enabled": true,
  "diffEditor.ignoreTrimWhitespace": false,
  "editor.inlineSuggest.enabled": true,
  "security.workspace.trust.startupPrompt": "always",
  "security.workspace.trust.banner": "always",
  "security.workspace.trust.enabled": false,
  "workbench.iconTheme": "material-icon-theme",
  "files.associations": {
    "*.txt": "log"
  },
  "json.maxItemsComputed": 32648,
  "[cpp]": {
    "editor.defaultFormatter": "ms-vscode.cpptools"
  },
  "editor.renderWhitespace": "none",
  "editor.bracketPairColorization.enabled": false,
  "code-runner.executorMap": {
    "c": "cd $dir && gcc \"$fileName\" -o (\"$fileNameWithoutExt\" + \".exe\") -std=c17 -Wall -Wextra -pedantic -O2 && & (\"$dir$fileNameWithoutExt\" + \".exe\")",
    "cpp": "cd $dir && g++ \"$fileName\" -o (\"$fileNameWithoutExt\" + \".exe\") -std=c++17 -Wall -Wextra -pedantic -O2 && & (\"$dir$fileNameWithoutExt\" + \".exe\")"
  },
  "code-runner.executorMapByFileExtension": {
    ".m": "cd $dir && matlab -batch \"$fileNameWithoutExt\""
  },
  "code-runner.runInTerminal": true,
  "code-runner.clearPreviousOutput": false,
  "code-runner.preserveFocus": false,
  "terminal.integrated.enableMultiLinePasteWarning": false,
  "[c]": {
    "editor.defaultFormatter": "ms-vscode.cpptools"
  },
  "terminal.integrated.cursorStyle": "line",
  "terminal.integrated.cursorBlinking": true,
  "[matlab]": {
    "editor.defaultFormatter": "AffenWiesel.matlab-formatter"
  },
  "matlab.lintOnSave": true,
  "matlab.mlintpath": "D:\\MATLAB\\bin\\win64\\mlint.exe",
  "explorer.confirmDelete": false,
  "C_Cpp.default.cStandard": "c17",
  "C_Cpp.default.cppStandard": "c++20",
  "C_Cpp.errorSquiggles": "disabled",
  "C_Cpp.default.compilerArgs": [
    "-Wall",
    "-Wextra",
    "-pedantic"
  ],
  "C_Cpp.loggingLevel": "Debug",
  "debug.onTaskErrors": "showErrors",
  "clangd.path": "c:\\Users\\User\\AppData\\Roaming\\Code\\User\\globalStorage\\llvm-vs-code-extensions.vscode-clangd\\install\\15.0.3\\clangd_15.0.3\\bin\\clangd.exe",
  "C_Cpp.intelliSenseEngine": "default",
  "C_Cpp.autocomplete": "disabled",
  "editor.inlayHints.enabled": "off",
  "workbench.colorTheme": "Dracula",
  "doxdocgen.generic.commandSuggestion": true,
  "doxdocgen.c.triggerSequence": "///",
  "doxdocgen.generic.commandSuggestionAddPrefix": true,
  "clangd.detectExtensionConflicts": false,
  "clangd.fallbackFlags": [
    "-Weverything",
    "-Wno-used-but-marked-unused",
    "-Wno-declaration-after-statement",
    "-Wno-vla",
    "-Wno-missing-prototypes",
    "-Wno-c++98-compat",
    "-IC:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/include",
    "-IC:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../include",
    "-IC:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/include-fixed",
    "-IC:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/include",
    "-nostdinc",
    "-target",
    "x86_64-pc-windows-gnu"
  ],
  "clangd.arguments": ["--log=verbose"],
  "editor.acceptSuggestionOnEnter": "off",
  "[python]": {
    "editor.defaultFormatter": "ms-python.python"
  },
  "editor.largeFileOptimizations": false,
  "terminal.integrated.scrollback": 32768,
  "editor.tokenColorCustomizations": { // Disables italics
    "textMateRules": [
      {
        "scope": [
          "comment",
          "comment.block",
          "comment.block.documentation",
          "comment.line",
          "constant",
          "constant.character",
          "constant.character.escape",
          "constant.numeric",
          "constant.numeric.integer",
          "constant.numeric.float",
          "constant.numeric.hex",
          "constant.numeric.octal",
          "constant.other",
          "constant.regexp",
          "constant.rgb-value",
          "emphasis",
          "entity",
          "entity.name",
          "entity.name.class",
          "entity.name.function",
          "entity.name.method",
          "entity.name.section",
          "entity.name.selector",
          "entity.name.tag",
          "entity.name.type",
          "entity.other",
          "entity.other.attribute-name",
          "entity.other.inherited-class",
          "invalid",
          "invalid.deprecated",
          "invalid.illegal",
          "keyword",
          "keyword.control",
          "keyword.operator",
          "keyword.operator.new",
          "keyword.operator.assignment",
          "keyword.operator.arithmetic",
          "keyword.operator.logical",
          "keyword.other",
          "markup",
          "markup.bold",
          "markup.changed",
          "markup.deleted",
          "markup.heading",
          "markup.inline.raw",
          "markup.inserted",
          "markup.italic",
          "markup.list",
          "markup.list.numbered",
          "markup.list.unnumbered",
          "markup.other",
          "markup.quote",
          "markup.raw",
          "markup.underline",
          "markup.underline.link",
          "meta",
          "meta.block",
          "meta.cast",
          "meta.class",
          "meta.function",
          "meta.function-call",
          "meta.preprocessor",
          "meta.return-type",
          "meta.selector",
          "meta.tag",
          "meta.type.annotation",
          "meta.type",
          "punctuation.definition.string.begin",
          "punctuation.definition.string.end",
          "punctuation.separator",
          "punctuation.separator.continuation",
          "punctuation.terminator",
          "storage",
          "storage.modifier",
          "storage.type",
          "string",
          "string.interpolated",
          "string.other",
          "string.quoted",
          "string.quoted.double",
          "string.quoted.other",
          "string.quoted.single",
          "string.quoted.triple",
          "string.regexp",
          "string.unquoted",
          "strong",
          "support",
          "support.class",
          "support.constant",
          "support.function",
          "support.other",
          "support.type",
          "support.type.property-name",
          "support.variable",
          "variable",
          "variable.language",
          "variable.name",
          "variable.other",
          "variable.other.readwrite",
          "variable.parameter"
        ],
        "settings": {
          "fontStyle": ""
        }
      }
    ]
  },
  "settingsSync.ignoredSettings": [
    "editor.fontSize"
  ],
  "files.maxMemoryForLargeFilesMB": 16384,
  "editor.suggest.snippetsPreventQuickSuggestions": false,
  "[latex]": {
    "editor.defaultFormatter": "James-Yu.latex-workshop"
  },
  "latex-workshop.latex.recipes": [
    {
      "name": "latexmk (xelatex)",
      "tools": [
        "cd",
        "xelatexmk"
      ]
    }
  ],
  "latex-workshop.latex.tools": [
    {
      "name": "xelatexmk",
      "command": "latexmk",
      "args": [
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "-xelatex",
        "-outdir=%OUTDIR%",
        "%DOC%"
      ],
      "env": {}
    },
    {
      "name": "cd",
      "command": "cd",
      "args": [
        "%DIR%"
      ]
    }
  ],
  "latex-workshop.latex.recipe.default": "latexmk (xelatex)",
  "latex-workshop.message.error.show": false,
  "latex-workshop.message.warning.show": false,
  "latex-workshop.message.information.show": false,
  "editor.unicodeHighlight.allowedLocales": {
    "zh-hant": true
  },
  "workbench.startupEditor": "none",
  "cmake.configureOnOpen": false,
  "editor.minimap.enabled": false,
  "codesnap.showWindowControls": false,
  "codesnap.containerPadding": "0",
  "codesnap.transparentBackground": true,
  "codesnap.backgroundColor": "#FFFFFF",
  "codesnap.boxShadow": "none",
  "update.showReleaseNotes": false,
  "git.autofetch": true,
  "git.enableSmartCommit": true,
  "gitlens.views.commits.showBranchComparison": false,
  "gitlens.views.showRelativeDateMarkers": false,
  "git.confirmSync": false
}
Dru01 commented 1 year ago

I tracked down it down to the version of gdb 13.1, installing gcc 11.2 version which comes with gdb 11.1 version it works perfectly fine. There's some incompability between gdb 13.1 and vscode or c++ extension.