Accessing Symbol Table from within program
- thepowersgang
- 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
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
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Re: Accessing Symbol Table from within program
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
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
- thepowersgang
- 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
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
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Re: Accessing Symbol Table from within program
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.
~[Fluidium]~