Accessing Symbol Table from within program

Programming, for all ages and all languages.
Post Reply
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Accessing Symbol Table from within program

Post by thepowersgang »

I'm working on doing stack back tracing in my OS and want to be able to read the symbol table from the error handler. Is there a way of getting the address of the symbol table at compile time via a linker variable or the such?
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Accessing Symbol Table from within program

Post by AJ »

Hi,

What format are you using? If you are using ELF, this is quite easy and symbols will be added with LD unless you use the -s switch. Reading the headers, you need to read the string table. The symbol table then uses pointers in to the string table to provide symbol names.

With PE/COFF, I guess there must be a similar way.

Cheers,
Adam
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Accessing Symbol Table from within program

Post by thepowersgang »

The problem is this is my kernel so afik the ELF header is not loaded by grub. Could it be possible to use a linker script to copy the symbol table to the data section?
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: Accessing Symbol Table from within program

Post by Stevo14 »

If you are able to read files off of the disk (or floppy, wherever your kernel's ELF file is located), then you could just load the ELF file off of the disk, extract the string and symbol tables, and put them at some known address for your error handlers to find (discarding the rest of the file to save space). Alternatively, you could have grub load your kernel's ELF file as a module and do the same thing to it.
Post Reply