OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 10:41 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Debug sections not loaded in memory
PostPosted: Wed Jan 06, 2016 9:44 pm 
Offline
Member
Member

Joined: Mon Dec 21, 2015 7:09 pm
Posts: 38
All,

I cannot manage to load the kernel symbols in memory. objdump shows the various debug sections exists in my kernel:

Code:
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00004011  00100000  00100000  00001000  2**12
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .rodata       00000392  00105000  00105000  00006000  2**12
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 .eh_frame     00000e28  00105394  00105394  00006394  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .data         000002e0  00107000  00107000  00008000  2**12
                  CONTENTS, ALLOC, LOAD, DATA
  4 .bss          00138fd4  00108000  00108000  000082e0  2**12
                  ALLOC
  5 .bootstrap_stack, 00004000  00240fd4  00240fd4  000082e0  2**2
                  ALLOC, READONLY
  6 .debug_line   00001270  00245000  00245000  00009000  2**12
                  CONTENTS, READONLY, DEBUGGING
  7 .debug_str    00002c41  00247000  00247000  0000b000  2**12
                  CONTENTS, READONLY, DEBUGGING
  8 .debug_info   00003c90  0024a000  0024a000  0000e000  2**12
                  CONTENTS, READONLY, DEBUGGING
  9 .debug_abbrev 000013f0  0024e000  0024e000  00012000  2**12
                  CONTENTS, READONLY, DEBUGGING
10 .debug_aranges 000001b8  00250000  00250000  00014000  2**12
                  CONTENTS, READONLY, DEBUGGING
11 .debug_macro  000009dc  00000000  00000000  000141b8  2**0
                  CONTENTS, READONLY, DEBUGGING
12 .comment      00000011  00000000  00000000  00014b94  2**0
                  CONTENTS, READONLY


I defined those sections in link.ld, and do see the sections boundaries in memory (debug_line starts at 0x00245000, debug_str starts at 0x00247000, etc.). However, when I look at what's in memory it's mostly empty. The few areas not filled with zeros look nothing like what objdump -s shows.

Did I forget anything? Am I supposed to configure GRUB Legacy to load debug symbols? The GRUB flags I use are 0x3.

Thanks


Top
 Profile  
 
 Post subject: Re: Debug sections not loaded in memory
PostPosted: Thu Jan 07, 2016 11:01 am 
Offline
Member
Member

Joined: Tue May 13, 2014 3:02 am
Posts: 280
Location: Private, UK
ELF program headers define what actually gets loaded into memory, not the section headers. "objdump -p" is the command to list those.

The linker will only create program headers for the sections that it believes are necessary to run the program. Debug sections are supposed to contain data for a debugger and are meant to be able to be removed safely with a utility like "strip", so aren't considered necessary and aren't loaded by the ld-generated program headers.

If you want them loaded you'll have to instruct ld to include them in the program headers using a "PHDRS" command in your link.ld file.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Debug sections not loaded in memory
PostPosted: Thu Jan 07, 2016 6:45 pm 
Offline
Member
Member

Joined: Mon Dec 21, 2015 7:09 pm
Posts: 38
It works, thanks a lot! Interestingly, I need to only put debug_info in the PHDRS section - trying to add debug_lines generates something which is not accepted by GRUB.

Next step: reverse engineer addr2line to understand how it's reading DWARF.


Top
 Profile  
 
 Post subject: Re: Debug sections not loaded in memory
PostPosted: Thu Jan 07, 2016 10:07 pm 
Offline
Member
Member

Joined: Mon Dec 21, 2015 7:09 pm
Posts: 38
By the way, are there some specific things to load and not to load in PHDRS? I tried to load just debug_info as it was the combination that both works and where addr2line doesn't crap out, but at the debug_info address I have what seems to be the content of debug_abbrev, debug_line and part of debug_string.

What I'm trying to do is to generate a readable stack trace. Right now I get the code address for each stack frame by programmatically going through the stack (I can then translate using with addr2line). Ideally I'd like to generate the function name and line number - but I realize that's a tall order.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 61 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group