VSCode에서 c 언어 디버깅 _Remote-WSL 사용
환경 구축
아래의 링크에 따라 Remote-WSL 환경에서 C 언어 프로그램이 가능할 때까지의 환경 구축을 실시합니다.
Visual Studio Code로 경쟁 프로 환경 구축 (도입편)
VSCode 설치, WSL, Remote-WSL 배포, WSL에 컴파일러 디버깅 설치
VSCode에서의 경쟁 프로용 C++ 환경을 WSL에 Remote Development하는 형태로 만든다
C++ 확장 기능을 WSL에 설치
C 언어용 디버그 설정
launch.json과 tasks.json 만들기
폴더, 소스를 준비합니다.
.vscode가 작성되지 않은 상태입니다.
![](https://s1.md5.ltd/image/6dbebaf05b1e1ca03ec4157666d61019.png)
F5를 누른 후 C++(GDB/LLDB)를 클릭합니다.
![](https://s1.md5.ltd/image/e085e7f6618e5b3e475e77c3669880e3.png)
gcc-~를 클릭합니다.
![](https://s1.md5.ltd/image/1b8c9808e81d69d6be0812e1b5464d31.png)
.vscode가 생성되고 그 안에 launch.json과 task.json의 두 파일이 생성됩니다.
![](https://s1.md5.ltd/image/dd95a9253464d10e48c9d7e8a10ea45c.png)
launch.json 및 tasks.json의 내용 (실행 형식 파일 이름 : 소스 이름 확장자를 제외한 이름)
소스 이름이 main.c이면 실행 형식 파일의 이름은 main입니다.
launch.json 및 tasks.json은 자동으로 생성된 파일에서 변경할 필요가 없습니다.
launch.json{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
launch.json과 tasks.json의 내용 (실행 형식 파일 이름 : a.out)
launch.json 수정 후 (program 만 수정){
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
최적화를 끄고 컴파일이 빨라지도록 -O0 옵션을 붙이고 있습니다.
tasks.json 수정 후 (args 만 수정){
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"-O0",
"${file}",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
디버깅
브레이크 포인트를 설정하고 F5, F11, F10을 누르면 디버깅이 가능합니다.
다음은 디버깅 중에 발생한 문제에 대해 설명합니다.
scanf 행에서 디버그 중지하고 있을 때 스텝 인을 하면 에러가 발생
아래 상태에서 스텝 인 (F11 누르기)
![](https://s1.md5.ltd/image/718c98485261e1a00ac6c9304721be30.png)
아래에 오류가 발생합니다.
![](https://s1.md5.ltd/image/2e34b1246f2804302883a44742afce33.png)
스텝 인이 아니라 스텝 오버 (F10 누름)하면 에러가 발생하지 않습니다.
Reference
이 문제에 관하여(VSCode에서 c 언어 디버깅 _Remote-WSL 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kunuthSensei/items/9a98c193f512b68b9031
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
launch.json과 tasks.json 만들기
폴더, 소스를 준비합니다.
.vscode가 작성되지 않은 상태입니다.
![](https://s1.md5.ltd/image/6dbebaf05b1e1ca03ec4157666d61019.png)
F5를 누른 후 C++(GDB/LLDB)를 클릭합니다.
![](https://s1.md5.ltd/image/e085e7f6618e5b3e475e77c3669880e3.png)
gcc-~를 클릭합니다.
![](https://s1.md5.ltd/image/1b8c9808e81d69d6be0812e1b5464d31.png)
.vscode가 생성되고 그 안에 launch.json과 task.json의 두 파일이 생성됩니다.
![](https://s1.md5.ltd/image/dd95a9253464d10e48c9d7e8a10ea45c.png)
launch.json 및 tasks.json의 내용 (실행 형식 파일 이름 : 소스 이름 확장자를 제외한 이름)
소스 이름이 main.c이면 실행 형식 파일의 이름은 main입니다.
launch.json 및 tasks.json은 자동으로 생성된 파일에서 변경할 필요가 없습니다.
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
launch.json과 tasks.json의 내용 (실행 형식 파일 이름 : a.out)
launch.json 수정 후 (program 만 수정)
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
최적화를 끄고 컴파일이 빨라지도록 -O0 옵션을 붙이고 있습니다.
tasks.json 수정 후 (args 만 수정)
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"-O0",
"${file}",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
디버깅
브레이크 포인트를 설정하고 F5, F11, F10을 누르면 디버깅이 가능합니다.
다음은 디버깅 중에 발생한 문제에 대해 설명합니다.
scanf 행에서 디버그 중지하고 있을 때 스텝 인을 하면 에러가 발생
아래 상태에서 스텝 인 (F11 누르기)
![](https://s1.md5.ltd/image/718c98485261e1a00ac6c9304721be30.png)
아래에 오류가 발생합니다.
![](https://s1.md5.ltd/image/2e34b1246f2804302883a44742afce33.png)
스텝 인이 아니라 스텝 오버 (F10 누름)하면 에러가 발생하지 않습니다.
Reference
이 문제에 관하여(VSCode에서 c 언어 디버깅 _Remote-WSL 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kunuthSensei/items/9a98c193f512b68b9031
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(VSCode에서 c 언어 디버깅 _Remote-WSL 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kunuthSensei/items/9a98c193f512b68b9031텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)