Skip to content

Commit d79a8cb

Browse files
committed
Initial commit
1 parent fcf6233 commit d79a8cb

11 files changed

Lines changed: 207 additions & 0 deletions

File tree

.vscode/launch.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "(Remote) Debug main_app with Libraries",
6+
"type": "cppdbg",
7+
"request": "launch",
8+
"program": "/home/user/dev/build/a.out", // [서버] 실행 파일 경로
9+
"args": [],
10+
"stopAtEntry": false,
11+
"cwd": "/home/user/dev/build", // [서버] 실행 위치
12+
"environment": [
13+
{ "name": "LD_LIBRARY_PATH", "value": "/home/user/dev/build" }
14+
],
15+
"MIMode": "gdb",
16+
"pipeTransport": {
17+
"pipeCwd": "${workspaceFolder}",
18+
"pipeProgram": "ssh.exe",
19+
"pipeArgs": ["user@192.168.0.100"], // [서버] 접속 정보 수정 필요
20+
"debuggerPath": "/usr/bin/gdb" // [서버] gdb 위치
21+
},
22+
"sourceFileMap": {
23+
"/home/user/dev/apps/main_app": "${workspaceFolder}/apps/main_app",
24+
"/home/user/dev/libs/lib_b": "${workspaceFolder}/libs/lib_b",
25+
"/home/user/dev/libs/lib_d": "${workspaceFolder}/libs/lib_d"
26+
},
27+
"additionalSOLibSearchPath": "/home/user/dev/build",
28+
"setupCommands": [
29+
{ "text": "-enable-pretty-printing", "ignoreFailures": true },
30+
{ "text": "set solib-search-path /home/user/dev/build" }
31+
]
32+
}
33+
]
34+
}

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Root 디렉토리에 위치
2+
SUBDIRS = libs/lib_d libs/lib_b apps/main_app
3+
4+
all:
5+
@for dir in $(SUBDIRS); do \
6+
$(MAKE) -C $$dir; \
7+
done
8+
9+
clean:
10+
rm -rf build/*
11+
@for dir in $(SUBDIRS); do \
12+
$(MAKE) -C $$dir clean; \
13+
done
14+

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
# 🚀 vscode-airgapped-cpp-debug
3+
4+
본 프로젝트는 인터넷 연결이 불가능한 **에어갭(Air-gapped) 리눅스 환경**에서 별도의 에이전트(`vscode-server`)나 `gdbserver` 설치 없이, 오직 **SSH 파이프**만을 이용하여 윈도우 VS Code에서 원격 디버깅을 수행할 수 있도록 설계된 C/C++ 프로젝트 템플릿입니다.
5+
6+
## 🌟 주요 특징
7+
* **Zero-Agent**: 서버에 `curl`, `wget`을 통한 추가 바이너리 설치가 필요 없습니다.
8+
* **Air-gapped Ready**: 오직 SSH(22번 포트)와 SFTP만 사용하여 작동합니다.
9+
* **Complex Structure**: 실행 파일(`a.out`)과 다중 공유 라이브러리(`.so`) 간의 의존성 디버깅을 지원합니다.
10+
* **Step-Into Support**: 메인 로직에서 라이브러리 내부 함수로 진입하는 디버깅이 가능합니다.
11+
12+
---
13+
14+
## 📂 프로젝트 구조
15+
```text
16+
.
17+
├── .vscode/
18+
│ └── launch.json # 윈도우 VS Code용 원격 디버그 설정 (핵심)
19+
├── apps/
20+
│ └── main_app/ # 메인 실행 프로그램 (a.out)
21+
├── libs/
22+
│ ├── lib_b/ # 중간 공유 라이브러리 (libb.so)
23+
│ └── lib_d/ # 최하위 공유 라이브러리 (libd.so)
24+
├── Makefile # 프로젝트 전체 빌드 관리
25+
└── build/ # 빌드 결과물 저장소 (서버 생성)
26+
```
27+
28+
---
29+
30+
## 🛠 사전 준비 사항 (Prerequisites)
31+
32+
### 1. 리눅스 서버 (Remote)
33+
* **GDB**: `gdb`가 설치되어 있어야 합니다. (`gdb --version`으로 확인)
34+
* **SSH**: SSH 서비스가 활성화되어 있어야 합니다.
35+
36+
### 2. 윈도우 개발 환경 (Local)
37+
* **VS Code**: `C/C++` 확장(Microsoft)이 설치되어 있어야 합니다.
38+
* **SSH Client**: 윈도우 기본 `ssh.exe`를 사용합니다.
39+
* **SSH Key**: 비밀번호 입력 없이 접속 가능하도록 `ssh-copy-id` 등으로 키 등록을 권장합니다.
40+
41+
---
42+
43+
## 🚀 빠른 시작 가이드 (Quick Start)
44+
45+
### Step 1: 소스 코드 동기화
46+
WinSCP 또는 SFTP 도구를 사용하여 본 프로젝트 전체를 서버의 특정 경로(예: `/home/user/dev`)에 업로드합니다.
47+
> **Tip:** WinSCP의 "업데이트된 상태로 유지" 기능을 사용하면 로컬 수정 사항이 실시간으로 서버에 반영됩니다.
48+
49+
### Step 2: 서버에서 빌드
50+
서버 터미널에 접속하여 루트 디렉토리에서 빌드를 수행합니다.
51+
```bash
52+
make clean
53+
make
54+
```
55+
`build/` 폴더 내에 `a.out`, `libb.so`, `libd.so`가 생성되었는지 확인합니다.
56+
57+
### Step 3: `launch.json` 수정
58+
`.vscode/launch.json` 파일을 열어 다음 항목을 자신의 환경에 맞게 수정합니다.
59+
* `"pipeArgs"`: 서버 접속 주소 (`user@ip`)
60+
* `"program"`: 서버 내 `a.out` 절대 경로
61+
* `"sourceFileMap"`: 서버 경로와 윈도우 로컬 경로 매칭
62+
63+
### Step 4: 디버깅 시작
64+
1. `main.c` 또는 라이브러리 소스에 브레이크포인트를 잡습니다.
65+
2. `F5`를 눌러 디버깅을 시작합니다.
66+
3. 변수 조사, 조사식, 콜 스택 등 모든 VS Code 디버깅 기능을 활용합니다.
67+
68+
---
69+
70+
## ⚠️ 주의사항
71+
* **소스 동기화**: 서버의 소스와 윈도우의 소스가 라인 단위로 일치해야 브레이크포인트가 정확히 작동합니다.
72+
* **빌드 옵션**: 모든 Makefile에는 `-g` (디버그 심볼) 옵션이 포함되어 있어야 합니다.
73+
* **LD_LIBRARY_PATH**: 실행 시 라이브러리를 찾지 못한다면 `launch.json``environment` 설정을 확인하세요.
74+
75+
---
76+

apps/main_app/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# apps/main_app/Makefile
2+
CC = gcc
3+
CFLAGS = -g -I../../libs/lib_b/include -I../../libs/lib_d/include
4+
LDFLAGS = -L../../build -lb -ld
5+
TARGET = ../../build/a.out
6+
SRCS = src/main.c
7+
OBJS = $(SRCS:.c=.o)
8+
9+
all: $(TARGET)
10+
11+
$(TARGET): $(OBJS)
12+
@mkdir -p ../../build
13+
$(CC) -o $@ $^ $(LDFLAGS)
14+
15+
%.o: %.c
16+
$(CC) $(CFLAGS) -c $< -o $@
17+
18+
clean:
19+
rm -f src/*.o $(TARGET)
20+
21+

apps/main_app/src/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
#include "../../libs/lib_b/include/lib_b.h"
3+
4+
int main() {
5+
printf("Starting main_app (a.out)...\n");
6+
print_b(); // b.so 함수 호출
7+
return 0;
8+
}

libs/lib_b/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# libs/lib_b/Makefile
2+
CC = gcc
3+
CFLAGS = -g -fPIC -I./include -I../lib_d/include
4+
LDFLAGS = -L../../build -ld # libd.so를 링크함
5+
TARGET = ../../build/libb.so
6+
SRCS = src/lib_b.c
7+
OBJS = $(SRCS:.c=.o)
8+
9+
all: $(TARGET)
10+
11+
$(TARGET): $(OBJS)
12+
@mkdir -p ../../build
13+
$(CC) -shared -o $@ $^ $(LDFLAGS)
14+
15+
%.o: %.c
16+
$(CC) $(CFLAGS) -c $< -o $@
17+
18+
clean:
19+
rm -f src/*.o $(TARGET)
20+
21+

libs/lib_b/include/lib_b.h

Whitespace-only changes.

libs/lib_b/src/lib_b.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
#include "../include/lib_b.h"
3+
#include "../../lib_d/include/lib_d.h"
4+
5+
void print_b() {
6+
printf("Hello from lib_b.so (Dependency Depth 1)\n");
7+
print_d(); // d.so 함수 호출
8+
}

libs/lib_d/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# libs/lib_d/Makefile
2+
CC = gcc
3+
CFLAGS = -g -fPIC -I./include
4+
TARGET = ../../build/libd.so
5+
SRCS = src/lib_d.c
6+
OBJS = $(SRCS:.c=.o)
7+
8+
all: $(TARGET)
9+
10+
$(TARGET): $(OBJS)
11+
@mkdir -p ../../build
12+
$(CC) -shared -o $@ $^
13+
14+
%.o: %.c
15+
$(CC) $(CFLAGS) -c $< -o $@
16+
17+
clean:
18+
rm -f src/*.o $(TARGET)
19+

libs/lib_d/include/lib_d.h

Whitespace-only changes.

0 commit comments

Comments
 (0)