androidのenvsetup.shに隠されてる(?)便利なコマンド

androidのフルソースをビルドするときに使うenvsetup.sh。

普段はビルドで'mm'するための準備にくらいしか使ってないけれど、実はいろいろなコマンドが拡張されるのだ。

試しに、envsetup.shを読み込んでから'help'とコマンドすると...

$ source ./envsetup.sh
$ help
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- croot:   Changes directory to the top of the tree.
- m:       Makes from the top of the tree.
- mm:      Builds all of the modules in the current directory.
- mmm:     Builds all of the modules in the supplied directories.
- cgrep:   Greps on all local C/C++ files.
- jgrep:   Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir:   Go to the directory containing a file.

Look at the source to view more functions. The complete list is:
add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant croot findmakefile gdbclient get_abs_build_var get_build_var getbugreports getprebuilt gettop godir help isviewserverstarted jgrep lunch m mm mmm pid print_lunch_menu printconfig resgrep runhat runtest runtest_py set_sequence_number set_stuff_for_environment setpaths settitle smoketest startviewserver stopviewserver tapas tracedmdump

m,mmの他に、

  • cgrep ... C/C++ファイルのみのgrep
  • jgrep ... Javaファイルのみのgrep

などもあるみたい。

で、オマケはその下にあるコマンドの羅列。

"Look at the source to view more functions."とあるように、envsetup.shの中身を直接見て動作を確かめるといいのだけど、個人的に特に使える!と思ったのが"gdbclient"コマンド。

Native層のデバッグは、gdbとgdbserverを使ってリモートデバッグをするわけだけど、シンボルの読み込み設定だったりServer側とClient側でそれぞれポートの設定やらプロセスにattachしておいたりだとかデバッグを始めるまでの手順がけっこう多い。

gdbclientコマンドだと、エミュレータでデバッグ対象のアプリプロセスもしくはプロセスを起動しておけば、

  • client側のシンボルの読み込み(システム系ライブラリなどほぼ全て)
  • target側のgdbserverの起動と、デバッグ対象プロセスへのattach
  • target側のadb forwardの設定
  • client側gdbの起動

までを1コマンドでやってくれる。

一番便利なのが、attachするプロセス番号を勝手に探してgdbserverでattachしてくれるところだと思う。

このgdbclientコマンド以外にもいろいろ使えそうなコマンドが拡張されるので、envsetup.shのソースは一度眺めてみると良いかも。

タイトルとURLをコピーしました