VSCodeでc言語ファイルのデバッグができません
Q&A
Closed
解決したいこと
VSCodeでのc言語ファイルのデバッグ時の不具合
windows10、VSCodeにてc言語ファイルをgdb?cppdbg?にてデバッグする際、コマンドプロンプトが一度は開くのですが、
コマンドプロンプトに何も表示されず、すぐにコマンドプロンプトが消えてしまいます。
(printf("Hello\n")等で文字列を出力しようとしており、ブレークポイントも設定しております。)
fopenで新規にファイルを作成する等はできるのですが、こちらもコマンドプロンプトがすぐに消えます。
デバッグ時にコマンドプロンプトが消えないように設定したいのですが、どのようにすればよろしいでしょうか?
また、原因はなんでしょうか?
発生している問題・エラー
デバッグを実行すると、VSCode上のコンソールにはエラーは表示されず、デバッグコンソールに以下のような文言が残されます。
=thread-group-added,id="i1"
GNU gdb (GDB) 9.2
Copyright (C) 2020 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-pc-msys".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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 12244.0x3910]
Thread 1 hit Breakpoint 1, 0x000000000040155d in main ()
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/msvcrt.dll'. Symbols loaded.
Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)
該当するソースコード
ファイル構成
C5 (フォルダ)
|-- test.c (ファイル)
|-- test.exe (ファイル)
|-- .vscode (フォルダ)
|-- c_cpp_properties.json (ファイル)
|-- launch.json (ファイル)
|-- tasks.json (ファイル)
↓↓↓ ここからtest.c ↓↓↓
#include <stdio.h>
int main(void)
{
printf("hello");
return 0;
}
↑↑↑ ここまでtest.c ↑↑↑
↓↓↓ ここからc_cpp_properties.json ↓↓↓
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/MinGW/include/",
"C:/Users/「user」/forVSCode/c5",
"C:/msys64/mingw64/x86_64-w64-mingw32/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/mingw/bin/gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x86"
}
],
"version": 4
}
↑↑↑ ここまでc_cpp_properties.json ↑↑↑
↓↓↓ ここからtasks.json ↓↓↓
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "gcc ${file} -o ${fileBasenameNoExtension}.exe",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
↑↑↑ ここまでtasks.json ↑↑↑
↓↓↓ ここからlaunch.json ↓↓↓
{
// IntelliSense を使用して利用可能な属性を学べます。
// 既存の属性の説明をホバーして表示します。
// 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gdb debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/msys64/usr/bin/gdb.exe",
"setupCommands": [
{
"description": "gcc",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"sourceFileMap": {
"/c/": "C:/"
}
}
]
}
↑↑↑ ここまでlaunch.json ↑↑↑
自分で試したこと
fopenでファイルを新規に作成 → ファイルは作成されるが、コマンドプロンプトがすぐに消える
あとはいろいろ試した結果が上記の設定ファイル(c_cpp_properties.json, tasks.json, launch.json)の状態ですので、具体的に何をしたかは覚えてないです・・・。
また、私情により長期間返信することが難しい可能性が高いです。
質問しておきながら大変恐縮ですが、ご容赦ください。
0 likes