lpoulain
Posts: 14
Joined: Mon May 20, 2019 12:35 am

Loading DWARF info in the kernel memory

Sat Jun 15, 2019 4:17 am

All,

Does anybody know how to load debugging information in the kernel memory?

I built my kernel to have debugging information, and running aarch64-none-elf-objdump --debugging kernel8.elf does display the DWARF information (.debug_str, .debug_abbrev, etc.)

However, when loading the kernel, I cannot manage to get this information in memory. I tried to tweak with the link.ld, e.g.

Code: Select all

.debug_str : { 
    . = ALIGN(4);
    __debug_str__ = .;
     *(.debug_str .debug_str.*)
}
To no avail. Any help will be appreciated.

bzt
Posts: 345
Joined: Sat Oct 14, 2017 9:57 pm

Re: Loading DWARF info in the kernel memory

Sat Jun 15, 2019 12:54 pm

Hi,

You question is somewhat vague, because there's no ELF loader to load a kernel. There's a step with objconv, when you convert the ELF into IMG by cropping out the text segment. Therefore you have to put the debug info into the text segment. For that, you have two options:

1. put your debug info in the text section, which section goes into the text segment anyway

Code: Select all

.text : {
    ...
    . = ALIGN(4);
    __debug_str__ = .;
     *(.debug_str .debug_str.*)
}

2. (and this is more preferable), give name to the text segment and tell your linker to put not only the text and read-only data sections, but the debug sections too into that segment.

Code: Select all

PHDRS
{
  text PT_LOAD FILEHDR PHDRS;
}
...
.debug_str : { 
    . = ALIGN(4);
    __debug_str__ = .;
     *(.debug_str .debug_str.*)
} :text
Please note that I've used "section" and "segment" consistently, because that matters. ".text" section is not the same as ":text" segment. You can verify the correspondence with "readelf", after the program headers block, there's a list like this:

Code: Select all

 Section to Segment mapping:
  Segment Sections...
   00     .text .got .got.plt .bss .debug_str
Cheers,
bzt

lpoulain
Posts: 14
Joined: Mon May 20, 2019 12:35 am

Re: Loading DWARF info in the kernel memory

Mon Jun 17, 2019 12:00 am

Thanks, it seems to work. Next step is to adapt my old code to read the DWARF info.

lpoulain
Posts: 14
Joined: Mon May 20, 2019 12:35 am

Re: Loading DWARF info in the kernel memory

Sun Jun 23, 2019 1:23 am

After some further coding, I found that the DWARF generated code is slightly different than what is expected.

Code: Select all

> aarch64-none-elf-readelf -wi kernel8.elf 
Contents of the .debug_info section:

  Compilation Unit @ offset 0x0:
   Length:        0x1e (32-bit)
   Version:       2
   Abbrev Offset: 0x38c1e0
   Pointer Size:  8
readelf: Warning: Debug info is corrupted, abbrev offset (38c1e0) is larger than abbrev section size (2fb0)
 <0><b>: Abbrev Number: 1
readelf: Warning: DIE at offset 0xb refers to abbreviation number 1 which does not exist
The .debug_info header contains an invalid abbrev offset. This is supposed to be the the offset of the Compilation Unit inside the .debug_abbrev section (which should be 0), but it is instead the offset in the whole executable (0x38c1e0 is the address of the .debug_abbrev section). I'm trying to generate a full DWARF information output to better troubleshoot when my code is going wrong.

I was wondering if you have managed to build an AARCH64 .elf file where readelf -wi or objdump -g generate the .debug_info section without error.

Return to “Bare metal, Assembly language”