segmentation 포인트 확인

gcc -g3 -fsanitize=address 파일명(ex. *.c)

-g 옵션 : 디버깅 실행파일 생성 옵션? 3을 붙이는 이유는 정보가 더 많이 나와서
-fsanitize=address : 자동완성 되니 일부 문자만 입력후 tab

./a.out 실행시 보이는 코드

./a.out 실행시 보이는 코드

#5 → #0 까지 순차적으로 확인하며 어느 부분에서 오류가 나는지 확인!!

변수값 확인하며 하나씩 실행하는 법 (vscode)

  1. Debug C/C++ File 오른쪽 상단 번호 클릭

    launch 실행 전에 Debugger 모드에서 App, Process에서 앱을 시작하는 방법
    attach 이미 실행중인 App, Process에 연결하는 방법
    {
        "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"
    }
    
    {
    	// 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"
    		}
    
    	]
    }
    

    [C] vscode debugger 사용하기!

  2. RUN AND DEBUG tab 클릭 → (lldb) Launch 실행 (왼쪽 상단)

    ‼️ 실행이 되지 않을때 -g3 옵션을 사용해서 컴파일을 해놓기!

  3. break 포인트 선택후 디버깅 실행

    Screen Shot 2023-02-24 at 1.46.52 PM.png