Subversion Repositories HelenOS-historic

Rev

Rev 1702 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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