Rev 2787 | Rev 4377 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2787 | Rev 2925 | ||
---|---|---|---|
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 <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 | * |
45 | * Return entry that seems most likely to correspond |
45 | * Return entry that seems most likely to correspond |
46 | * to address passed in the argument. |
46 | * to address passed in the argument. |
47 | * |
47 | * |
48 | * @param addr Address. |
48 | * @param addr Address. |
49 | * |
49 | * |
50 | * @return Pointer to respective symbol string on success, NULL otherwise. |
50 | * @return Pointer to respective symbol string on success, NULL otherwise. |
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 | * |
67 | * @param name - search string |
67 | * @param name - search string |
68 | * @param startpos - starting position, changes to found position |
68 | * @param startpos - starting position, changes to found position |
69 | * @return Pointer to the part of string that should be completed or NULL |
69 | * @return Pointer to the part of string that should be completed or NULL |
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 | ||
103 | /** Return address that corresponds to the entry |
103 | /** Return address that corresponds to the entry |
104 | * |
104 | * |
105 | * Search symbol table, and if there is one match, return it |
105 | * Search symbol table, and if there is one match, return it |
106 | * |
106 | * |
107 | * @param name Name of the symbol |
107 | * @param name Name of the symbol |
108 | * @return 0 - Not found, -1 - Duplicate symbol, other - address of symbol |
108 | * @return 0 - Not found, -1 - Duplicate symbol, other - address of symbol |
109 | */ |
109 | */ |
110 | uintptr_t get_symbol_addr(const char *name) |
110 | uintptr_t get_symbol_addr(const char *name) |
111 | { |
111 | { |
112 | count_t found = 0; |
112 | count_t found = 0; |
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++; |
124 | } |
124 | } |
125 | if (found > 1) |
125 | if (found > 1) |
126 | return ((uintptr_t) -1); |
126 | return ((uintptr_t) -1); |
127 | return addr; |
127 | return addr; |
128 | } |
128 | } |
129 | 129 | ||
130 | /** Find symbols that match parameter and prints them */ |
130 | /** Find symbols that match parameter and prints them */ |
131 | void symtab_print_search(const char *name) |
131 | void symtab_print_search(const char *name) |
132 | { |
132 | { |
133 | int i; |
133 | int i; |
134 | uintptr_t addr; |
134 | uintptr_t addr; |
135 | char *realname; |
135 | char *realname; |
136 | 136 | ||
137 | 137 | ||
138 | i = 0; |
138 | i = 0; |
139 | while (symtab_search_one(name, &i)) { |
139 | while (symtab_search_one(name, &i)) { |
140 | addr = uint64_t_le2host(symbol_table[i].address_le); |
140 | addr = uint64_t_le2host(symbol_table[i].address_le); |
141 | realname = symbol_table[i].symbol_name; |
141 | realname = symbol_table[i].symbol_name; |
142 | printf("%.*p: %s\n", sizeof(uintptr_t) * 2, addr, realname); |
142 | printf("%.*p: %s\n", sizeof(uintptr_t) * 2, addr, realname); |
143 | i++; |
143 | i++; |
144 | } |
144 | } |
145 | } |
145 | } |
146 | 146 | ||
147 | /** Symtab completion |
147 | /** Symtab completion |
148 | * |
148 | * |
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; |
160 | 160 | ||
161 | /* Allow completion of pointers */ |
161 | /* Allow completion of pointers */ |
162 | if (name[0] == '*' || name[0] == '&') |
162 | if (name[0] == '*' || name[0] == '&') |
163 | name++; |
163 | name++; |
164 | 164 | ||
165 | /* Do not print everything */ |
165 | /* Do not print everything */ |
166 | if (!strlen(name)) |
166 | if (!strlen(name)) |
167 | return 0; |
167 | return 0; |
168 | 168 | ||
169 | 169 | ||
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 | } |
183 | if (!found) |
184 | if (!found) |
184 | return 0; |
185 | return 0; |
185 | 186 | ||
186 | if (found > 1 && !strlen(output)) { |
187 | if (found > 1 && !strlen(output)) { |
187 | printf("\n"); |
188 | printf("\n"); |
188 | startpos = 0; |
189 | startpos = 0; |
189 | while ((foundtxt = symtab_search_one(name, &startpos))) { |
190 | while ((foundtxt = symtab_search_one(name, &startpos))) { |
190 | printf("%s\n", symbol_table[startpos].symbol_name); |
191 | printf("%s\n", symbol_table[startpos].symbol_name); |
191 | startpos++; |
192 | startpos++; |
192 | } |
193 | } |
193 | } |
194 | } |
194 | strncpy(input, output, MAX_SYMBOL_NAME); |
195 | strncpy(input, output, MAX_SYMBOL_NAME); |
195 | return found; |
196 | return found; |
196 | 197 | ||
197 | } |
198 | } |
198 | 199 | ||
199 | /** @} |
200 | /** @} |
200 | */ |
201 | */ |
201 | 202 |