QEMU による Linux カーネルのデバッグ手順 - 2023.1 日本語

PetaLinux ツール資料: リファレンス ガイド (UG1144)

Document ID
UG1144
Release Date
2023-05-16
Version
2023.1 日本語
  1. 次のコマンドを実行し、現在ビルド済みの Linux を使用して QEMU を起動します。
    petalinux-boot --qemu --kernel
  2. QEMU のコンソールを確認します。QEMU コマンドの詳細を表示します。-gdb tcp:<TCP_PORT> から GDB TCP を取得します。
  3. PetaLinux の settings スクリプトが実行済みであることを確認して別のコマンド コンソールを開き、Linux ディレクトリに移動します。
    cd "<plnx-proj-root>/images/linux"
  4. vmlinux カーネル イメージに対してコマンド モードで GDB を起動します。
    petalinux-util --gdb vmlinux

    GDB プロンプトが表示されます。次に例を示します。

    petalinux-util --gdb vmlinux
    GNU gdb (GDB) 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 "--host=x86_64-petalinux-linux --target=aarch64-xilinx-linux".
    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 vmlinux...
    (No debugging symbols found in vmlinux)
    (gdb)
    
  5. 次の GDB コマンドを実行し、GDB で QEMU ターゲットに接続します。
    (gdb) target remote :9000
  6. QEMU の実行を継続します。
    (gdb) continue
  7. Ctrl+C を押すとカーネル実行を中断して GDB プロンプトに戻ることができます。
  8. ブレークポイントを設定し、ほかの GDB コマンドを実行してカーネルをデバッグできます。
注意:
ポート 9000 がほかのプロセスで使用中の場合、petalinux-boot で別のポートの使用が試みられます。petalinux-boot の出力を見て、どのポートが使用されているかを確認してください。たとえば、「INFO: qemu-system-arm ... -gdb tcp::9001 ...」と表示される場合は、ポート 9001 が使用されています。
ヒント: カーネル コンフィギュレーション メニューで petalinux-config --kernel > Kernel hacking > Kernel debugging を選択してカーネル デバッグを有効にし、カーネル デバッグ シンボルをイメージに含めることを推奨します。