arXiv:2410.01215cs.CLcs.AI2024-10中稿 · ICSE 2026被引 59

用分层调试解决代码生成中的细微错误,显著提升通过率。

From Code to Correctness: Closing the Last Mile of Code Generation with Hierarchical Debugging

  • 将代码分解为多层级子函数树,逐级定位错误
  • 在HumanEval上比原始生成准确率高18.9%,修复成功率97.6%
  • 适合需要高可靠性的自动化代码生成场景

尽管大语言模型在代码生成方面取得进展,但生成代码的通过率仍受细微错误制约,尤其在复杂问题上常需人工干预才能通过测试。现有基于LLM的调试系统将程序视为整体,无法在不同粒度下处理错误,从语法到算法缺陷均难以覆盖。本文提出多粒度调试器MGDebugger,通过将问题代码分解为分层子函数树,按层级逐级分析与修复。调试过程中采用基于LLM的模拟执行器,追踪代码运行与变量状态,精准定位错误。实验表明,MGDebugger在HumanEval上相比原始生成准确率提升18.9%,在HumanEvalFix中修复成功率达97.6%,可有效应对各类错误和难度级别,展现强大鲁棒性与有效性。

原文摘要 · Abstract (English)

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 monolithic 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 by isolating, identifying, and resolving 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 demonstrate that MGDebugger outperforms existing debugging systems, achieving an 18.9% improvement in accuracy over seed generations in HumanEval and a 97.6% repair success rate in HumanEvalFix. Furthermore, MGDebugger effectively fixes bugs across different categories and difficulty levels, demonstrating its robustness and effectiveness.

代码生成智能调试分层推理LLM应用

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。