Study: DeveloperTools(DevTool)/DevTool: IDE

[IDE] VSCode C++ ๋””๋ฒ„๊น… ํ™˜๊ฒฝ ์„ธํŒ…(task.json, launch.json): GCC on Linux (feat. ๋ชจ๋“  ์ค‘๋‹จ์ ์—์„œ ๋ฉˆ์ถ”๋„๋ก)

DrawingProcess 2022. 7. 8. 09:43
๋ฐ˜์‘ํ˜•
๐Ÿ’ก ๋ณธ ๋ฌธ์„œ๋Š” Visual Studio Code๋ฅผ ํ™œ์šฉํ•œ C++ ๋””๋ฒ„๊น… ํ™˜๊ฒฝ ์„ธํŒ… ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์†Œ๊ฐœํ•ฉ๋‹ˆ๋‹ค.
์šด์˜์ฒด์ œ ๋ณ„๋กœ ์ง€์›๋˜๋Š” ์ปดํŒŒ์ผ๋Ÿฌ์— ์ฐจ์ด๊ฐ€ ์žˆ์–ด ์šด์˜์ฒด์ œ๋ณ„๋กœ ์ผ๋ถ€ ์ƒ์ดํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ ๋ณธ์ธ์˜ ์šด์˜์ฒด์ œ๋ฅผ ํ™•์ธํ•˜๊ณ  ๊ทธ์— ๋งž์ถฐ์„œ ์ง„ํ–‰ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

๋ฏธ๋ฆฌ ์•Œ์•„์•ผ ํ•  ์  (์ฃผ์˜์‚ฌํ•ญ)

VSCode์—์„œ ๋””๋ฒ„๊น…์‹œ ํ”„๋กœ์ ํŠธ์˜ ์ƒ์œ„์— ์žˆ๋Š” .vscode/ํด๋” ๋‚ด์— task.json๊ณผ launch.json์„ ์•„๋ž˜์™€ ์œ ์‚ฌํ•˜๊ฒŒ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. VScode์˜ ๋””๋ฒ„๊น…์„ ์‹คํ–‰ํ•˜๋ฉด launch.json์ด ์‹คํ–‰๋˜๋Š”๋ฐ, ์ด๋•Œ preLaunchTask ๋ผ๋ฒจ์ด ์žˆ๋‹ค๋ฉด task.json์—์„œ label์ด ๋™์ผํ•œ ๊ฒƒ์„ ์ฐพ๊ณ  task.json ์ž‘์—…์„ ์‹คํ–‰ํ•œ ํ›„ launch.json์ด ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ task.json์˜ "label"๊ณผ launch.json์˜ "preLaunchTask"๋Š” ๋™์ผํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

ํ•˜๋‹จ์—์„œ json ํŒŒ์ผ์— ๋Œ€ํ•œ ์„ค๋ช…์„ ํ•ด์ค„ ์˜ˆ์ •์ด๋‹ˆ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

VSCode C++ ๋””๋ฒ„๊น… ํ™˜๊ฒฝ ์„ธํŒ…

1. task.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "rm exist build file",
            "command": "rm",
            "args": [
                "-f",
                "${workspaceFolder}/Debug/${fileBasenameNoExtension}"
            ],
            "options": {
            	"cwd": "${workspaceFolder}"
            }
        },
        {
            "type": "shell",
            "label": "clang++ build active file",
            
            // ๊ธฐ์กด์˜ ๋นŒ๋“œ ํŒŒ์ผ ์ง€์šฐ๊ธฐ
            "dependsOn": [
                "rm exist build file"
            ],
            "dependsOrder": "sequence",

            // "windows" for Windows, "linux" for Linux, and "osx" for macOS.
            "linux":{
                "command": "/usr/bin/g++",
                "args": [
                    "-g",
                    "${file}",
                    "-o",
                    "Debug/${fileBasenameNoExtension}"
                    // "${fileDirname}/${fileBasenameNoExtension}"
                ],
            },
            "osx":{
                "command": "/usr/bin/clang++",
                "args": [
                    "-std=c++17",
                    "-stdlib=libc++",
                    "-g",
                    "${file}",
                    "-o",
                    "Debug/${fileBasenameNoExtension}"
                ],
            },
            "options": {
            	"cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

2. launch.json

{
  // IntelliSense๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ€๋Šฅํ•œ ํŠน์„ฑ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์„ธ์š”.
  // ๊ธฐ์กด ํŠน์„ฑ์— ๋Œ€ํ•œ ์„ค๋ช…์„ ๋ณด๋ ค๋ฉด ๊ฐ€๋ฆฌํ‚ต๋‹ˆ๋‹ค.
  // ์ž์„ธํ•œ ๋‚ด์šฉ์„ ๋ณด๋ ค๋ฉด https://go.microsoft.com/fwlink/?linkid=830387์„(๋ฅผ) ๋ฐฉ๋ฌธํ•˜์„ธ์š”.
  "version": "0.2.0",
  "configurations": [
      {
          "preLaunchTask": "clang++ build active file",
          "request": "launch",
          "name": "Build and debug active file",
          "type": "cppdbg",
          
          // "windows" for Windows, "linux" for Linux, and "osx" for macOS.
          "linux": {
            "MIMode": "gdb",
            "miDebuggerPath": "/bin/gdb"
          },
          "osx": {
            "MIMode": "lldb"
          },
          
          "cwd": "${workspaceFolder}",
          "program": "${workspaceFolder}/Debug/${fileBasenameNoExtension}",
          "args": [ 
              // "--gtest_filter=store.*" 
          ],
          "stopAtEntry": false,
          "environment": [],
          "externalConsole": false,
          "setupCommands": [
              {
                  "description": "gdb์— ์ž๋™ ์„œ์‹ ์ง€์ • ์‚ฌ์šฉ",
                  "text": "-enable-pretty-printing",
                  "ignoreFailures": true
              }
          ]
      }
  ]
}
  • "type": cppdbg๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
  • "program": ๋””๋ฒ„๊น…ํ•  ์‹คํ–‰ํŒŒ์ผ์˜ ์ ˆ๋Œ€๊ฒฝ๋กœ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
  • "args": ๋””๋ฒ„๊น…ํ•  ์‹œ ์˜ต์…˜์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ํ˜„์žฌ googletest ์ค‘ store๋งŒ ์‹คํ–‰ํ•˜๊ณ ์ž ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

+ VScode: ๋ชจ๋“  ์ค‘๋‹จ์ ์—์„œ ๋ฉˆ์ถ”๋„๋ก ์„ค์ •

  1. ์„ค์ •: ์ƒ๋‹จ๋ฐ” -> ๊ธฐ๋ณธ์„ค์ • -> ์„ค์ •(command + ,)
  2. ๋ชจ๋“  ์ค‘๋‹จ์ ์—์„œ ๋ฉˆ์ถ”๊ธฐ: breakpoint ๊ฒ€์ƒ‰ ํ›„ 'Debug: Allow Breakpoints Everywhere' ์ฒดํฌ

 

๋ฐ˜์‘ํ˜•