Rev 1264 | Rev 1705 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1264 | Rev 1702 | ||
---|---|---|---|
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 |
|
- | 37 | * @ingroup debug |
|
- | 38 | * @{ |
|
- | 39 | */ |
|
- | 40 | ||
29 | /** |
41 | /** |
30 | * @file symtab.c |
42 | * @file |
31 | * @brief Kernel symbol resolver. |
43 | * @brief Kernel symbol resolver. |
32 | */ |
44 | */ |
33 | 45 | ||
34 | #include <symtab.h> |
46 | #include <symtab.h> |
35 | #include <typedefs.h> |
47 | #include <typedefs.h> |
36 | #include <arch/byteorder.h> |
48 | #include <arch/byteorder.h> |
37 | #include <func.h> |
49 | #include <func.h> |
38 | #include <print.h> |
50 | #include <print.h> |
39 | 51 | ||
40 | /** Return entry that seems most likely to correspond to argument. |
52 | /** Return entry that seems most likely to correspond to argument. |
41 | * |
53 | * |
42 | * Return entry that seems most likely to correspond |
54 | * Return entry that seems most likely to correspond |
43 | * to address passed in the argument. |
55 | * to address passed in the argument. |
44 | * |
56 | * |
45 | * @param addr Address. |
57 | * @param addr Address. |
46 | * |
58 | * |
47 | * @return Pointer to respective symbol string on success, NULL otherwise. |
59 | * @return Pointer to respective symbol string on success, NULL otherwise. |
48 | */ |
60 | */ |
49 | char * get_symtab_entry(__native addr) |
61 | char * get_symtab_entry(__native addr) |
50 | { |
62 | { |
51 | count_t i; |
63 | count_t i; |
52 | 64 | ||
53 | for (i=1;symbol_table[i].address_le;++i) { |
65 | for (i=1;symbol_table[i].address_le;++i) { |
54 | if (addr < __u64_le2host(symbol_table[i].address_le)) |
66 | if (addr < __u64_le2host(symbol_table[i].address_le)) |
55 | break; |
67 | break; |
56 | } |
68 | } |
57 | if (addr >= __u64_le2host(symbol_table[i-1].address_le)) |
69 | if (addr >= __u64_le2host(symbol_table[i-1].address_le)) |
58 | return symbol_table[i-1].symbol_name; |
70 | return symbol_table[i-1].symbol_name; |
59 | return NULL; |
71 | return NULL; |
60 | } |
72 | } |
61 | 73 | ||
62 | /** Find symbols that match the parameter forward and print them. |
74 | /** Find symbols that match the parameter forward and print them. |
63 | * |
75 | * |
64 | * @param name - search string |
76 | * @param name - search string |
65 | * @param startpos - starting position, changes to found position |
77 | * @param startpos - starting position, changes to found position |
66 | * @return Pointer to the part of string that should be completed or NULL |
78 | * @return Pointer to the part of string that should be completed or NULL |
67 | */ |
79 | */ |
68 | static char * symtab_search_one(const char *name, int *startpos) |
80 | static char * symtab_search_one(const char *name, int *startpos) |
69 | { |
81 | { |
70 | int namelen = strlen(name); |
82 | int namelen = strlen(name); |
71 | char *curname; |
83 | char *curname; |
72 | int i,j; |
84 | int i,j; |
73 | int colonoffset = -1; |
85 | int colonoffset = -1; |
74 | 86 | ||
75 | for (i=0;name[i];i++) |
87 | for (i=0;name[i];i++) |
76 | if (name[i] == ':') { |
88 | if (name[i] == ':') { |
77 | colonoffset = i; |
89 | colonoffset = i; |
78 | break; |
90 | break; |
79 | } |
91 | } |
80 | 92 | ||
81 | for (i=*startpos;symbol_table[i].address_le;++i) { |
93 | for (i=*startpos;symbol_table[i].address_le;++i) { |
82 | /* Find a ':' in name */ |
94 | /* Find a ':' in name */ |
83 | curname = symbol_table[i].symbol_name; |
95 | curname = symbol_table[i].symbol_name; |
84 | for (j=0; curname[j] && curname[j] != ':'; j++) |
96 | for (j=0; curname[j] && curname[j] != ':'; j++) |
85 | ; |
97 | ; |
86 | if (!curname[j]) |
98 | if (!curname[j]) |
87 | continue; |
99 | continue; |
88 | j -= colonoffset; |
100 | j -= colonoffset; |
89 | curname += j; |
101 | curname += j; |
90 | if (strlen(curname) < namelen) |
102 | if (strlen(curname) < namelen) |
91 | continue; |
103 | continue; |
92 | if (strncmp(curname, name, namelen) == 0) { |
104 | if (strncmp(curname, name, namelen) == 0) { |
93 | *startpos = i; |
105 | *startpos = i; |
94 | return curname+namelen; |
106 | return curname+namelen; |
95 | } |
107 | } |
96 | } |
108 | } |
97 | return NULL; |
109 | return NULL; |
98 | } |
110 | } |
99 | 111 | ||
100 | /** Return address that corresponds to the entry |
112 | /** Return address that corresponds to the entry |
101 | * |
113 | * |
102 | * Search symbol table, and if there is one match, return it |
114 | * Search symbol table, and if there is one match, return it |
103 | * |
115 | * |
104 | * @param name Name of the symbol |
116 | * @param name Name of the symbol |
105 | * @return 0 - Not found, -1 - Duplicate symbol, other - address of symbol |
117 | * @return 0 - Not found, -1 - Duplicate symbol, other - address of symbol |
106 | */ |
118 | */ |
107 | __address get_symbol_addr(const char *name) |
119 | __address get_symbol_addr(const char *name) |
108 | { |
120 | { |
109 | count_t found = 0; |
121 | count_t found = 0; |
110 | __address addr = NULL; |
122 | __address addr = NULL; |
111 | char *hint; |
123 | char *hint; |
112 | int i; |
124 | int i; |
113 | 125 | ||
114 | i = 0; |
126 | i = 0; |
115 | while ((hint=symtab_search_one(name, &i))) { |
127 | while ((hint=symtab_search_one(name, &i))) { |
116 | if (!strlen(hint)) { |
128 | if (!strlen(hint)) { |
117 | addr = __u64_le2host(symbol_table[i].address_le); |
129 | addr = __u64_le2host(symbol_table[i].address_le); |
118 | found++; |
130 | found++; |
119 | } |
131 | } |
120 | i++; |
132 | i++; |
121 | } |
133 | } |
122 | if (found > 1) |
134 | if (found > 1) |
123 | return ((__address) -1); |
135 | return ((__address) -1); |
124 | return addr; |
136 | return addr; |
125 | } |
137 | } |
126 | 138 | ||
127 | /** Find symbols that match parameter and prints them */ |
139 | /** Find symbols that match parameter and prints them */ |
128 | void symtab_print_search(const char *name) |
140 | void symtab_print_search(const char *name) |
129 | { |
141 | { |
130 | int i; |
142 | int i; |
131 | __address addr; |
143 | __address addr; |
132 | char *realname; |
144 | char *realname; |
133 | 145 | ||
134 | 146 | ||
135 | i = 0; |
147 | i = 0; |
136 | while (symtab_search_one(name, &i)) { |
148 | while (symtab_search_one(name, &i)) { |
137 | addr = __u64_le2host(symbol_table[i].address_le); |
149 | addr = __u64_le2host(symbol_table[i].address_le); |
138 | realname = symbol_table[i].symbol_name; |
150 | realname = symbol_table[i].symbol_name; |
139 | printf("%.*p: %s\n", sizeof(__address) * 2, addr, realname); |
151 | printf("%.*p: %s\n", sizeof(__address) * 2, addr, realname); |
140 | i++; |
152 | i++; |
141 | } |
153 | } |
142 | } |
154 | } |
143 | 155 | ||
144 | /** Symtab completion |
156 | /** Symtab completion |
145 | * |
157 | * |
146 | * @param input - Search string, completes to symbol name |
158 | * @param input - Search string, completes to symbol name |
147 | * @returns - 0 - nothing found, 1 - success, >1 print duplicates |
159 | * @returns - 0 - nothing found, 1 - success, >1 print duplicates |
148 | */ |
160 | */ |
149 | int symtab_compl(char *input) |
161 | int symtab_compl(char *input) |
150 | { |
162 | { |
151 | char output[MAX_SYMBOL_NAME+1]; |
163 | char output[MAX_SYMBOL_NAME+1]; |
152 | int startpos = 0; |
164 | int startpos = 0; |
153 | char *foundtxt; |
165 | char *foundtxt; |
154 | int found = 0; |
166 | int found = 0; |
155 | int i; |
167 | int i; |
156 | char *name = input; |
168 | char *name = input; |
157 | 169 | ||
158 | /* Allow completion of pointers */ |
170 | /* Allow completion of pointers */ |
159 | if (name[0] == '*' || name[0] == '&') |
171 | if (name[0] == '*' || name[0] == '&') |
160 | name++; |
172 | name++; |
161 | 173 | ||
162 | /* Do not print everything */ |
174 | /* Do not print everything */ |
163 | if (!strlen(name)) |
175 | if (!strlen(name)) |
164 | return 0; |
176 | return 0; |
165 | 177 | ||
166 | 178 | ||
167 | output[0] = '\0'; |
179 | output[0] = '\0'; |
168 | 180 | ||
169 | while ((foundtxt = symtab_search_one(name, &startpos))) { |
181 | while ((foundtxt = symtab_search_one(name, &startpos))) { |
170 | startpos++; |
182 | startpos++; |
171 | if (!found) |
183 | if (!found) |
172 | strncpy(output, foundtxt, strlen(foundtxt)+1); |
184 | strncpy(output, foundtxt, strlen(foundtxt)+1); |
173 | else { |
185 | else { |
174 | for (i=0; output[i] && foundtxt[i] && output[i]==foundtxt[i]; i++) |
186 | for (i=0; output[i] && foundtxt[i] && output[i]==foundtxt[i]; i++) |
175 | ; |
187 | ; |
176 | output[i] = '\0'; |
188 | output[i] = '\0'; |
177 | } |
189 | } |
178 | found++; |
190 | found++; |
179 | } |
191 | } |
180 | if (!found) |
192 | if (!found) |
181 | return 0; |
193 | return 0; |
182 | 194 | ||
183 | if (found > 1 && !strlen(output)) { |
195 | if (found > 1 && !strlen(output)) { |
184 | printf("\n"); |
196 | printf("\n"); |
185 | startpos = 0; |
197 | startpos = 0; |
186 | while ((foundtxt = symtab_search_one(name, &startpos))) { |
198 | while ((foundtxt = symtab_search_one(name, &startpos))) { |
187 | printf("%s\n", symbol_table[startpos].symbol_name); |
199 | printf("%s\n", symbol_table[startpos].symbol_name); |
188 | startpos++; |
200 | startpos++; |
189 | } |
201 | } |
190 | } |
202 | } |
191 | strncpy(input, output, MAX_SYMBOL_NAME); |
203 | strncpy(input, output, MAX_SYMBOL_NAME); |
192 | return found; |
204 | return found; |
193 | 205 | ||
194 | } |
206 | } |
- | 207 | ||
- | 208 | /** @} |
|
- | 209 | */ |
|
- | 210 | ||
195 | 211 |