아래와 같이 C 기반으로 테스트 프로그램 작성하여 진행 진행
#include <stdio.h>
int test0()
{
int test0=0;
printf("Hello World %d\n",test0);
return 0;
}
int test1()
{
int test1=3;
printf("Hello World %d\n",test1 );
return 0;
}
int test2()
{
printf("Hello World 2\n");
return 0;
}
static int world=2;
int main ()
{
test0();
test1();
test2();
printf("main World %d\n",world);
return 0;
}
VS Code에서 좌측아이콘의 Run and Debug 메뉴로 이동 후 lauch.json 부분 수정
.vscode/launch.json
1.1 OpenOCD 에 연결
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
.vscode/launch.json 관련문서
https://code.visualstudio.com/docs/cpp/launch-json-reference
https://code.visualstudio.com/docs/cpp/launch-json-reference
상위 program 항목: ELF or a.out 으로 심볼테이블 찾아야함
상위 설정 후 좌측 Run Debug 메뉴에서 손쉽게 디버깅 (이미 gdb와 관련부분 이미설치됨)
VS Code 의 Debugging 문서
세부사항은 아래 문서참조
https://code.visualstudio.com/docs/editor/debugging
https://code.visualstudio.com/docs/editor/debugging
만약 OpenOCD의 gdbserver에 연결하고자 한다면, 아래와 같이 Server Address 추가
Linux에서 build를 했다면, 내부에 gdbinit이 존재할 것이며, 아래와 같이 gdb 위치도 추가
"configurations": [
{
....
"miDebuggerServerAddress": "localhost:3333",
"miDebuggerPath": "gdb path ",
....
}
VS Code 기반으로 gdbserver debugging
https://medium.com/@spe_/debugging-c-c-programs-remotely-using-visual-studio-code-and-gdbserver-559d3434fb78
https://medium.com/@spe_/debugging-c-c-programs-remotely-using-visual-studio-code-and-gdbserver-559d3434fb78
1.2 VS Code의 Task 사용법
VS Code에서 Task를 이용하여 외부툴 연결
Task를 만들어서 VS Code에서 쉽게 Command를 만들어 Shell Script등을 연결하자.
VS Code의 Menu
Terminal-> Run Task 실행