Subversion Repositories HelenOS-historic

Rev

Rev 1264 | Rev 1705 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
268 palkovsky 1
/*
2
 * Copyright (C) 2005 Ondrej Palkovsky
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
1702 cejka 29
 /** @defgroup debug Debug
30
 * @ingroup kernel
31
 * @{
32
 * @}
33
 */
34
 
35
 
36
 /** @addtogroup genericdebug generic
37
 * @ingroup debug
38
 * @{
39
 */
40
 
1264 jermar 41
/**
1702 cejka 42
 * @file
1264 jermar 43
 * @brief   Kernel symbol resolver.
44
 */
268 palkovsky 45
 
46
#include <symtab.h>
47
#include <typedefs.h>
292 jermar 48
#include <arch/byteorder.h>
582 palkovsky 49
#include <func.h>
50
#include <print.h>
268 palkovsky 51
 
1264 jermar 52
/** Return entry that seems most likely to correspond to argument.
268 palkovsky 53
 *
404 jermar 54
 * Return entry that seems most likely to correspond
55
 * to address passed in the argument.
56
 *
57
 * @param addr Address.
58
 *
59
 * @return Pointer to respective symbol string on success, NULL otherwise.
268 palkovsky 60
 */
61
char * get_symtab_entry(__native addr)
62
{
63
    count_t i;
64
 
292 jermar 65
    for (i=1;symbol_table[i].address_le;++i) {
338 jermar 66
        if (addr < __u64_le2host(symbol_table[i].address_le))
268 palkovsky 67
            break;
68
    }
338 jermar 69
    if (addr >= __u64_le2host(symbol_table[i-1].address_le))
268 palkovsky 70
        return symbol_table[i-1].symbol_name;
71
    return NULL;
72
}
582 palkovsky 73
 
1264 jermar 74
/** Find symbols that match the parameter forward and print them.
601 palkovsky 75
 *
76
 * @param name - search string
77
 * @param startpos - starting position, changes to found position
78
 * @return Pointer to the part of string that should be completed or NULL
79
 */
80
static char * symtab_search_one(const char *name, int *startpos)
81
{
82
    int namelen = strlen(name);
83
    char *curname;
84
    int i,j;
85
    int colonoffset = -1;
86
 
87
    for (i=0;name[i];i++)
88
        if (name[i] == ':') {
89
            colonoffset = i;
90
            break;
91
        }
92
 
93
    for (i=*startpos;symbol_table[i].address_le;++i) {
94
        /* Find a ':' in name */
95
        curname = symbol_table[i].symbol_name;
96
        for (j=0; curname[j] && curname[j] != ':'; j++)
97
            ;
98
        if (!curname[j])
99
            continue;
100
        j -= colonoffset;
101
        curname += j;
102
        if (strlen(curname) < namelen)
103
            continue;
104
        if (strncmp(curname, name, namelen) == 0) {
105
            *startpos = i;
106
            return curname+namelen;
107
        }
108
    }
109
    return NULL;
110
}
111
 
582 palkovsky 112
/** Return address that corresponds to the entry
113
 *
601 palkovsky 114
 * Search symbol table, and if there is one match, return it
582 palkovsky 115
 *
116
 * @param name Name of the symbol
117
 * @return 0 - Not found, -1 - Duplicate symbol, other - address of symbol
118
 */
119
__address get_symbol_addr(const char *name)
120
{
121
    count_t found = 0;
601 palkovsky 122
    __address addr = NULL;
123
    char *hint;
124
    int i;
582 palkovsky 125
 
601 palkovsky 126
    i = 0;
127
    while ((hint=symtab_search_one(name, &i))) {
128
        if (!strlen(hint)) {
129
            addr =  __u64_le2host(symbol_table[i].address_le);
582 palkovsky 130
            found++;
131
        }
601 palkovsky 132
        i++;
582 palkovsky 133
    }
601 palkovsky 134
    if (found > 1)
135
        return ((__address) -1);
136
    return addr;
582 palkovsky 137
}
138
 
601 palkovsky 139
/** Find symbols that match parameter and prints them */
582 palkovsky 140
void symtab_print_search(const char *name)
141
{
142
    int i;
143
    __address addr;
144
    char *realname;
145
 
601 palkovsky 146
 
147
    i = 0;
148
    while (symtab_search_one(name, &i)) {
149
        addr =  __u64_le2host(symbol_table[i].address_le);
150
        realname = symbol_table[i].symbol_name;
1224 cejka 151
        printf("%.*p: %s\n", sizeof(__address) * 2, addr, realname);
601 palkovsky 152
        i++;
153
    }
154
}
155
 
156
/** Symtab completion
157
 *
1248 jermar 158
 * @param input - Search string, completes to symbol name
601 palkovsky 159
 * @returns - 0 - nothing found, 1 - success, >1 print duplicates
160
 */
616 palkovsky 161
int symtab_compl(char *input)
601 palkovsky 162
{
163
    char output[MAX_SYMBOL_NAME+1];
164
    int startpos = 0;
165
    char *foundtxt;
166
    int found = 0;
167
    int i;
616 palkovsky 168
    char *name = input;
601 palkovsky 169
 
616 palkovsky 170
    /* Allow completion of pointers  */
171
    if (name[0] == '*' || name[0] == '&')
172
        name++;
173
 
601 palkovsky 174
    /* Do not print everything */
175
    if (!strlen(name))
176
        return 0;
616 palkovsky 177
 
601 palkovsky 178
 
179
    output[0] = '\0';
180
 
181
    while ((foundtxt = symtab_search_one(name, &startpos))) {
182
        startpos++;
183
        if (!found)
184
            strncpy(output, foundtxt, strlen(foundtxt)+1);
185
        else {
186
            for (i=0; output[i] && foundtxt[i] && output[i]==foundtxt[i]; i++)
187
                ;
188
            output[i] = '\0';
582 palkovsky 189
        }
601 palkovsky 190
        found++;
582 palkovsky 191
    }
601 palkovsky 192
    if (!found)
193
        return 0;
194
 
602 palkovsky 195
    if (found > 1 && !strlen(output)) {
601 palkovsky 196
        printf("\n");
197
        startpos = 0;
198
        while ((foundtxt = symtab_search_one(name, &startpos))) {
199
            printf("%s\n", symbol_table[startpos].symbol_name);
200
            startpos++;
201
        }
202
    }
616 palkovsky 203
    strncpy(input, output, MAX_SYMBOL_NAME);
601 palkovsky 204
    return found;
205
 
582 palkovsky 206
}
1702 cejka 207
 
208
 /** @}
209
 */
210