Skip to main content
QUICK REVIEW

[Paper Review] Debug like a Human: A Large Language Model Debugger via Verifying Runtime Execution Step-by-step

Zhong Li, Zilong Wang|arXiv (Cornell University)|Feb 25, 2024
Model-Driven Software Engineering TechniquesComputer Science3 citations
TL;DR

LDB is a novel debugging framework that enables large language models (LLMs) to iteratively refine code by analyzing runtime execution step-by-step, tracking intermediate variables and control flow across basic blocks. By emulating human debugging practices—such as setting breakpoints and inspecting variable states—LDB improves code generation accuracy by up to 9.8% across HumanEval, MBPP, and TransCoder benchmarks, achieving state-of-the-art performance.

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.

Motivation & Objective

  • To address the limitation of existing LLM-based code generation methods that treat programs as indivisible entities, ignoring granular execution details.
  • To bridge the gap between LLM debugging and human developer practices, which rely on runtime inspection of intermediate states and control flow.
  • To improve code generation accuracy by enabling LLMs to verify correctness block-by-block using execution traces and variable values.
  • To develop a framework that is compatible with diverse LLM backbones and effective across multiple code generation tasks, including text-to-code and code translation.

Proposed method

  • LDB decomposes generated programs into basic blocks using control flow graph analysis to enable fine-grained execution tracking.
  • It executes the program with a failing test case and records the runtime values of intermediate variables after each basic block.
  • The framework then queries an LLM to evaluate the correctness of each block’s behavior relative to the task description, providing feedback per block.
  • Based on the LLM’s verdicts and explanations, the model regenerates a refined program that corrects identified errors.
  • The process is iterative, allowing the LLM to progressively debug and improve the code using runtime insights.
  • The method is evaluated across multiple benchmarks and LLM architectures, including GPT-3.5, StarCoder, and CodeLlama.

Experimental results

Research questions

  • RQ1Can LLMs achieve better code generation accuracy by analyzing runtime execution step-by-step rather than treating programs as monolithic units?
  • RQ2To what extent does block-level verification using intermediate variable states improve debugging performance compared to post-execution feedback alone?
  • RQ3How effective is the proposed debugging framework across diverse LLM architectures and code generation tasks?
  • RQ4Does the framework maintain performance gains when applied to more powerful LLMs like GPT-4 or Reflexion?

Key findings

  • LDB improves code generation accuracy by up to 9.8% on the HumanEval benchmark compared to baseline methods.
  • The framework achieves state-of-the-art performance on HumanEval, MBPP, and TransCoder benchmarks across multiple LLM backbones.
  • Even with powerful models like GPT-4 and Reflexion, LDB consistently enhances performance, demonstrating its generalizability.
  • The block-level debugging approach enables LLMs to identify and correct logical errors such as incorrect conditionals (e.g., checking for even instead of odd elements) with high precision.
  • Feedback from the LLM on individual blocks leads to accurate identification of faulty logic, such as misinterpreting 'odd elements in even positions' as 'even elements in even positions'.
  • The method effectively handles complex control flows and data operations by isolating and verifying each basic block independently.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.