使用ubuntu24.4系统qemu-system-aarch64 +gdb-multiarch调试内核,设置断点无法停止

问题描述 投票:0回答:1

我在

qemu-system-aarch64 +gdb-multiarch
下使用Ubuntu 24.04系统来调试内核。但设置断点并不能让它停止。

系统信息:

  • Ubuntu版本:22.04
  • 调试内核版本:5.0.0
  • Qemu版本:
    qemu-system-aarch64 --version
    QEMU emulator version 8.2.2 (Debian 1:8.2.2+ds-0ubuntu1.2)
    Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers
    
  • GDB版本:
    gdb-multiarch --version
    GNU gdb (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git
    Copyright (C) 2024 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.
    

重现步骤:

  1. 使用qemu启动系统:
    qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -m 1024 -smp 4 -kernel arch/arm64/boot/Image --append "noinitrd root=/dev/vda rw console=ttyAMA0 loglevel=8" -nographic -drive if=none,file=rootfs_ext4.img,id=hd0 -device virtio-blk-device,drive=hd0 --fsdev local,id=kmod_dev,path=$PWD/kmodules,security_model=none -device virtio-9p-device,fsdev=kmod_dev,mount_tag=kmod_mount -S -s
    
  2. 使用gdb-multiarch连接并调试:
    gdb-multiarch vmlinux
    (gdb) target remote localhost:1234
    Remote debugging using localhost:1234
    
    0x0000000040000000 in ?? ()
    
    (gdb) b start_kernel
    Breakpoint 1 at 0xffff2000126704ec: file init/main.c, line 538.
    (gdb) c
    Continuing.
    

我尝试将调试好的Linux内核替换为5.10.9版本,但问题依然存在。我尝试用 GNU gdb (Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24)) 14.2.90.20240526-git 替换 gdb 工具,但问题仍然存在。

linux-kernel gdb qemu
1个回答
0
投票

那是因为您忘记禁用 KASLR。您放置的断点永远不会被命中,因为您从

vmlinux
获得的符号地址与运行时的真实地址不匹配,因为在启动时应用 KASLR 时,在
start_kernel()
之前,内核映像将被移动到内存中的其他位置调用。将
nokaslr
添加到内核命令行(QEMU 的
-append
选项),您将按预期命中断点。

© www.soinside.com 2019 - 2024. All rights reserved.