Rev 4055 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4055 | Rev 4156 | ||
---|---|---|---|
Line 39... | Line 39... | ||
39 | #include <byteorder.h> |
39 | #include <byteorder.h> |
40 | #include <string.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 | #include <errno.h> |
|
44 | 45 | ||
45 | /** Return entry that seems most likely to correspond to argument. |
46 | /** Get name of symbol that seems most likely to correspond to address. |
46 | * |
- | |
47 | * Return entry that seems most likely to correspond |
- | |
48 | * to address passed in the argument. |
- | |
49 | * |
47 | * |
50 | * @param addr Address. |
48 | * @param addr Address. |
- | 49 | * @param name Place to store pointer to the symbol name. |
|
51 | * |
50 | * |
52 | * @return Pointer to respective symbol string on success, NULL otherwise. |
51 | * @return Zero on success or negative error code, ENOENT if not found, |
- | 52 | * ENOTSUP if symbol table not available. |
|
53 | */ |
53 | */ |
54 | char * get_symtab_entry(unative_t addr) |
54 | int symtab_name_lookup(unative_t addr, char **name) |
55 | { |
55 | { |
- | 56 | #ifdef CONFIG_SYMTAB |
|
56 | count_t i; |
57 | count_t i; |
57 | 58 | ||
58 | for (i = 1; symbol_table[i].address_le; ++i) { |
59 | for (i = 1; symbol_table[i].address_le; ++i) { |
59 | if (addr < uint64_t_le2host(symbol_table[i].address_le)) |
60 | if (addr < uint64_t_le2host(symbol_table[i].address_le)) |
60 | break; |
61 | break; |
61 | } |
62 | } |
62 | if (addr >= uint64_t_le2host(symbol_table[i - 1].address_le)) |
63 | if (addr >= uint64_t_le2host(symbol_table[i - 1].address_le)) { |
63 | return symbol_table[i - 1].symbol_name; |
64 | *name = symbol_table[i - 1].symbol_name; |
- | 65 | return EOK; |
|
- | 66 | } |
|
- | 67 | ||
- | 68 | *name = NULL; |
|
64 | return NULL; |
69 | return ENOENT; |
- | 70 | #else |
|
- | 71 | *name = NULL; |
|
- | 72 | return ENOTSUP; |
|
- | 73 | #endif |
|
- | 74 | } |
|
- | 75 | ||
- | 76 | /** Lookup symbol by address and format for display. |
|
- | 77 | * |
|
- | 78 | * Returns name of closest corresponding symbol, "Not found" if none exists |
|
- | 79 | * or "N/A" if no symbol information is available. |
|
- | 80 | * |
|
- | 81 | * @param addr Address. |
|
- | 82 | * @param name Place to store pointer to the symbol name. |
|
- | 83 | * |
|
- | 84 | * @return Pointer to a human-readable string. |
|
- | 85 | */ |
|
- | 86 | char *symtab_fmt_name_lookup(unative_t addr) |
|
- | 87 | { |
|
- | 88 | int rc; |
|
- | 89 | char *name; |
|
- | 90 | ||
- | 91 | rc = symtab_name_lookup(addr, &name); |
|
- | 92 | switch (rc) { |
|
- | 93 | case EOK: return name; |
|
- | 94 | case ENOENT: return "Not found"; |
|
- | 95 | default: return "N/A"; |
|
65 | } |
96 | } |
- | 97 | } |
|
- | 98 | ||
- | 99 | #ifdef CONFIG_SYMTAB |
|
66 | 100 | ||
67 | /** Find symbols that match the parameter forward and print them. |
101 | /** Find symbols that match the parameter forward and print them. |
68 | * |
102 | * |
69 | * @param name - search string |
103 | * @param name - search string |
70 | * @param startpos - starting position, changes to found position |
104 | * @param startpos - starting position, changes to found position |
Line 100... | Line 134... | ||
100 | } |
134 | } |
101 | } |
135 | } |
102 | return NULL; |
136 | return NULL; |
103 | } |
137 | } |
104 | 138 | ||
- | 139 | #endif |
|
- | 140 | ||
105 | /** Return address that corresponds to the entry |
141 | /** Return address that corresponds to the entry |
106 | * |
142 | * |
107 | * Search symbol table, and if there is one match, return it |
143 | * Search symbol table, and if there is one match, return it |
108 | * |
144 | * |
109 | * @param name Name of the symbol |
145 | * @param name Name of the symbol |
- | 146 | * @param addr Place to store symbol address |
|
- | 147 | * |
|
110 | * @return 0 - Not found, -1 - Duplicate symbol, other - address of symbol |
148 | * @return Zero on success, ENOENT - not found, EOVERFLOW - duplicate |
- | 149 | * symbol, ENOTSUP - no symbol information available. |
|
111 | */ |
150 | */ |
112 | uintptr_t get_symbol_addr(const char *name) |
151 | int symtab_addr_lookup(const char *name, uintptr_t *addr) |
113 | { |
152 | { |
- | 153 | #ifdef CONFIG_SYMTAB |
|
114 | count_t found = 0; |
154 | count_t found = 0; |
115 | uintptr_t addr = NULL; |
- | |
116 | char *hint; |
155 | char *hint; |
117 | int i; |
156 | int i; |
118 | 157 | ||
119 | i = 0; |
158 | i = 0; |
120 | while ((hint = symtab_search_one(name, &i))) { |
159 | while ((hint = symtab_search_one(name, &i))) { |
121 | if (!strlen(hint)) { |
160 | if (!strlen(hint)) { |
122 | addr = uint64_t_le2host(symbol_table[i].address_le); |
161 | *addr = uint64_t_le2host(symbol_table[i].address_le); |
123 | found++; |
162 | found++; |
124 | } |
163 | } |
125 | i++; |
164 | i++; |
126 | } |
165 | } |
127 | if (found > 1) |
166 | if (found > 1) |
128 | return ((uintptr_t) -1); |
167 | return EOVERFLOW; |
- | 168 | if (found < 1) |
|
- | 169 | return ENOENT; |
|
129 | return addr; |
170 | return EOK; |
- | 171 | #else |
|
- | 172 | return ENOTSUP; |
|
- | 173 | #endif |
|
130 | } |
174 | } |
131 | 175 | ||
132 | /** Find symbols that match parameter and prints them */ |
176 | /** Find symbols that match parameter and prints them */ |
133 | void symtab_print_search(const char *name) |
177 | void symtab_print_search(const char *name) |
134 | { |
178 | { |
- | 179 | #ifdef CONFIG_SYMTAB |
|
135 | int i; |
180 | int i; |
136 | uintptr_t addr; |
181 | uintptr_t addr; |
137 | char *realname; |
182 | char *realname; |
138 | 183 | ||
139 | 184 | ||
Line 142... | Line 187... | ||
142 | addr = uint64_t_le2host(symbol_table[i].address_le); |
187 | addr = uint64_t_le2host(symbol_table[i].address_le); |
143 | realname = symbol_table[i].symbol_name; |
188 | realname = symbol_table[i].symbol_name; |
144 | printf("%p: %s\n", addr, realname); |
189 | printf("%p: %s\n", addr, realname); |
145 | i++; |
190 | i++; |
146 | } |
191 | } |
- | 192 | #else |
|
- | 193 | printf("No symbol information available.\n"); |
|
- | 194 | #endif |
|
147 | } |
195 | } |
148 | 196 | ||
149 | /** Symtab completion |
197 | /** Symtab completion |
150 | * |
198 | * |
151 | * @param input - Search string, completes to symbol name |
199 | * @param input - Search string, completes to symbol name |
152 | * @returns - 0 - nothing found, 1 - success, >1 print duplicates |
200 | * @returns - 0 - nothing found, 1 - success, >1 print duplicates |
153 | */ |
201 | */ |
154 | int symtab_compl(char *input) |
202 | int symtab_compl(char *input) |
155 | { |
203 | { |
- | 204 | #ifdef CONFIG_SYMTAB |
|
156 | char output[MAX_SYMBOL_NAME + 1]; |
205 | char output[MAX_SYMBOL_NAME + 1]; |
157 | int startpos = 0; |
206 | int startpos = 0; |
158 | char *foundtxt; |
207 | char *foundtxt; |
159 | int found = 0; |
208 | int found = 0; |
160 | int i; |
209 | int i; |
Line 194... | Line 243... | ||
194 | startpos++; |
243 | startpos++; |
195 | } |
244 | } |
196 | } |
245 | } |
197 | strncpy(input, output, MAX_SYMBOL_NAME); |
246 | strncpy(input, output, MAX_SYMBOL_NAME); |
198 | return found; |
247 | return found; |
199 | 248 | #else |
|
- | 249 | return 0; |
|
- | 250 | #endif |
|
200 | } |
251 | } |
201 | 252 | ||
202 | /** @} |
253 | /** @} |
203 | */ |
254 | */ |