LoginSignup
1
1

More than 3 years have passed since last update.

RISC-Vエミュレータ上で動作するリアルタイムOSに対してデバッガを使う(QEMU + NuttX + GDB)

Last updated at Posted at 2020-01-11

前回の記事 の続きの小ネタです。

手順

ビルドを終えてnuttxバイナリが作られたディレクトリに移動します。
まず、QEMUを実行します。
QEMU実行時には -s-S のオプションを用います。

$ qemu-system-riscv32 -s -S -nographic -machine sifive_e -kernel ./nuttx
オプション 意味
-s shorthand for -gdb tcp::1234
-S freeze CPU at startup (use 'c' to start execution)

-S を指定したため待ってくれているのでその状態で、別のウィンドウからGDBを実行します。

$ riscv64-unknown-elf-gdb ./nuttx -ex "target remote localhost:1234"

そのときに

Reading symbols from ./nuttx...

というシンボルを読み込んでいる表示が見られるはずです。

ビルド時にデバッグシンボルを含めるには、コンフィグDEBUG_SYMBOLSを有効にする必要があります。
hifive1-revb:nsh ではデフォルトで有効になっていました。

debug_symbols.png

あとは好きにブレークポイントを設定するなどしてください。
以下は例

(gdb) b nsh_main
Breakpoint 1 at 0x20403972: file nsh_main.c, line 218.
(gdb) c
Continuing.

Breakpoint 1, nsh_main (argc=1, argv=0x80002128) at nsh_main.c:218
218       (void)sched_getparam(0, &param);
(gdb)
1
1
0

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
1
1