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