QEMU+GDB
前回の続き
QEMUをGDB接続待ち状態にすること自体は容易だが、複数コアをエミュレートしている時にCortex-R5で動くコードをGDBでステップ実行できるのか?
結果今のところうまくいっていないがどこまでやったかを記載する。
gdb-multiarchのインストール
WSL2上でARM向けELFのデバッグを行うのでgdb-multiarchを用いる。
sudo apt-get install gdb-multiarch
とりあえずつないでみる
QEMU側の起動
cd $WORKSPACE/qemu-ug-examples/BareMetal_examples/bare_metal_r5
vi test.sh
test.shのqemu-system-aarch64実行のオプションに以下を加える。
-s: GDB からの接続を、 localhost:1234 で待ち受ける
-S: 起動と同時に一時停止する
実行
cd $WORKSPACE/qemu-ug-examples/BareMetal_examples/bare_metal_r5
./test.sh $WORKSPACE/qemu/build/aarch64-softmmu $WORKSPACE/qemu-devicetrees/LATEST/SINGLE_ARCH
GDB接続を待ち受け、前回記事で見たようなHello Worldの出力はない。
GDB
別ウィンドウで以下実行
gdb-multiarch hello_uart_lowv.elf
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 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 "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://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"...
Reading symbols from r5_stl_tests.elf...
(gdb) target remote :1234
これはうまくいかない
Remote debugging using :1234
warning: Selected architecture armv7 is not compatible with reported target architecture aarch64
warning: Architecture rejected target-supplied description
Remote 'g' packet reply is too long (expected 168 bytes, got 268 bytes): 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cd030040
ELFがarmv7でターゲットがaarch64であることでwarningが出てる。
一応順序を逆にしてみると
gdb-multiarch
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 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 "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://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".
(gdb) target remote :1234
Remote debugging using :1234
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x0000000000000000 in ?? ()
(gdb) file hello_uart_lowv.elf
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
warning: Selected architecture armv7 is not compatible with reported target architecture aarch64
Architecture of file not recognized.
やはりうまくいかない。とりあえず実行してみても何も起きない。
(gdb) c
Continuing.
このエミュレータはVersalのようで、Cortex-A72が2コア、Cortex-R5Fが2コアで構成されている
(qemu) info cpus
* CPU #0: thread_id=1652
CPU #1: thread_id=1653
CPU #2: thread_id=1654
CPU #3: thread_id=1655
しかしGDB側でinfo threadsで確認するとCortex-A72しか見えない。
(gdb) info threads
Id Target Id Frame
* 1 Thread 1.1 (Cortex-A72 #0 [running]) 0x0000000000000000 in ?? ()
2 Thread 1.2 (Cortex-A72 #1 [running]) 0x0000000000000000 in ?? ()