跳转至

使用 git-bisect 定位 bug

git-bisect 是一个强大的工具,用于快速追踪引入 iPXE bug 的确切更改。如果你在使用最新版本的 iPXE 时遇到问题,并且你知道某个较旧版本的 iPXE 没有同样的问题,那么你可以使用 git-bisect

一旦你确定了引入 bug 的确切更改,就可以通知开发者,他们随后可以利用这些信息来帮助解决你的问题。

入门

A network card

首先,检出一份 iPXE 源代码树:

  git clone https://github.com/ipxe/ipxe.git

并验证你能够构建 iPXE:

  cd ipxe/src
  make bin/undionly.kpxe

就本教程而言,假定你要使用 iPXE 的 undionly.kpxe 构建。如果你想使用不同的 iPXE 构建(例如带有 Intel e1000 网卡驱动程序的可启动 ISO),那么你应该把 bin/undionly.kpxe 替换为你想要的构建(例如 bin/e1000.iso)。

测试你刚构建的 iPXE,并确认该 bug 在这个最新版本的 iPXE 中仍然存在。(代码变化频繁,你遇到的 bug 可能已经被修复了。)

二分过程

要开始二分,告知 git-bisect 最新版本的代码有 bug:

  cd ..
  git bisect start
  git bisect bad

告诉 git-bisect 哪个较旧版本的 iPXE 没有该 bug。例如,如果你知道该 bug 在 1.0.0 版本中不存在,可以使用:

  git bisect good v1.0.0

git-bisect 会选择一个位于你所述"好"和"坏"版本中间的版本。例如:

  [mcb30@dolphin]$ git bisect good v1.0.0
  Bisecting: 187 revisions left to test after this (roughly 8 steps)
  [28934ee] [retry] Hold reference while timer is running

构建并测试 git-bisect 选择的版本:

  cd src
  make bin/undionly.kpxe
  cd ..

(同样,把 bin/undionly.kpxe 替换为你正在使用的构建。)

Here be dragons

告知 git-bisect 它选择的版本是否有该 bug:

  git bisect bad     (if the bug is present)
  git bisect good    (if the bug is not present)

git-bisect 将选择另一个新版本供你测试。构建并测试这个新版本,并再次使用 git bisect badgit bisect good 报告结果。重复此过程,直到你看到类似这样的消息:

  7e1b1d6145a36ae7ad1c58663c7116f96fada1f9 is the first bad commit

  commit 7e1b1d6145a36ae7ad1c58663c7116f96fada1f9
  Author: Michael Brown <mcb30@ipxe.org>
  Date:   Thu Nov 25 23:45:30 2010 +0000

      [vlan] Allow duplicate VLAN creation attempts

如果你正确地遵循了这个过程,那么这就是引入该 bug 的提交。你现在可以联系开发者,提供你的 bug 的详细信息,包括"第一个坏提交"(在上面的示例中为 7e1b1d6145a36ae7ad1c58663c7116f96fada1f9)。

An envelope

清理

完成后,告诉 git-bisect 清理你的 iPXE 源代码树并将其恢复到最新版本:

  git bisect reset

感谢你帮助改进 iPXE!