Git でバグを bisect する

提供: ArchWiki
2022年2月8日 (火) 01:25時点におけるKgx (トーク | 投稿記録)による版 (一部翻訳)
ナビゲーションに移動 検索に移動

Mesa や Linux カーネルなどのプロジェクトで発生したバグを報告する際、 問題のあるコミットが何であるかを確認するために、最後に動作した既知のバージョン と問題のある新しいバージョンとの間でバイセクトを行うよう求められることがよくあ ります。Arch では、AUR の機能のおかげで、これは非常に簡単に行うことができます。

古いリリースに戻す場合

問題を引き起こしているのが新しいパッケージのリリースであることを確認することは有用かもしれません。Arch での パッケージのダウングレード は、古いバージョンのパッケージがシステムにキャッシュとして保存されていれば、簡単に実行できます。

ノート: 古いバージョンで問題が解決されたとしても、それはプログラムのバグではなく、Arch が提供するパッケージの問題である可能性があります

git からのパッケージの構築

bisect を行うには、git からパッケージのバージョンをビルドする必要があります。これは AUR から -git パッケージをビルドすることで実現できます。

bisect のセットアップ

パッケージのビルドが成功したら、src/ ディレクトリ内の git ルートディレクトリに移動する必要があります。git ルートディレクトリの名前は、多くの場合pkgname と同じです。(または接尾辞 -git を除いたもの)

$ cd src/git_root

そこから、bisecting するプロセスを開始できます:

$ git bisect start

次のコマンドは、bisecting する場所を指定するために使用できるすべてのタグを表示します:

$ git tag

前の例に続いて、バージョン oldver は機能したが、newver は機能しなかったと想定します。

$ git bisect good oldver
$ git bisect bad newver

良いバージョンと悪いバージョンのタグが付けられたので、コミットのテストに進むことができます。

Bisecting

Change back into the directory with the PKGBUILD. If you are still in the directory mentioned in the previous section this can be accomplished like so:

$ cd ../..

You can now rebuild and install the specific revision of the package:

$ makepkg -efsi
ノート: It is very important to keep the -e prefix intact as otherwise it will remove all the changes you have made.

Once the new package is installed you can test for your previously discovered error. Return to the directory you were in the previous section:

$ cd src/git_root

If you encountered your problem, tell that the revision was bad:

$ git bisect bad

If you did not encounter your problem, tell that the revision it was good:

$ git bisect good

Then do as described at the beginning of this section again and repeat until git bisect names the troublesome commit.

ノート:
  • You may need to run a make clean after issuing the git bisect command.
  • It will actually count down the number of steps all the way down to zero, so it is important not to stop until it actually names the first bad commit.

Speeding up builds

Building smaller kernel

You can shorten kernel build times by building only the modules required by the local system using modprobed-db, or by make localmodconfig. Of course you can completely drop irrelevant drivers, for example sound drivers to debug a network problem.

Ccache

If you are bisecting a large project built using gcc, it might be possible to reduce build times by enabling ccache. It may take several build iterations before you start to see benefits from the cache, however. The likelihood of cache hits generally increases as the distance between bisection points decreases.

ノート: Ccache is effective only when compiling exactly identical sources. And to bisect the kernel, it is not necessary to do make clean, meaning ccache is a complete waste.

Restoring package

Reverting to an original version of the package can be done by installing the package from repositories with pacman.

See also