source: mainline/kernel/generic/src/debug/symtab.c@ 3061bc1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3061bc1 was b7fd2a0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Use errno_t in all uspace and kernel code.

Change type of every variable, parameter and return value that holds an
<errno.h> constant to either errno_t (the usual case), or sys_errno_t
(some places in kernel). This is for the purpose of self-documentation,
as well as for type-checking with a bit of type definition hackery.

Although this is a massive commit, it is a simple text replacement, and thus
is very easy to verify. Simply do the following:

`
git checkout <this commit's hash>
git reset HEAD
git add .
tools/srepl '\berrno_t\b' int
git add .
tools/srepl '\bsys_errno_t\b' sysarg_t
git reset
git diff
`

While this doesn't ensure that the replacements are correct, it does ensure
that the commit doesn't do anything except those replacements. Since errno_t
is typedef'd to int in the usual case (and sys_errno_t to sysarg_t), even if
incorrect, this commit cannot change behavior.

  • Property mode set to 100644
File size: 5.8 KB
RevLine 
[ab08b42]1/*
[df4ed85]2 * Copyright (c) 2005 Ondrej Palkovsky
[ab08b42]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
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
15 * derived from this software without specific prior written permission.
16 *
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
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
[06e1e95]29/** @addtogroup genericdebug
[b45c443]30 * @{
31 */
32
[cf26ba9]33/**
[b45c443]34 * @file
[68ad9d2]35 * @brief Kernel symbol resolver.
[cf26ba9]36 */
[ab08b42]37
38#include <symtab.h>
[5d494b3]39#include <byteorder.h>
[19f857a]40#include <str.h>
[6e716a59]41#include <print.h>
[d99c1d2]42#include <typedefs.h>
[e16e0d59]43#include <errno.h>
[f0d7bd9]44#include <console/prompt.h>
[ab08b42]45
[68ad9d2]46/** Get name of a symbol that seems most likely to correspond to address.
[ab08b42]47 *
[c19aa612]48 * @param addr Address.
49 * @param name Place to store pointer to the symbol name.
50 * @param offset Place to store offset from the symbol address.
[68ad9d2]51 *
[cde999a]52 * @return Zero on success or an error code, ENOENT if not found,
[68ad9d2]53 * ENOTSUP if symbol table not available.
[a783ca4]54 *
[ab08b42]55 */
[b7fd2a0]56errno_t symtab_name_lookup(uintptr_t addr, const char **name, uintptr_t *offset)
[ab08b42]57{
[e16e0d59]58#ifdef CONFIG_SYMTAB
[98000fb]59 size_t i;
[68ad9d2]60
61 for (i = 1; symbol_table[i].address_le; i++) {
[7f1c620]62 if (addr < uint64_t_le2host(symbol_table[i].address_le))
[ab08b42]63 break;
64 }
[68ad9d2]65
[e16e0d59]66 if (addr >= uint64_t_le2host(symbol_table[i - 1].address_le)) {
67 *name = symbol_table[i - 1].symbol_name;
[0dee005]68 if (offset)
69 *offset = addr -
70 uint64_t_le2host(symbol_table[i - 1].address_le);
[e16e0d59]71 return EOK;
72 }
[68ad9d2]73
[e16e0d59]74 *name = NULL;
75 return ENOENT;
[68ad9d2]76
[e16e0d59]77#else
78 *name = NULL;
79 return ENOTSUP;
80#endif
81}
82
83/** Lookup symbol by address and format for display.
84 *
[c19aa612]85 * Returns name of closest corresponding symbol,
86 * "unknown" if none exists and "N/A" if no symbol
87 * information is available.
[e16e0d59]88 *
[68ad9d2]89 * @param addr Address.
90 * @param name Place to store pointer to the symbol name.
91 *
92 * @return Pointer to a human-readable string.
[e16e0d59]93 *
94 */
[a000878c]95const char *symtab_fmt_name_lookup(uintptr_t addr)
[e16e0d59]96{
[a000878c]97 const char *name;
[b7fd2a0]98 errno_t rc = symtab_name_lookup(addr, &name, NULL);
[68ad9d2]99
[e16e0d59]100 switch (rc) {
[68ad9d2]101 case EOK:
102 return name;
103 case ENOENT:
[c19aa612]104 return "unknown";
[68ad9d2]105 default:
106 return "N/A";
[e16e0d59]107 }
[ab08b42]108}
[6e716a59]109
[e16e0d59]110#ifdef CONFIG_SYMTAB
111
[cf26ba9]112/** Find symbols that match the parameter forward and print them.
[0c8e692]113 *
[68ad9d2]114 * @param name Search string
115 * @param startpos Starting position, changes to found position
116 *
117 * @return Pointer to the part of string that should be completed or NULL.
118 *
[0c8e692]119 */
[98000fb]120static const char *symtab_search_one(const char *name, size_t *startpos)
[0c8e692]121{
[98000fb]122 size_t namelen = str_length(name);
[68ad9d2]123
[98000fb]124 size_t pos;
[68ad9d2]125 for (pos = *startpos; symbol_table[pos].address_le; pos++) {
126 const char *curname = symbol_table[pos].symbol_name;
127
[37c312a]128 /* Find a ':' in curname */
[68ad9d2]129 const char *colon = str_chr(curname, ':');
130 if (colon == NULL)
[0c8e692]131 continue;
[68ad9d2]132
133 if (str_length(curname) < namelen)
[0c8e692]134 continue;
[68ad9d2]135
136 if (str_lcmp(name, curname, namelen) == 0) {
137 *startpos = pos;
138 return (curname + str_lsize(curname, namelen));
[0c8e692]139 }
140 }
[68ad9d2]141
[0c8e692]142 return NULL;
143}
144
[e16e0d59]145#endif
146
[68ad9d2]147/** Return address that corresponds to the entry.
[6e716a59]148 *
[0c8e692]149 * Search symbol table, and if there is one match, return it
[6e716a59]150 *
[68ad9d2]151 * @param name Name of the symbol
152 * @param addr Place to store symbol address
153 *
154 * @return Zero on success, ENOENT - not found, EOVERFLOW - duplicate
155 * symbol, ENOTSUP - no symbol information available.
[e16e0d59]156 *
[6e716a59]157 */
[b7fd2a0]158errno_t symtab_addr_lookup(const char *name, uintptr_t *addr)
[6e716a59]159{
[e16e0d59]160#ifdef CONFIG_SYMTAB
[98000fb]161 size_t found = 0;
162 size_t pos = 0;
[68ad9d2]163 const char *hint;
164
165 while ((hint = symtab_search_one(name, &pos))) {
166 if (str_length(hint) == 0) {
167 *addr = uint64_t_le2host(symbol_table[pos].address_le);
[6e716a59]168 found++;
169 }
[68ad9d2]170 pos++;
[6e716a59]171 }
[68ad9d2]172
[0c8e692]173 if (found > 1)
[e16e0d59]174 return EOVERFLOW;
[68ad9d2]175
[e16e0d59]176 if (found < 1)
177 return ENOENT;
[68ad9d2]178
[e16e0d59]179 return EOK;
[68ad9d2]180
[e16e0d59]181#else
182 return ENOTSUP;
183#endif
[6e716a59]184}
185
[68ad9d2]186/** Find symbols that match parameter and print them */
[6e716a59]187void symtab_print_search(const char *name)
188{
[e16e0d59]189#ifdef CONFIG_SYMTAB
[98000fb]190 size_t pos = 0;
[68ad9d2]191 while (symtab_search_one(name, &pos)) {
192 uintptr_t addr = uint64_t_le2host(symbol_table[pos].address_le);
193 char *realname = symbol_table[pos].symbol_name;
[7e752b2]194 printf("%p: %s\n", (void *) addr, realname);
[68ad9d2]195 pos++;
[0c8e692]196 }
[68ad9d2]197
[e16e0d59]198#else
199 printf("No symbol information available.\n");
200#endif
[0c8e692]201}
202
[a363016]203/** Symtab completion enum, see kernel/generic/include/kconsole.h */
204const char* symtab_hints_enum(const char *input, const char **help,
205 void **ctx)
[0c8e692]206{
[e16e0d59]207#ifdef CONFIG_SYMTAB
[a363016]208 size_t len = str_length(input);
209 struct symtab_entry **entry = (struct symtab_entry**)ctx;
[e435537]210
[a363016]211 if (*entry == NULL)
212 *entry = symbol_table;
[68ad9d2]213
[a363016]214 for (; (*entry)->address_le; (*entry)++) {
215 const char *curname = (*entry)->symbol_name;
[68ad9d2]216
[a363016]217 /* Find a ':' in curname */
218 const char *colon = str_chr(curname, ':');
219 if (colon == NULL)
220 continue;
221
222 if (str_length(curname) < len)
223 continue;
[e435537]224
[a363016]225 if (str_lcmp(input, curname, len) == 0) {
226 (*entry)++;
227 if (help)
228 *help = NULL;
229 return (curname + str_lsize(curname, len));
230 }
[6e716a59]231 }
[68ad9d2]232
[a363016]233 return NULL;
[68ad9d2]234
[e16e0d59]235#else
[a363016]236 return NULL;
[e16e0d59]237#endif
[6e716a59]238}
[b45c443]239
[06e1e95]240/** @}
[b45c443]241 */
Note: See TracBrowser for help on using the repository browser.