Debug like a Human: A Large Language Model Debugger via Verifying Runtime Execution Step by Step

Li Zhong, Zilong Wang, Jingbo Shang

arXiv:2402.16906 · 2026-07-27 공개 · arXiv · PDF

code-generation human-eval mbpp debugging-framework runtime-execution code-debugging llm-debugger basic-blocks

Abstract

Large language models (LLMs) are leading significant progress in code generation. Beyond one-pass code generation, recent works further integrate unit tests and program verifiers into LLMs to iteratively refine the generated programs. However, these works consider the generated programs as an indivisible entity, which falls short for LLMs in debugging the programs, especially when the programs contain complex logic flows and data operations. In contrast, when human developers debug programs, they typically set breakpoints and selectively examine runtime execution information. The execution flow and the intermediate variables play a crucial role in the debugging process, yet they are underutilized in the existing literature on code generation. In this study, we introduce Large Language Model Debugger (LDB), a novel debugging framework that enables LLMs to refine their generated programs with the runtime execution information. Specifically, LDB segments the programs into basic blocks and tracks the values of intermediate variables after each block throughout the runtime execution. This allows LLMs to concentrate on simpler code units within the overall execution flow, verify their correctness against the task description block by block, and efficiently pinpoint any potential errors. Experiments demonstrate that LDB consistently enhances the baseline performance by up to 9.8% across the HumanEval, MBPP, and TransCoder benchmarks, archiving new state-of-the-art performance in code debugging for various LLM selections.

한국어 요약

한 줄 요약

LDB는 실행 시점 정보를 활용해 생성된 코드를 단계별로 검증하는 LLM 디버깅 프레임워크로, HumanEval 등 3개 벤치마크에서 최대 9.8% 성능 향상.

핵심 기여도

핵심 아이디어

기존 LLM 기반 코드 생성 방식은 전체 코드를 단일 단위로 처리해 복잡한 로직의 디버깅이 어려웠다. 인간 개발자는 디버깅 시 **basic block** 단위로 실행 흐름을 분석하고 중간 변수를 점검하는 반면, 기존 연구는 실행 결과만을 기반으로 코드를 수정하는 방식이었다. LDB는 이와 달리, **LLM이 실행 시점의 basic block 단위 정보를 기반으로 코드의 정확성을 검증**하도록 설계되었다. 각 basic block의 실행 결과를 추적하고, 이를 기반으로 LLM이 **task description과 비교하며 오류를 점진적으로 수정**하게 한다. 이는 인간 개발자의 디버깅 방식을 모방한 것으로, 실행 흐름과 중간 상태를 활용한 **step-by-step 검증**이라는 새로운 패러다임을 제시한다.

기술적 접근법

주요 결과

의의 및 한계

LDB는 기존 LLM 기반 코드 생성 방식의 한계를 극복하고, 실행 시점 정보를 활용한 디버깅 프레임워크를 처음으로 제시한 점에서 학술적 의의가 있다. 특히, **basic block 단위 분석**을 통해 복잡한 로직을 단순화하고, **LLM이 실행 흐름을 이해**하도록 유도하는 방식은 기존 디버깅 접근법과 차별화된다. 그러나 LDB는 **LLM이 실행 흐름을 정확히 해석하는 능력**에 의존하며, 일부 복잡한 제어 흐름에서는 오류를 감지하지 못할 수 있다. 또한, **실행 시간 증가**와 **LLM의 반복적 질의 비용**이 발생하는 점도 한계로 지적된다.

실용적 활용

LDB는 코드 생성 후 **자동 디버깅**을 요구하는 산업 현장, 예를 들어 소프트웨어 개발 도구, 코드 생성 플랫폼, 코드 테스트 자동화 시스템 등에 적용 가능하다. 특히, **LLM이 생성한 코드의 신뢰도를 높이기 위해 실행 흐름을 기반으로 단계별 검증**이 필요한 상황에서 유용하다.