Search
🌍

bb2.1___1. title: VSCode is just a kind of visualizer. When you want to debug C program with vscode, you should make a debuggable execution file with your own build system yourself, and let vscode know the execution file.

생성
🚀 prev note
🚀 next note
♻️ next note
14 more properties
VSCode is just a kind of visualizer. When you want to debug C program(from3) with vscode, you should make a debuggable execution file with your own build system yourself(참고2:using g flag), and let vscode know the execution file.
. ├── Makefile ├── other.c ├── other.h ├── main.c └── main.o
Plain Text
복사
directory structure
Let’s see and end-to-end example. First, create a Makefile to make a debuggable & executable output file.
Code(from1)
CC = gcc CFLAGS = -g main: main.o other.o $(CC) ${CFLAGS} -o main main.o other.o main.o: main.c main.h $(CC) ${CFLAGS} -c main.c other.o: other.c other.h $(CC) ${CFLAGS} -c other.c clean: rm -f main main.o other.o
Makefile
복사
Makefile
The debuggable output file name is main in this example. Next, select main file (”program”: ${workspaceFolder}/main) to start debugging when you click the debug button in the VSCode. I’m using macbook, so my debugger backend is lldb.
CFLAGS = -g
Makefile
복사
Note that the debuggable file had to be built with the -g compiler flag(참고2). That’s all you need.
{ "version": "0.2.0", "configurations": [ { "type": "lldb", "request": "launch", "name": "My debug", "program": "${workspaceFolder}/main", "args": [], "cwd": "${workspaceFolder}", } ] }
Makefile
복사
.vscode/launch.json
Change your debugger to proper type (lldb or something).
For your convenience, it’s common to make a tasks.json file. It can be just working as a shortcut instead of typing a boring same command in your terminal. The task is just typing a shell command to run the Makefile. The name of the task is "run make using Makefile" as you can see below.
{ "version": "2.0.0", "tasks": [ { "label": "run make using Makefile", "type": "shell", "command": "make", } ] }
Makefile
복사
.vscode/tasks.json
You can link the task on the debug button as below. It means when you click the debug button, the make task will be start automatically so you can run debugging mode with a up-to-dated code.
{ "version": "0.2.0", "configurations": [ { "type": "lldb", "request": "launch", "name": "My debug", "program": "${workspaceFolder}/main", "args": [], "cwd": "${workspaceFolder}", "preLaunchTask": "run make using Makefile", } ] }
Makefile
복사
.vscode/launch.json
. ├── .vscode │ ├── launch.json │ └── tasks.json ├── Makefile ├── other.c ├── other.h ├── main.c └── main.o
YAML
복사
final directory structure
parse me : 언젠가 이 글에 쓰이면 좋을 것 같은 재료들.
1.
None
from : 과거의 어떤 생각이 이 생각을 만들었는가?
3.
supplementary : 어떤 새로운 생각이 이 문서에 작성된 생각을 뒷받침하는가?
1.
None
opposite : 어떤 새로운 생각이 이 문서에 작성된 생각과 대조되는가?
1.
None
to : 이 문서에 작성된 생각이 어떤 생각으로 발전되고 이어지는가?
1.
None
참고 : 레퍼런스