エミュレータ上で実行しているAndroidカーネルをDDDでデバッグするときブレークできない

400 views
Skip to first unread message

ksky

unread,
Jan 15, 2015, 1:21:11 AM1/15/15
to android-g...@googlegroups.com
初めて投稿させていただきます。
このフォーラムで適切か確信がないですが、ご助言いただけますと幸いです。

エミュレータ上で起動したAndroidカーネルをDDD(GDB)でデバッグしようとしているのですが、
設定したブレークポイントで止まってくれず困っています。

以下に基本情報と実施した操作を記します。
使用するツールはこれで適切か、設定に不備がないかをご教示ください。

また、不足している情報がありましたらご指摘お願いいたします。

<基本情報>
HostOS: Ubuntu14.04 64bit LTS
GCC: 4.8.2
Make: 3.8.1
Emulator(QEMU): 0.10.50Android
DDD: 3.3.12
GDB: 7.7.1
Android(Linux)Kernel: 2.6.29


<操作>
●ターゲットをARMに指定して、ビルドオプションを設定してカーネルをビルド
$ export ARCH=arm
$ export SUBARCH=arm
$ export CROSS_COMPILE=arm-eabi-
$ make goldfish_armv7_defconfig
$ make menuconfig

Linux Kernel Configuration
  Kernel hacking
    [Y]Compile the kernel with debug info

$ make -j8


●Androidエミュレータをデバッグオプションを付けて起動
$ emulator -kernel goldfish/arch/arm/boot/zImage -qemu -s -S

●DDDを起動しエミュレータに接続
$ DDD vmlinux
GNU DDD 3.3.12 (x86_64-pc-linux-gnu), by Dorothea LReading symbols from vmlinux...done.
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
warning: Architecture rejected target-supplied description
Could not fetch register "st2"; remote failure reply 'E14'
0x00000000 in ?? ()

●ブレークポイントをstart_kernel()に設定
(gdb) b start_kernel
Breakpoint 1 at 0xc00086a4: file init/main.c, line 531.
(gdb) continue
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.#←SIGTRAPが発行され、設定した以外の場所でブレイクする
0x00021d78 in ?? ()
(gdb)

●一度SIGTRAPを受けると、ブレークポイントを外さない限り他の操作が受け付けられない
(gdb) next
Cannot find bounds of current function
(gdb) step
Cannot find bounds of current function
(gdb) continue
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.#←SIGTRAPが発行され設定した以外の場所でブレイクする。
0x00021d78 in ?? ()
(gdb)

以上です。よろしくお願いします。

Akihiko Seino

unread,
Jan 15, 2015, 8:00:16 AM1/15/15
to android-g...@googlegroups.com

はじめまして。

DDDを起動してからエミュレータを起動しないとそこには止まらない気がします。

ksky

unread,
Jan 15, 2015, 8:33:05 PM1/15/15
to android-g...@googlegroups.com
せんべいさん、ありがとうございます。
DDDを起動→エミュレータ起動の順で試してみましたが、やはり無関係な箇所でSIGTRAPが発生しました。
なお、QEMUの-Sオプションをつけているため、エミュレータはDDDで接続するまで起動処理で止まってくれるはずと考えています。

$ emulator -qemu -h

QEMU PC emulator version 0.10.50Android, Copyright (c) 2003-2008 Fabrice Bellard
(中略)
Debug/Expert options:
-serial dev     redirect the serial port to char device 'dev'
-parallel dev   redirect the parallel port to char device 'dev'
-monitor dev    redirect the monitor to char device 'dev'
-pidfile file   write PID to 'file'
-singlestep   always run in singlestep mode
-S              freeze CPU at startup (use 'c' to start execution)


手順は下記のページを参考にしました(カーネルのバージョン違いのためビルドオプションがいくつか異なります)。

2015年1月15日木曜日 22時00分16秒 UTC+9 せんべい:

はじめまして。

DDDを起動してからエミュレータを起動しないとそこには止まらない気がします。

ksky

unread,
Jan 16, 2015, 3:35:31 AM1/16/15
to android-g...@googlegroups.com
GDB本体のターゲットアーキテクチャを確認したところ、i386系となっていることが分かったため、
armにビルドし直すことで無事解決いたしました。

以下の通り実施しました。

●GDBで使用できるアーキテクチャの確認

$ ddd ~/android/goldfish/vmlinux    #DDD起動

GNU DDD 3.3.12 (x86_64-pc-linux-gnu), by Dorothea LReading symbols from /home/ksky/android/goldfish/vmlinux...done.
(gdb) set arch
Requires an argument. Valid arguments are i386, i386:x86-64, i386:x64-32, i8086, i386:intel, i386:x86-64:intel, i386:x64-32:intel, i386:nacl, i386:x86-64:nacl, i386:x64-32:nacl, auto.   #一覧の中に"arm"が入っていない
(gdb)


●GDBをクロスデバッガとしてビルドし直す
cd /tmp
tar xjvf gdb-7.7.1.tar.bz2

cd gdb-7.7.1/
./configure --prefix=/opt/gdb/arm --target=arm-eabi   #ターゲットにarm-eabiを指定
make -j8
sudo make install

export PATH=/opt/gdb/arm/bin:$PATH       #arm-eabi-gdbコマンドにパスを通す

●arm-eabi-gdbを指定してDDD起動
ddd ~/android/goldfish/vmlinux --debugger arm-eabi-gdb

●アーキテクチャにarmが含まれていることを確認
GNU DDD 3.3.12 (x86_64-pc-linux-gnu), by Dorothea LReading symbols from /home/ksky/android/goldfish/vmlinux...done.
(gdb) set arch
Requires an argument. Valid arguments are arm, armv2, armv2a, armv3, armv3m, armv4, armv4t, armv5, armv5t, armv5te, xscale, ep9312, iwmmxt, iwmmxt2, auto.

●エミュレータに接続、ブレイクポイントを設定して続行
(gdb) b start_kernel
Breakpoint 1 at 0xc00086a4: file init/main.c, line 531.
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
warning: Can not parse XML target description; XML support was disabled at compile time
0x00000000 in ?? ()
(gdb) continue
Continuing.

Breakpoint 1, start_kernel () at init/main.c:531
(gdb) 

2015年1月16日金曜日 10時33分05秒 UTC+9 ksky:
Reply all
Reply to author
Forward
0 new messages