Breakpoint
Breakpoint
A point at which a debugger pauses execution. Used to inspect variable state and step through code.
Breakpoint
A point at which a debugger pauses execution. Used to inspect variable state and step through code.
A breakpoint is a marker that temporarily pauses program execution at a specific point during debugging. When execution reaches a line of code where a breakpoint is set, the program stops, and the developer can inspect in detail the variable values, call stack, memory state, and more at that moment.
A conditional breakpoint is an advanced feature that pauses execution only when a specific condition is true. For example, if you set it to "break only when i > 100," you can pinpoint exactly the moment a problem occurs among hundreds of iterations, which greatly improves debugging efficiency.
Modern IDEs and debuggers support various types of breakpoints. These include line breakpoints (break at a specific line), function breakpoints (break on function entry), exception breakpoints (break when an exception is thrown), and data breakpoints (break when a variable's value changes). By making appropriate use of these various breakpoints, you can effectively trace even complex bugs.
Breakpoints are far more powerful than debugging with print statements. This is because you can observe the execution flow without modifying the code, evaluate expressions at the point of the break, and trace the code line by line using step over/step into/step out. In production environments, logging is used instead of breakpoints, but during development they are the most efficient debugging tool.
# Python pdb (Python Debugger) 사용 예제
import pdb
def calculate_average(numbers):
"""평균 계산 함수 - 디버깅 데모"""
total = 0
count = 0
for num in numbers:
# pdb.set_trace()를 사용한 수동 브레이크포인트
# 이 지점에서 실행이 멈추고 디버거 프롬프트가 나타남
pdb.set_trace() # 여기서 중단됨
total += num
count += 1
print(f"현재 합계: {total}, 개수: {count}")
return total / count if count > 0 else 0
# 조건부 브레이크포인트 시뮬레이션
def debug_loop_with_condition(data):
for i, item in enumerate(data):
# 조건부 중단: i가 5일 때만 디버거 진입
if i == 5:
pdb.set_trace() # 조건부 브레이크포인트
process(item)
# breakpoint() - Python 3.7+ 내장 함수 (권장)
def modern_debugging():
x = 10
y = 20
breakpoint() # Python 3.7+ 표준 브레이크포인트
# 디버거에서 사용 가능한 명령어:
# n (next): 다음 줄로 이동
# s (step): 함수 안으로 진입
# c (continue): 다음 브레이크포인트까지 실행
# p 변수명: 변수 값 출력
# l (list): 현재 코드 주변 표시
# q (quit): 디버거 종료
result = x + y
return result
# 실행 예시
if __name__ == "__main__":
numbers = [1, 2, 3, 4, 5]
avg = calculate_average(numbers)
print(f"평균: {avg}")
"This bug was hard to reproduce, so I tried a conditional breakpoint. I set it to break only when user_id is a specific value, and I was able to find the cause of the problem right away."
"When debugging, I mainly use the IDE's breakpoints. I stop execution with a line breakpoint, check variable states in the Watch window, and trace the code flow with step over and step into. In loops, I use conditional breakpoints to catch only specific conditions."
"There's a leftover pdb.set_trace() here. Please be sure to remove debugging breakpoints before committing. If you add a pdb check to the pre-commit hook, you can prevent them from being pushed by mistake."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Be sure to remove debugging code such as pdb.set_trace(), debugger, and breakpoint() before committing. If it runs in production, the service may halt or security issues may arise.
Setting too many breakpoints actually makes debugging inefficient. Set them only at the 2-3 key points where you suspect the problem, and make use of conditional breakpoints.
Learning debugger shortcuts such as F5 (run), F9 (toggle breakpoint), F10 (step over), and F11 (step into) greatly speeds up debugging. Shortcuts differ for each IDE, so get familiar with the keymap of the tool you use.