一句话:提出层次化调试器 MGDebugger,通过子函数分解与自底向上排错,显著提升 LLM 生成代码的修复成功率。
大语言模型在代码生成上进步显著,但生成代码常因细微错误而无法通过测试,现有基于 LLM 的调试系统将程序视为整体,难以处理从底层语法错误到高层算法缺陷的多粒度问题。本文提出 MGDebugger,将待调试代码分解为子函数层次树,每一层对应不同错误粒度,并以自底向上方式迭代定位和修复缺陷。为测试各子函数,作者提出 LLM 模拟的 Python 执行器,跟踪执行过程与关键变量状态以精确定位错误。实验表明,MGDebugger 在 HumanEval 上相较种子生成最高提升 18.9% 准确率,在 HumanEvalFix 上达到 97.6% 修复成功率;在 Defects4J v1.2 和 v2.0 上分别修复 129 和 64 个真实缺陷,超越当前最优程序修复方法 13.2% 和 8.5%。
While large language models have made significant strides in code generation, the pass rate of the generated code is bottlenecked on subtle errors, often requiring human intervention to pass tests, especially for complex problems. Existing LLM-based debugging systems treat generated programs as holistic units, failing to address bugs at multiple levels of granularity, from low-level syntax errors to high-level algorithmic flaws. In this paper, we introduce Multi-Granularity Debugger (MGDebugger), a hierarchical code debugger that isolates, identifies, and resolves bugs at various levels of granularity. MGDebugger decomposes problematic code into a hierarchical tree structure of subfunctions, with each level representing a particular granularity of error. During debugging, it analyzes each subfunction and iteratively resolves bugs in a bottom-up manner. To effectively test each subfunction, we propose an LLM-simulated Python executor, which traces code execution and tracks important variable states to pinpoint errors accurately. Extensive experiments with both open-source and commercial LLMs demonstrate that MGDebugger significantly outperforms existing debugging systems, achieving up to 18.9% improvement in accuracy over seed generations in HumanEval and a 97.6% repair success rate in HumanEvalFix. Furthermore, MGDebugger effectively generalizes to real-world software defects, fixing 129 bugs in Defects4J v1.2 and 64 bugs in Defects4J v2.0, outperforming state-of-the-art program repair approaches by 13.2% and 8.5% respectively. These results demonstrate MGDebugger’s robustness and effectiveness across different scenarios, establishing it as a powerful tool for closing the last mile of code generation.1
@inproceedings{abs-2410-01215,
title = {From Code to Correctness: Closing the Last Mile of Code Generation with Hierarchical Debugging},
author = {Yuling Shi and Songsong Wang and Chengcheng Wan and Min Wang and Xiaodong Gu},
booktitle = {ICSE},
year = {2026},
doi = {10.1145/3744916.3773255}
}