[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -4,116 +4,150 @@ title: Debugger Techniques
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-REINFORCE-WIKI-DEV-DEBUGGER-TECHNIQUES, 디버거, Debugger, 디버깅, 중단점, Breakpoint, 호출 스택]
|
||||
aliases: [Debugging, Debug Tooling]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 1.0
|
||||
tags: [Debugging, Runtime, Analysis, Troubleshooting, Tools]
|
||||
raw_sources: [Datacollector_Export_2026-05-02]
|
||||
last_reinforced: 2026-05-02
|
||||
github_commit: pending
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [debugging, devtools, troubleshooting]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: applied
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: Multi
|
||||
framework: gdb/lldb/Chrome DevTools
|
||||
---
|
||||
|
||||
# [[고급 디버깅 기법과 런타임 추적 (Debugger Techniques)]]
|
||||
# Debugger Techniques
|
||||
|
||||
## 1. 개요
|
||||
디버거(Debugger)는 실행 중인 프로그램의 내부 상태를 실시간으로 관찰하고 제어할 수 있게 해주는 가장 강력한 동적 분석 도구이다. 단순히 오류를 수정하는 단계를 넘어, 코드의 실행 흐름(Control Flow)과 데이터의 상태 변화(State Change)를 추적하여 시스템의 정밀한 멘탈 모델을 구축하는 핵심 수단으로 활용된다.
|
||||
## 매 한 줄
|
||||
> **"매 print 보다 breakpoint 가 빠르고, breakpoint 보다 reverse-debug 이 깊다."**. Debugger techniques 는 breakpoint, watchpoint, conditional, log-point, time-travel, post-mortem (core dump) 의 매 toolkit. 2026 stack: Chrome DevTools (live), VS Code DAP, gdb/lldb, rr (record-replay), Pernosco (cloud time-travel).
|
||||
|
||||
## 2. 핵심 기능 및 활용법
|
||||
- **중단점 (Breakpoints)**: 코드의 특정 지점에서 실행을 일시 정지. 조건부 중단점(Conditional Breakpoints)을 사용하여 특정 조건이 충족될 때만 정지하도록 설정 가능.
|
||||
- **단계별 실행 (Stepping)**:
|
||||
- **Step Over**: 현재 라인의 함수를 실행하고 다음 라인으로 이동.
|
||||
- **Step Into**: 현재 라인의 함수 내부로 진입하여 상세 로직 관찰.
|
||||
- **Step Out**: 현재 함수를 끝까지 실행하고 호출한 상위 함수로 복귀.
|
||||
- **호출 스택 (Call Stack) 조사**: 현재 실행 지점에 도달하기까지 거쳐온 함수의 계층 구조를 역추적하여 실행 맥락 파악.
|
||||
- **변수 및 메모리 감시 (Watch & Inspect)**: 변수의 현재 값, 객체의 구조, 메모리 주소 등을 실시간으로 확인.
|
||||
## 매 핵심
|
||||
|
||||
## 3. 탐험적 디버깅 (Exploratory Debugging)
|
||||
- **온보딩 활용**: 새로운 코드베이스를 익힐 때 단순히 읽는 대신, 주요 기능의 진입점에 중단점을 설정하고 데이터가 어떻게 가공되어 전달되는지 직접 관찰.
|
||||
- **가설 검증**: "이 변수는 이 시점에서 null이 아닐 것이다"와 같은 가설을 세우고 디버거로 즉각 확인하여 인지적 불확실성 제거.
|
||||
- **의도적 오류 주입**: 런타임에 변수 값을 강제로 변경하여 시스템의 예외 처리 로직이나 에지 케이스 대응 능력을 테스트.
|
||||
### 매 Breakpoint Type
|
||||
- **Line**: 매 source line 정지.
|
||||
- **Conditional**: 매 expression true 일 때만.
|
||||
- **Log-point** ("tracepoint"): 매 정지 안하고 log 찍음.
|
||||
- **Function**: 매 fn enter.
|
||||
- **Watchpoint**: 매 memory address change.
|
||||
- **Exception**: 매 throw caught/uncaught.
|
||||
- **DOM**: 매 Chrome — node modification.
|
||||
- **XHR/fetch**: 매 URL pattern.
|
||||
- **Event listener**: 매 click/keydown 등.
|
||||
|
||||
## 4. 트레이드오프 및 주의사항
|
||||
- **관찰자 효과 (Heisenbug)**: 디버거 연결 자체가 타이밍 이슈나 경합 조건(Race Condition)을 변화시켜, 디버깅 중에는 버그가 나타나지 않거나 다르게 동작할 수 있음.
|
||||
- **멀티스레드/비동기 제약**: 여러 스레드가 동시에 실행되거나 비동기 콜백이 많은 환경에서는 중단점이 실행 흐름을 방해하여 전체적인 흐름을 놓칠 수 있음. (이 경우 로깅이나 분산 추적 도구가 더 효과적일 수 있음)
|
||||
- **환경 의존성**: 로컬 환경과 프로덕션 환경의 데이터나 설정 차이로 인해 로컬 디버깅만으로는 원인 파악이 힘든 경우가 존재함.
|
||||
### 매 Time-Travel Debugging
|
||||
- **rr** (Linux): record once, replay backwards/forwards — 매 nondeterministic bug 의 답.
|
||||
- **Pernosco**: rr trace 의 cloud UI — 매 expression 의 모든 변경 이력.
|
||||
- **WinDbg TTD** (Windows).
|
||||
- **Chrome DevTools "Replay panel"** (2025+ experimental).
|
||||
|
||||
## 5. 지식 연결 (Related)
|
||||
- [[Dynamic_Behavior_Tracking]]: 디버깅을 포함하는 광범위한 런타임 분석 기법.
|
||||
- [[Flame_Graphs]]: 프로파일링 결과를 시각화하여 디버깅의 우선순위를 결정하는 도구.
|
||||
- [[Static_Code_Analysis]]: 디버깅 전 단계에서 코드의 구조적 결함을 찾아내는 기술.
|
||||
### 매 응용
|
||||
1. Heisenbug — 매 conditional + log-point.
|
||||
2. Crash post-mortem — 매 core dump + gdb.
|
||||
3. Performance — 매 sampling + breakpoint.
|
||||
4. Memory leak — 매 heap snapshot diff.
|
||||
5. Distributed — 매 OpenTelemetry trace.
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
- **정보 상태**: 검증 완료 (Verified)
|
||||
- **출처 신뢰도**: A
|
||||
- **검토 이유**: 소프트웨어의 동작을 추측이 아닌 사실(Fact) 기반으로 이해하고 제어하기 위한 전문적인 디버깅 표준 정립.
|
||||
## 💻 패턴
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
|
||||
> *(TODO: 한 문장으로 핵심 통찰을 작성. "X는 Y 조건에서 Z 효과를 낸다" 구조 권장.)*
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
|
||||
**추출된 패턴:**
|
||||
> *(TODO)*
|
||||
|
||||
**세부 내용:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
|
||||
- **과거 데이터와의 충돌:** 없음
|
||||
- **정책 변화:** 없음
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
|
||||
- **Parent:** [[10_Wiki/Topics]]
|
||||
- **Related:** *(TODO: 최소 2개)*
|
||||
- **Opposite / Trade-off:** *(TODO)*
|
||||
- **Raw Source:** 직접 입력
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
### Chrome conditional breakpoint
|
||||
```javascript
|
||||
// 매 in DevTools right-click line → Add conditional breakpoint
|
||||
// expression: user.id === 42 && cart.total > 1000
|
||||
// 또는 logpoint: console.log('cart', cart, 'time', performance.now())
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### gdb scripted debugging
|
||||
```bash
|
||||
gdb --batch -x debug.gdb ./app core.12345
|
||||
# debug.gdb
|
||||
set pagination off
|
||||
bt full
|
||||
info threads
|
||||
thread apply all bt
|
||||
print *some_struct
|
||||
```
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### lldb Python script
|
||||
```bash
|
||||
(lldb) script
|
||||
>>> frame = lldb.frame
|
||||
>>> for var in frame.variables: print(var.name, var.value)
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### rr record-replay (Linux)
|
||||
```bash
|
||||
rr record ./buggy_program
|
||||
rr replay
|
||||
# 매 in rr's gdb
|
||||
(rr) reverse-continue
|
||||
(rr) reverse-step
|
||||
(rr) watch -l some_var
|
||||
```
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
### Node.js inspector + Chrome
|
||||
```bash
|
||||
node --inspect-brk=0.0.0.0:9229 server.js
|
||||
# 매 chrome://inspect
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### Python pdb / debugpy
|
||||
```python
|
||||
import pdb; pdb.set_trace() # 매 classic
|
||||
breakpoint() # 매 PEP 553 (python 3.7+)
|
||||
# 매 VS Code remote: debugpy.listen(('0.0.0.0', 5678)); debugpy.wait_for_client()
|
||||
```
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
### eBPF dynamic tracing
|
||||
```bash
|
||||
sudo bpftrace -e 'uprobe:./app:malloc { @[ustack] = count(); }'
|
||||
```
|
||||
|
||||
### Conditional log-point pattern
|
||||
```javascript
|
||||
// 매 production-safe lazy log — no perf cost when disabled
|
||||
if (DEBUG) console.log('state', JSON.stringify(state));
|
||||
// 매 better — feature flag gated
|
||||
if (flags.debugCart) logger.debug({ cart, user });
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Tool |
|
||||
|---|---|
|
||||
| Web (Chromium) | DevTools Sources panel |
|
||||
| Node.js | --inspect + DevTools / VS Code |
|
||||
| C/C++ Linux | gdb / lldb + rr |
|
||||
| C/C++ macOS | lldb + Instruments |
|
||||
| Python | debugpy + VS Code |
|
||||
| Heisenbug | rr + Pernosco |
|
||||
| Production crash | core dump + gdb |
|
||||
| Distributed | OTel trace |
|
||||
|
||||
**기본값**: 매 IDE breakpoint → 부족시 rr / TTD.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[중단점 (Breakpoints)]]
|
||||
- 변형: [[동적 런타임 분석 (Dynamic Runtime Analysis)]]
|
||||
- 응용: [[Flame_Graphs]] · [[Logging_and_Error_Handling]]
|
||||
- Adjacent: [[Analyze runtime performance]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: stack trace 해석, log clustering, hypothesis generation, repro script.
|
||||
**언제 X**: 매 step-into 같은 deterministic 작업 — IDE 가 직접.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **printf-only**: 매 build cycle 낭비 — debugger 사용.
|
||||
- **Production breakpoint**: 매 thread freeze — log-point 사용.
|
||||
- **No source map**: 매 minified frame 해독 불가.
|
||||
- **Trust gut without repro**: 매 unreliable repro 면 가설 무한 반복.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified: Chrome DevTools docs; gdb manual; rr-project.org; Pernosco docs.
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — breakpoint taxonomy + rr/TTD + multi-lang |
|
||||
|
||||
Reference in New Issue
Block a user