How to use add-symbol-file in gdb after the program jumped to linux? (both when PC is physical and virtual)

Chan Kim ckim at etri.re.kr
Wed Jan 12 08:43:27 CET 2022


Hello experts,

 

I'm following linux boot-loading using u-boot (using SPL falcon mode, from
RAM) on a qemu virtual machine (now linux started in real board too). The
code jumped to linux kernel and because I have done `add-symbol-file vmlinux
0x80081000` I can follow the kernel code step by step using gdb connected to
the virtual machine. Actually I loaded the kernel image to 0x80080000 but I
had to set the address to 0x80081000 to make the source code appear on the
gdb correctly according to the PC value(I don't know why this difference of
0x1000 is needed).  

Later I found the kernel sets up the page table (identity mapping and swap
table) and jumps to `__primary_switched` and this is where pure kernel
virtual address is used first time for the PC. This is where the call is
made at the end of the head.S file.  

 

    ldr x8, =__primary_switched

    adrp    x0, __PHYS_OFFSET

    br  x8

 

In the symbol file (vmlinux, an elf file), the symbols before
__primary_switched are all mapped at virtual addresses (starting with
0xffffffc0..... high addresses) but the gdb could follow the source even
when the PC value was using physical address. (The PC was initially loaded
with physical address of the kernel start and PC relative jumps were being
used until it jumps to `__primary_switched`, mmu disabled or using identity
mapping) So does this mean, in doing `add-symbol-file` only the offset of
the symbols from the start of text matters?  

Another question : I can follow the kernel source with gdb but after
__primary_switched, I cannot see the source. The debugger doesn't show the
correct source location according to the now kernel virtual PC value. Should
I tell the debugger to use correct offset using add-symbol-file again? if so
how?

 

I would be happy to hear any comment or advice.

Thank you!

 

Chan Kim

 



More information about the U-Boot mailing list