root/Whitix/trunk/kernel/symbols.c

Revision 1979, 2.8 KB (checked in by mwhitworth, 3 years ago)

Don't print anything if we can't resolve to a name.

Line 
1/*  This file is part of Whitix.
2 *
3 *  Whitix is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  Whitix is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with Whitix; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 */
18
19#include <config.h>
20#include <console.h>
21#include <elf.h>
22#include <module.h>
23#include <sections.h>
24#include <symbols.h>
25#include <print.h>
26
27#ifdef CONFIG_ALL_SYMBOLS
28
29#define KERNEL_BASE_ADDRESS             0x100000
30#define DATA __attribute__((section(".data")))
31
32static struct ElfSymbol* symTable DATA;
33static int symTableSize DATA;
34static char* strTable DATA;
35static int strTableSize DATA;
36
37const char* SymbolLookup(char* stringTable, struct ElfSymbol* symbolTable, int symSize, DWORD address, DWORD* size, DWORD* offset)
38{
39        DWORD i=0;
40        struct ElfSymbol* currSym=NULL;
41        struct ElfSymbol* symbol=NULL;
42        DWORD currOffset=~0;
43
44        while (i < (symSize/sizeof(struct ElfSymbol)))
45        {
46                symbol=&symbolTable[i++];
47
48                if (ELF_ST_TYPE(symbol->symInfo) != STT_FUNC)
49                        continue;
50
51                if (address-symbol->symValue > currOffset)
52                        continue;
53
54                currOffset=address-symbol->symValue;
55
56                currSym=symbol;
57        }
58
59        if (!currSym)
60                return NULL;
61
62        *offset=currOffset;
63        *size=currSym->symSize;
64
65        if (*offset > *size)
66                return NULL;
67
68        return stringTable+currSym->symName;
69}
70
71void SymbolPrint(DWORD address)
72{
73        DWORD size, offset;
74        const char* name;
75
76        name = SymbolLookup(strTable, symTable, symTableSize, address, &size, &offset);
77
78        if (name)
79                KePrint("%s+%#X/%#X\n", name, offset, size);
80        else
81                KePrint("%#X\n", address);
82}
83
84SYMBOL_EXPORT(SymbolPrint);
85
86void SymbolsCopy()
87{
88        DWORD sectionAddr, numEntries;
89        struct ElfSectionHeader* sectionHeaders;
90        int i;
91       
92        EarlyConsoleInit();
93        ArchGetSectionInfo(&sectionAddr, &numEntries);
94       
95        sectionHeaders=(struct ElfSectionHeader*)sectionAddr;
96
97        /* Search the section headers for the symbol and string tables. */
98        for (i=1; i<numEntries; i++)
99        {
100                struct ElfSectionHeader* curr=&sectionHeaders[i];
101               
102                if (curr->shType == SEC_TYPE_SYMTAB)
103                {
104                        symTable=(struct ElfSymbol*)(curr->shAddr);
105                        symTableSize=curr->shSize;
106                }else if (curr->shType == SEC_TYPE_STRTAB)
107                {
108                        strTable=(char*)(curr->shAddr);
109                        strTableSize=curr->shSize;
110                }
111        }
112}
113
114#else
115/* Stub functions. */
116
117void SymbolPrint(DWORD address)
118{
119        KePrint("%10X\n", address);
120}
121
122void SymbolsCopy()
123{
124}
125
126#endif
Note: See TracBrowser for help on using the browser.