# 调试

调试是从软件或硬件中查找并移除缺陷（即“虫子”）的过程：它包括定位故障、诊断系统为何表现异常，以及施加修复以解决问题而不引入新问题。这一术语于1947年进入计算机领域的民间传说，当时在哈佛马克二号上工作的工程师发现一只飞蛾卡在机器某个部件中，便把它粘进了日志本；但调试实践本身与编程一样古老，如今涵盖交互式调试器、日志记录、自动化故障定位以及大规模生产事故响应。

| 关键事实 | 详情 |
|---|---|
| 术语起源 | 1947年9月9日，哈佛马克二号的操作员将一处错误追溯到卡在继电器中的一只飞蛾，并记录为“首次实际发现虫子的案例”；那张粘着飞蛾的日志页现由史密森尼美国国家历史博物馆收藏<sup>[1](https://sites.harding.edu/fmccown/short-history-of-computing.pdf)</sup><sup> • </sup><sup>[2](https://www.americanhistory.si.edu/collections/object/nmah_334663)</sup> |
| 更早的用法 | 《牛津英语词典》收录了1945年“debug”一词的用例，语境是飞机发动机，早于其在计算机领域的用法<sup>[3](https://mathshistory.st-andrews.ac.uk/SH/hopper_2_sh.pdf)</sup> |
| 时间成本 | 在一项观察性研究中，开发者调试每个已提交缺陷的中位时间为29分钟（四分位距19至75分钟）<sup>[4](https://cs.gmu.edu/~tlatoza/papers/WhatConstitutesDebugging.pdf)</sup> |
| 时间花在哪里 | 约一半的调试时间用于理解错误如何产生（缺陷诊断），另一半用于复现或修补错误<sup>[5](https://publikationen.sulb.uni-saarland.de/bitstream/20.500.11880/31243/1/Phd_thesis_Ezekiel_Soremekun-no-cv.pdf)</sup> |
| AI辅助 | 在METR的一项随机对照试验中，16名经验丰富的开发者使用2025年初的AI工具完成自己代码仓库中的问题时，平均多花了19%的时间<sup>[6](https://www.itpro.com/software/development/think-ai-coding-tools-are-speeding-up-work-think-again-theyre-actually-slowing-developers-down)</sup> |
| AI精度差距 | 在精确调试基准（Precise Debugging Benchmark）上，GPT-5.1-Codex和DeepSeek-V3.2-Thinking等前沿模型通过单元测试的比例超过76%，但编辑级精度低于45%<sup>[7](https://www.microsoft.com/en-us/research/publication/precise-debugging-benchmark-is-your-model-debugging-or-regenerating/)</sup> |

## 飞蛾与词语

调试史上最著名的事件是字面意义上的。哈佛马克二号是一台1945年至1946年间建造的机电计算机，在测试期间，操作员将一处故障追溯到卡在继电器触点之间的一只飞蛾。他们把它取出来，粘在日志本标有日期的一页上，并写下“首次实际发现虫子的案例”，旁边还有“70号继电器F面板（飞蛾）在继电器中”之类的记录。<sup>[1](https://sites.harding.edu/fmccown/short-history-of-computing.pdf)</sup> 那本粘着飞蛾的日志本现为史密森尼美国国家历史博物馆藏品的一部分。<sup>[2](https://www.americanhistory.si.edu/collections/object/nmah_334663)</sup>

这个故事常被说成是“调试”一词的起源，但史料更为审慎。史密森尼指出，那本日志本可能并非[格蕾丝·霍珀](https://www.edgepedia.org/zh/grace-hopper)（Grace Hopper）的，尽管她与马克二号团队的其他成员帮助普及了“计算机虫子”和“调试”这两个词。<sup>[8](https://www.si.edu/object/eniac-electronic-numerator-integrator-and-computer%3Anmah_334663)</sup> 这个词本身早于该事件：《[牛津英语词典](https://www.edgepedia.org/zh/oxford-english-dictionary)》的词源中收录了1945年“debug”的用例，语境是飞机发动机。<sup>[3](https://mathshistory.st-andrews.ac.uk/SH/hopper_2_sh.pdf)</sup> 霍珀是一名海军数学家，二战期间从事哈佛马克一号的相关工作，后来因推动计算机语言标准化而在业界广为人知，她成为这个故事最著名的讲述者。<sup>[9](https://www.si.edu/spotlight/women-mathematicians/grace-hopper-the-navy-and-computers)</sup><sup> • </sup><sup>[10](https://www.usni.org/magazines/naval-history-magazine/1992/september/profile-grace-murray-hopper)</sup>

## 调试包括什么

一次调试从开发者首次遇到缺陷开始，到缺陷解决为止，可分为几个可辨识的阶段：复现故障、定位出错代码、诊断原因，以及修复并验证修复。一项关于实际调试的博士研究发现，约一半时间用于理解错误如何产生，另一半用于复现或修补它。<sup>[5](https://publikationen.sulb.uni-saarland.de/bitstream/20.500.11880/31243/1/Phd_thesis_Ezekiel_Soremekun-no-cv.pdf)</sup> 缺陷并不保证能得到解决：在一项针对实时编程直播的研究中，一半的调试事件针对已提交缺陷，且未以成功修复告终，原因要么是需要更多信息才能复现缺陷，要么是开发者推迟了这项工作。<sup>[4](https://cs.gmu.edu/~tlatoza/papers/WhatConstitutesDebugging.pdf)</sup>

**工具与技术。** 标准的交互式工具是调试器，这是一种让开发者观察并纠正编程错误的应用程序，通常通过在断点处暂停执行并检查程序状态来实现。<sup>[11](https://learn.microsoft.com/en-us/windows/desktop/Debug/basic-debugging)</sup> 例如，Python的pdb支持在语句之后单步执行代码、事后调试以及在程序控制下调用；自Python 3.7起，内置的`breakpoint()`调用可直接进入调试器。<sup>[12](https://docs.python.org/3/library/pdb.html)</sup> 对职业开发者的调查将工具版图分为若干类别，包括打印与日志、断言、符号调试器与时间回溯调试器、程序切片，以及若干类自动化故障定位。<sup>[13](https://www.hirschfeld.org/writings/media/PerscheidSiegmundTaeumelHirschfeld_2017_StudyingTheAdvancementInDebuggingPracticeOfProfessionalSoftwareDevelopers_SpringerSQJ.pdf)</sup>

**自动化支持。** 增量调试（delta debugging）等技术通过系统性地测试候选输入或变更集，自动缩小回归（由近期变更引入的缺陷）的成因范围；一项针对真实回归缺陷的评估基于这一原理构建了工具，用于软件演化过程。<sup>[14](https://www.sciencedirect.com/science/article/abs/pii/S0164121211002743)</sup> 工具设计的实证结果并不总符合直觉：一项关于以对象为中心的断点的对照实验发现，虽有人提出这种断点比普通行断点更适合面向对象程序，但对调试所需操作数量、理解或修复缺陷的有效性以及所花时间均无显著影响。<sup>[15](https://doi.org/10.1145/3715759)</sup>

## 调试要花多长时间

测量数据因环境而异，但一致表明调试占开发工作的相当大一部分。实时编程研究中每个已提交缺陷的中位时间为29分钟，四分位距为19至75分钟，表明存在一条艰难案例的长尾。<sup>[4](https://cs.gmu.edu/~tlatoza/papers/WhatConstitutesDebugging.pdf)</sup> 关于调试器使用的研究报告称，开发者平均有14%至16%的时间花在调试器本身之内，而以对象为中心的断点实验在其自身环境中测得29%至38%。<sup>[15](https://doi.org/10.1145/3715759)</sup> 缩短这一时间具有经济意义，因为调试是开发和[软件维护](https://www.edgepedia.org/zh/software-maintenance)中公认的耗时环节。<sup>[15](https://doi.org/10.1145/3715759)</sup>

## 生产环境中的调试

软件发布后调试并未停止。在谷歌，团队使用工具组合、高层策略和底层任务来调试分布式生产系统中的事故，公司还研究了其工程师实际如何响应生产事故，这往往不同于《站点可靠性工程》指南中写下的理想化做法。<sup>[16](https://research.google/pubs/debugging-incidents-in-googles-distributed-systems/)</sup> 谷歌的事故管理指南将响应本身视为一个项目，在技术缓解之外，还要有计划好的参与、文档记录，以及与用户和利益相关方的一致沟通。<sup>[17](https://sre.google/resources/practices-and-processes/incident-management-guide/)</sup>

事故解决后，谷歌的做法是撰写无责事后复盘，这是一份记录事故如何展开、其影响以及哪些做得好或可改进的书面材料，其原则是责备个人无助于学习。随后聚合众多复盘中的结构化数据，可以揭示趋势和需要更大投入的领域。<sup>[17](https://sre.google/resources/practices-and-processes/incident-management-guide/)</sup>

## 调试AI生成的代码

AI编程助手从两个方向改变了调试工作量。在辅助方面，谷歌SRE报告了能在约两分钟预算内拦截警报并收集上下文的AI系统，以及一项“事故假设”功能，可提出可信原因和验证步骤；谷歌的[A/B测试](https://www.edgepedia.org/zh/a-b-testing)测得，仅凭这种信息性辅助，平均缓解时间（MTTM）就缩短了10%，而AI驱动的调查仪表盘将受支持事故的MTTM缩短了约44%。<sup>[18](https://sre.google/resources/practices-and-processes/ai-engineering-reliable-operations/)</sup>

在负担方面，证据不一。METR的随机对照试验发现，经验丰富的开发者在自己开源仓库上工作时，使用2025年初的AI工具平均多花19%的时间，研究者将这一单一环境的结果作为基线而非普遍结论提出。<sup>[6](https://www.itpro.com/software/development/think-ai-coding-tools-are-speeding-up-work-think-again-theyre-actually-slowing-developers-down)</sup> 调查显示，67%的开发者调试AI生成代码的时间比采用这些工具之前更多。<sup>[19](https://www.itpro.com/software/development/senior-developers-are-all-in-on-vibe-coding-but-junior-staff-lack-the-experience-to-spot-critical-flaws)</sup>

模型能力也未达到调试的具体要求。与代码补全不同，调试需要定位故障并施加有针对性的编辑，而精确调试基准用编辑级精度和缺陷级召回率来衡量这一点。前沿模型通过单元测试的比例很高，但会重新生成看似正确、过度编辑的解决方案：GPT-5.1-Codex和DeepSeek-V3.2-Thinking的通过率超过76%，精度却低于45%，即使明确指示其做最小编辑也是如此，迭代式或智能体式策略也未显著提高精度或召回率。<sup>[7](https://www.microsoft.com/en-us/research/publication/precise-debugging-benchmark-is-your-model-debugging-or-regenerating/)</sup>

## References

1. [A Short History of Computing (McOwn, Harding University)](https://sites.harding.edu/fmccown/short-history-of-computing.pdf)
2. [Log Book With Computer Bug, National Museum of American History, Smithsonian Institution](https://www.americanhistory.si.edu/collections/object/nmah_334663)
3. [The term 'debugging' and Grace Hopper, School of Mathematics and Statistics, University of St Andrews](https://mathshistory.st-andrews.ac.uk/SH/hopper_2_sh.pdf)
4. [What constitutes debugging? Empirical findings from live-coding streams, Empirical Software Engineering (2023)](https://cs.gmu.edu/~tlatoza/papers/WhatConstitutesDebugging.pdf)
5. [Debugging in Practice: An Empirical Study (Soremekun, Saarland University doctoral thesis)](https://publikationen.sulb.uni-saarland.de/bitstream/20.500.11880/31243/1/Phd_thesis_Ezekiel_Soremekun-no-cv.pdf)
6. [Think AI coding tools are speeding up work? Think again, ITPro (METR randomized controlled trial)](https://www.itpro.com/software/development/think-ai-coding-tools-are-speeding-up-work-think-again-theyre-actually-slowing-developers-down)
7. [Precise Debugging Benchmark: Is Your Model Debugging or Regenerating?, Microsoft Research](https://www.microsoft.com/en-us/research/publication/precise-debugging-benchmark-is-your-model-debugging-or-regenerating/)
8. [log book with computer bug | smithsonian institution](https://www.si.edu/object/eniac-electronic-numerator-integrator-and-computer%3Anmah_334663)
9. [Grace Hopper: The Navy and Computers, Smithsonian Institution](https://www.si.edu/spotlight/women-mathematicians/grace-hopper-the-navy-and-computers)
10. [In Profile: Grace Murray Hopper, Naval History Magazine (1992)](https://www.usni.org/magazines/naval-history-magazine/1992/september/profile-grace-murray-hopper)
11. [Basic Debugging, Microsoft Learn](https://learn.microsoft.com/en-us/windows/desktop/Debug/basic-debugging)
12. [pdb, The Python Debugger, Python 3 documentation](https://docs.python.org/3/library/pdb.html)
13. [Studying the advancement in debugging practice of professional software developers, Software Quality Journal (2017)](https://www.hirschfeld.org/writings/media/PerscheidSiegmundTaeumelHirschfeld_2017_StudyingTheAdvancementInDebuggingPracticeOfProfessionalSoftwareDevelopers_SpringerSQJ.pdf)
14. [Towards automated debugging in software evolution: Evaluating delta debugging on real regression bugs, Journal of Systems and Software](https://www.sciencedirect.com/science/article/abs/pii/S0164121211002743)
15. [Empirically Evaluating the Impact of Object-Centric Breakpoints on the Debugging of Object-Oriented Programs, Proceedings of the ACM on Software Engineering](https://doi.org/10.1145/3715759)
16. [Debugging Incidents in Google's Distributed Systems, Google Research (ACM Queue, 2020)](https://research.google/pubs/debugging-incidents-in-googles-distributed-systems/)
17. [Incident Management Guide, Google SRE](https://sre.google/resources/practices-and-processes/incident-management-guide/)
18. [AI Engineering for Reliable Operations, Google SRE](https://sre.google/resources/practices-and-processes/ai-engineering-reliable-operations/)
19. [Senior developers are all in on vibe coding, but junior staff lack the experience to spot critical flaws, ITPro (Fastly survey)](https://www.itpro.com/software/development/senior-developers-are-all-in-on-vibe-coding-but-junior-staff-lack-the-experience-to-spot-critical-flaws)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Software engineering and development process › Software testing and quality

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/debugging

English original: https://www.edgepedia.org/debugging
