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