Subversion Repositories HelenOS

Rev

Rev 2745 | Rev 2927 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2745 Rev 2797
Line 34... Line 34...
34
 * @file
34
 * @file
35
 * @brief   Kernel symbol resolver.
35
 * @brief   Kernel symbol resolver.
36
 */
36
 */
37
 
37
 
38
#include <symtab.h>
38
#include <symtab.h>
39
#include <arch/byteorder.h>
39
#include <byteorder.h>
40
#include <func.h>
40
#include <func.h>
41
#include <print.h>
41
#include <print.h>
42
 
42
 
43
/** Return entry that seems most likely to correspond to argument.
43
/** Return entry that seems most likely to correspond to argument.
44
 *
44
 *
Line 51... Line 51...
51
 */
51
 */
52
char * get_symtab_entry(unative_t addr)
52
char * get_symtab_entry(unative_t addr)
53
{
53
{
54
    count_t i;
54
    count_t i;
55
 
55
 
56
    for (i=1;symbol_table[i].address_le;++i) {
56
    for (i = 1; symbol_table[i].address_le; ++i) {
57
        if (addr < uint64_t_le2host(symbol_table[i].address_le))
57
        if (addr < uint64_t_le2host(symbol_table[i].address_le))
58
            break;
58
            break;
59
    }
59
    }
60
    if (addr >= uint64_t_le2host(symbol_table[i-1].address_le))
60
    if (addr >= uint64_t_le2host(symbol_table[i - 1].address_le))
61
        return symbol_table[i-1].symbol_name;
61
        return symbol_table[i - 1].symbol_name;
62
    return NULL;
62
    return NULL;
63
}
63
}
64
 
64
 
65
/** Find symbols that match the parameter forward and print them.
65
/** Find symbols that match the parameter forward and print them.
66
 *
66
 *
Line 70... Line 70...
70
 */
70
 */
71
static char * symtab_search_one(const char *name, int *startpos)
71
static char * symtab_search_one(const char *name, int *startpos)
72
{
72
{
73
    unsigned int namelen = strlen(name);
73
    unsigned int namelen = strlen(name);
74
    char *curname;
74
    char *curname;
75
    int i,j;
75
    int i, j;
76
    int colonoffset = -1;
76
    int colonoffset = -1;
77
 
77
 
78
    for (i=0;name[i];i++)
78
    for (i = 0; name[i]; i++)
79
        if (name[i] == ':') {
79
        if (name[i] == ':') {
80
            colonoffset = i;
80
            colonoffset = i;
81
            break;
81
            break;
82
        }
82
        }
83
 
83
 
84
    for (i=*startpos;symbol_table[i].address_le;++i) {
84
    for (i = *startpos; symbol_table[i].address_le; ++i) {
85
        /* Find a ':' in name */
85
        /* Find a ':' in name */
86
        curname = symbol_table[i].symbol_name;
86
        curname = symbol_table[i].symbol_name;
87
        for (j=0; curname[j] && curname[j] != ':'; j++)
87
        for (j = 0; curname[j] && curname[j] != ':'; j++)
88
            ;
88
            ;
89
        if (!curname[j])
89
        if (!curname[j])
90
            continue;
90
            continue;
91
        j -= colonoffset;
91
        j -= colonoffset;
92
        curname += j;
92
        curname += j;
93
        if (strlen(curname) < namelen)
93
        if (strlen(curname) < namelen)
94
            continue;
94
            continue;
95
        if (strncmp(curname, name, namelen) == 0) {
95
        if (strncmp(curname, name, namelen) == 0) {
96
            *startpos = i;
96
            *startpos = i;
97
            return curname+namelen;
97
            return curname + namelen;
98
        }
98
        }
99
    }
99
    }
100
    return NULL;
100
    return NULL;
101
}
101
}
102
 
102
 
Line 113... Line 113...
113
    uintptr_t addr = NULL;
113
    uintptr_t addr = NULL;
114
    char *hint;
114
    char *hint;
115
    int i;
115
    int i;
116
 
116
 
117
    i = 0;
117
    i = 0;
118
    while ((hint=symtab_search_one(name, &i))) {
118
    while ((hint = symtab_search_one(name, &i))) {
119
        if (!strlen(hint)) {
119
        if (!strlen(hint)) {
120
            addr =  uint64_t_le2host(symbol_table[i].address_le);
120
            addr =  uint64_t_le2host(symbol_table[i].address_le);
121
            found++;
121
            found++;
122
        }
122
        }
123
        i++;
123
        i++;
Line 149... Line 149...
149
 * @param input - Search string, completes to symbol name
149
 * @param input - Search string, completes to symbol name
150
 * @returns - 0 - nothing found, 1 - success, >1 print duplicates
150
 * @returns - 0 - nothing found, 1 - success, >1 print duplicates
151
 */
151
 */
152
int symtab_compl(char *input)
152
int symtab_compl(char *input)
153
{
153
{
154
    char output[MAX_SYMBOL_NAME+1];
154
    char output[MAX_SYMBOL_NAME + 1];
155
    int startpos = 0;
155
    int startpos = 0;
156
    char *foundtxt;
156
    char *foundtxt;
157
    int found = 0;
157
    int found = 0;
158
    int i;
158
    int i;
159
    char *name = input;
159
    char *name = input;
Line 170... Line 170...
170
    output[0] = '\0';
170
    output[0] = '\0';
171
 
171
 
172
    while ((foundtxt = symtab_search_one(name, &startpos))) {
172
    while ((foundtxt = symtab_search_one(name, &startpos))) {
173
        startpos++;
173
        startpos++;
174
        if (!found)
174
        if (!found)
175
            strncpy(output, foundtxt, strlen(foundtxt)+1);
175
            strncpy(output, foundtxt, strlen(foundtxt) + 1);
176
        else {
176
        else {
177
            for (i=0; output[i] && foundtxt[i] && output[i]==foundtxt[i]; i++)
177
            for (i = 0; output[i] && foundtxt[i] &&
-
 
178
                 output[i] == foundtxt[i]; i++)
178
                ;
179
                ;
179
            output[i] = '\0';
180
            output[i] = '\0';
180
        }
181
        }
181
        found++;
182
        found++;
182
    }
183
    }