Using Large Language Models for System-Level Programming: From Code Review to Debugging and Repair

    System-level programming is a demanding test of an AI model’s engineering capabilities because it involves complex environments, limited debugging tools, and errors whose symptoms may be far from their root causes. This article presents a two-round experiment in which a large language model reviews, repairs, and iteratively improves a nonfunctional low-level program. It also summarizes a practical workflow for using AI effectively in system programming: review before modification, add instrumentation, provide real runtime feedback, and verify domain-specific details manually.

    1. Why System-Level Programming Is a Real Test for Large Language Models

    Large language models have become highly capable at everyday web development and scripting tasks. These areas have abundant training data, and errors can usually be identified quickly through short feedback cycles. System-level programming is a very different challenge:

    1. Complex environmental dependencies. In bare-metal or firmware development, programs cannot rely on operating-system services. Graphics output, memory management, and input collection must interact directly with low-level protocols and hardware abstractions. Large models have uneven knowledge of these specialized areas, which are relatively uncommon but technically deep.
    2. Severely limited debugging tools. There may be no IDE breakpoints, mature logging framework, or even a functioning console. Developers often have to observe program behavior through serial output or screen pixels. This makes blind debugging particularly difficult for AI.
    3. Misleading failure symptoms. A wild pointer may allow a program to appear to start normally before it suddenly exits. The root cause may be far removed from the location where the failure becomes visible.

    For these reasons, system-level programming provides a more meaningful test of engineering ability than asking a model to generate a front-end page.

    2. Experiment Design: Two Iterations with Progressive Goals

    To observe the model’s workflow in detail, the experiment was divided into two stages:

    • Round one: From broken code to a running program. A modular codebase was prepared that looked well structured but could not run successfully. It included separate files for the entry point, main loop, game logic, rendering, and input handling. The goal was to repair the hidden defects and allow the program to start normally and enter the game loop.
    • Round two: Refinement and optimization. After the program became stable, the next step was to address details such as graphics output and input responsiveness so that the overall experience reached a usable level.

    This structure reflects a common real-world engineering scenario: taking over legacy code that appears reasonable but is full of runtime problems. The goal is not to evaluate whether a model can generate code from scratch, but whether it can read, review, diagnose, and repair an existing system.

    3. The First Round: Exposing and Fixing Problems Step by Step

    3.1 Review the Code Before Making Changes

    One of the most reusable lessons is: do not ask the AI to modify the code immediately. Ask it to review the code first. A suitable prompt might be:

    1. Review this code and inspect the entry point, main loop,
    2. game logic, rendering module, and input handling one by one.
    3. List the issues that could prevent the program from running.
    4. Do not modify the code yet.

    Within a few minutes, the model produced a list of potential problems. This “diagnose before prescribing” workflow has three advantages:

    • It forces the model to build an understanding of the codebase as a whole instead of applying local patches.
    • The issue list itself becomes a deliverable for human review, making it easier to verify whether the model is heading in the right direction.
    • It breaks a large task into smaller, verifiable steps, producing clearer feedback at each stage.

    3.2 Problem One: The Program Exits Shortly After Startup

    After the issues from the review were addressed, the program started successfully. The screen displayed a log indicating that the game loop had started, but the program exited immediately afterward. This is a typical case of a program that can start but cannot remain alive.

    The method used to locate the failure was critical. In an environment without a debugger, the practical approach is to insert diagnostic output along the critical path and monitor execution through a serial connection:

    1. Output a progress marker at every stage of initialization
    2. so we can determine exactly where the program terminates.

    After the logs narrowed the search area, the model identified the problem in the graphics output protocol call. A pointer to display mode information obtained during an earlier query had become invalid after the display mode was set. This was a typical wild-pointer issue.

    The fix was straightforward: retrieve the framebuffer information again after setting the display mode, rather than retaining and using the old pointer.

    This problem is highly representative of system programming. A mismatch in pointer lifetime caused by API call ordering is common in low-level software. By following the cycle of “instrument, observe, narrow down, and fix,” the model was able to locate the issue independently. This suggests that its debugging methodology can remain reliable even when its domain knowledge is incomplete.

    3.3 Problem Two: The Program Runs, but No Graphics Are Displayed

    After the crash was fixed, the program ran consistently, but no graphics appeared on the screen. When this behavior was reported to the model, it identified a problem with the GUID configuration for the graphics output protocol. The underlying framework defined several protocol identifiers with similar purposes. Using the wrong one prevented the program from obtaining the correct graphics output interface.

    This case highlights a common weakness of large models in specialized domains: small distinctions between similar constants, macros, and definitions. Such details are often sparsely represented in training data, making it easy for a model to confuse related identifiers.

    The appropriate response is to provide the model with the complete failure context and let it reason from the surrounding code, rather than expecting it to produce a correct solution in a single attempt.

    4. General Principles for Using AI in System-Level Tasks

    Several reusable lessons emerged from this experiment:

    1. Work in small increments and verify each stage. Break the task into a loop of review, repair, execution, error reporting, and another repair. Provide real feedback at every step instead of expecting one perfect code generation.
    2. Review before modification. Ask the model to produce an issue list first. Humans can then assess its direction and avoid allowing the model to continue down an incorrect path.
    3. Use instrumentation extensively. In environments without a debugger, diagnostic output provides visibility into program behavior. Asking the AI to add logs at critical points is one of the most efficient ways to locate failures.
    4. Provide raw observations to the model. Serial logs, the exact time of termination, and what appears on the screen are much more useful than vague descriptions such as “the program crashed.”
    5. Manually verify specialized details. Models are generally reliable with common technologies, but they may make mistakes involving protocol GUIDs, call ordering, and other low-level details. Human review of critical changes remains necessary.

    5. Conclusion

    The most important lesson from this experiment is not whether AI can write correct code on the first attempt—it clearly cannot. The more meaningful finding is that when AI is treated as an engineer that follows a methodology and responds to feedback, it can gradually bring broken code back to life even in a system-level environment that is difficult to debug.

    Engineering ability is not limited to code generation. It also includes identifying problems, interpreting feedback, and iterating continuously. These are precisely the areas where large language models have significant practical potential.

    For enterprise teams seeking to build AI programming assistants in the cloud, a practical approach is to select a large-model service with strong code understanding and multi-turn reasoning capabilities, such as the general-purpose model capabilities provided by Baidu AI Cloud, and combine it with the collaboration workflow described in this article. This makes AI adoption in production engineering more systematic and realistic.