gcc -g3 -fsanitize=address 파일명(ex. *.c)
-g 옵션 : 디버깅 실행파일 생성 옵션? 3을 붙이는 이유는 정보가 더 많이 나와서
-fsanitize=address : 자동완성 되니 일부 문자만 입력후 tab
./a.out 실행시 보이는 코드
#5 → #0 까지 순차적으로 확인하며 어느 부분에서 오류가 나는지 확인!!
Debug C/C++ File 오른쪽 상단 번호 클릭
launch | 실행 전에 Debugger 모드에서 App, Process에서 앱을 시작하는 방법 |
---|---|
attach | 이미 실행중인 App, Process에 연결하는 방법 |
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
// 실행하게 되는 명령어
"command": "/usr/bin/gcc",
// 명령어 인자
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
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": "(lldb) Launch",
//
"type": "cppdbg",
"request": "launch",
// launch 하는 대상 프로그램
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
RUN AND DEBUG tab 클릭 → (lldb) Launch 실행 (왼쪽 상단)
‼️ 실행이 되지 않을때 -g3 옵션을 사용해서 컴파일을 해놓기!
break 포인트 선택후 디버깅 실행