LoginSignup
9
9

More than 5 years have passed since last update.

ARM Linuxのリモートデバッグ用にgdb 8.0.1 をソースからビルドする

Last updated at Posted at 2018-01-11

どうせやるなら、現在の最新版で試さなければと思って。

gdbのビルド

gdb本体をビルドするにはARMのクロスコンパイラは不要です。
gdb 8.0以降ではビルドするのに、C++-11 の規格のコンパイラが必要になっています。g++なら4.8以降。

wget http://ftp.jaist.ac.jp/pub/GNU/gdb/gdb-8.0.1.tar.gz
tar xf gdb-8.0.1.tar.gz

mkdir obj
cd obj
../gdb-8.0.1/configure --target=arm-buildroot-linux-gnueabi
make -j8
sudo make install

これで /usr/local/以下にインストールされます。

$ arm-buildroot-linux-gnueabi-gdb -v
GNU gdb (GDB) 8.0.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-buildroot-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".

gdbserverのビルド

ARMのクロスコンパイラが必要です。
今回はarm-buildroot-linux-gnueabi-gcc を使用します。

mkdir obj.gdbserver.arm
cd obj.gdbserver.arm
../gdb-8.0.1/gdb/gdbserver/configure --host=arm-buildroot-linux-gnueabi
make -j8
arm-buildroot-linux-gnueabi-strip gdbserver
$ file gdbserver
gdbserver: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.4.0, stripped
$ ls -l gdbserver
-rwxrwxr-x 1 koba koba 294016 Jan 11 11:22 gdbserver

gdbserverのスタティックリンク版のビルド

mkdir obj.gdbserver.arm.static
cd obj.gdbserver.arm.static
LDFLAGS=--static ../gdb-8.0.1/gdb/gdbserver/configure --host=arm-buildroot-linux-gnueabi
make -j8
arm-buildroot-linux-gnueabi-strip gdbserver
$ file gdbserver
gdbserver: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (GNU/Linux), statically linked, for GNU/Linux 3.4.0, stripped
$ ls -l gdbserver
-rwxrwxr-x 1 koba koba 1079556 Jan 11 11:24 gdbserver

スタティックリンク版は実行ファイルのサイズが大きくなりますが、実機のライブラリやABIが異なる環境でも動作可能です。
これを手札として持っていると、他のプロジェクトからの救援要請で早急にリモートデバッグ環境をセットアップしたいときに初動が早くなります。

9
9
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9