I’m using lldb connect QEMU to debug linux kernel. The linux kernel been load to 0x40200000, So I have to use target modules load to defining load addresses for sections. But when set this, the hardware breakpoint can’t be hint. Is is a bug?
-
Build the latest linux kernel for ARM64.
-
Launch QEMU to debug kernel
qemu-system-aarch64 -machine virt,accel=hvf -cpu host
-kernel arch/arm64/boot/Image
-append "nokaslr"
-nographic
-m 2G
-s
-S
- Launch lldb and connect to QEMU
lldb vmlinux
(lldb) gdb-remote 1234
(lldb) breakpoint set -H -a 0x41e300e8
(lldb) c
- This will successfully hint this breakpoint. But when use
target modules load
to specify debug symbol addresses for sections.
(lldb) target modules load --file vmlinux .head.text 0x40200000 .text 0x40210000 .rodata.text 0x41e2b800 .init.text 0x41e40000
the section load address .text 0x40210000 .rodata.text 0x41e2b800 .init.text 0x41e40000 may be different when linux version is different. You need use readelf to virtual address in vmlinux. and calculate:
Section load address = Sections start address - (Linux Entry address - Qemu load address)
e.g. .rodata.text
readelf -S out/arm64/vmlinux
There are 51 section headers, starting at offset 0x17316b88:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 1] .head.text PROGBITS ffff800080000000 010000 010000 00 AX 0 0 65536
[19] .rodata.text PROGBITS ffff800081c2b800 1c3b800 005800 00 AX 0 0 2048
0xffff800081c2b800 - ( 0xffff800080000000 - 0x40200000) = 0x41e2b800
- After set this. The breakpoint will not be hit regardless of whether the virtual or physical address is used to set the breakpoint.
set breakpoint by physical address:
(lldb) breakpoint set -H -a 0x41e300f4
set breakpoint by virtual address:
(lldb) breakpoint set -H -a 0xffff800081c300f4
(lldb) c
The breakpoint will not be hit now!!!
- My environment is:
OS: Mac OS 14.5
PC: Macbook Pro M2 Max
QEMU: 9.0.1
LLDB: 18.1.7
Linux kernel version: 6.10-rc4
I have search by google and lldb’s github project. But there was no solution. How to set breakpoint after use target modules load
to specify debug symbol addresses for sections. Or this is a bug of lldb?