Changeset e16e0d59 in mainline for kernel/generic/src/debug


Ignore:
Timestamp:
2009-03-17T20:33:18Z (16 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5eb90cb
Parents:
b1c8dc0
Message:

Make optionality of symbol information less intrusive per Jakub's request. Also, improve symtab function names and update their semantics.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/debug/symtab.c

    rb1c8dc0 re16e0d59  
    4242#include <arch/types.h>
    4343#include <typedefs.h>
    44 
    45 /** Return entry that seems most likely to correspond to argument.
    46  *
    47  * Return entry that seems most likely to correspond
    48  * to address passed in the argument.
    49  *
    50  * @param addr Address.
    51  *
    52  * @return Pointer to respective symbol string on success, NULL otherwise.
    53  */
    54 char * get_symtab_entry(unative_t addr)
    55 {
     44#include <errno.h>
     45
     46/** Get name of symbol that seems most likely to correspond to address.
     47 *
     48 * @param addr  Address.
     49 * @param name  Place to store pointer to the symbol name.
     50 *
     51 * @return      Zero on success or negative error code, ENOENT if not found,
     52 *              ENOTSUP if symbol table not available.
     53 */
     54int symtab_name_lookup(unative_t addr, char **name)
     55{
     56#ifdef CONFIG_SYMTAB
    5657        count_t i;
    5758
     
    6061                        break;
    6162        }
    62         if (addr >= uint64_t_le2host(symbol_table[i - 1].address_le))
    63                 return symbol_table[i - 1].symbol_name;
    64         return NULL;
    65 }
     63        if (addr >= uint64_t_le2host(symbol_table[i - 1].address_le)) {
     64                *name = symbol_table[i - 1].symbol_name;
     65                return EOK;
     66        }
     67
     68        *name = 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 */
     86char *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";
     96        }
     97}
     98
     99#ifdef CONFIG_SYMTAB
    66100
    67101/** Find symbols that match the parameter forward and print them.
     
    103137}
    104138
     139#endif
     140
    105141/** Return address that corresponds to the entry
    106142 *
    107143 * Search symbol table, and if there is one match, return it
    108144 *
    109  * @param name Name of the symbol
    110  * @return 0 - Not found, -1 - Duplicate symbol, other - address of symbol
    111  */
    112 uintptr_t get_symbol_addr(const char *name)
    113 {
     145 * @param name  Name of the symbol
     146 * @param addr  Place to store symbol address
     147 *
     148 * @return      Zero on success, ENOENT - not found, EOVERFLOW - duplicate
     149 *              symbol, ENOTSUP - no symbol information available.
     150 */
     151int symtab_addr_lookup(const char *name, uintptr_t *addr)
     152{
     153#ifdef CONFIG_SYMTAB
    114154        count_t found = 0;
    115         uintptr_t addr = NULL;
    116155        char *hint;
    117156        int i;
     
    120159        while ((hint = symtab_search_one(name, &i))) {
    121160                if (!strlen(hint)) {
    122                         addr =  uint64_t_le2host(symbol_table[i].address_le);
     161                        *addr =  uint64_t_le2host(symbol_table[i].address_le);
    123162                        found++;
    124163                }
     
    126165        }
    127166        if (found > 1)
    128                 return ((uintptr_t) -1);
    129         return addr;
     167                return EOVERFLOW;
     168        if (found < 1)
     169                return ENOENT;
     170        return EOK;
     171#else
     172        return ENOTSUP;
     173#endif
    130174}
    131175
     
    133177void symtab_print_search(const char *name)
    134178{
     179#ifdef CONFIG_SYMTAB
    135180        int i;
    136181        uintptr_t addr;
     
    145190                i++;
    146191        }
     192#else
     193        printf("No symbol information available.\n");
     194#endif
    147195}
    148196
     
    154202int symtab_compl(char *input)
    155203{
     204#ifdef CONFIG_SYMTAB
    156205        char output[MAX_SYMBOL_NAME + 1];
    157206        int startpos = 0;
     
    197246        strncpy(input, output, MAX_SYMBOL_NAME);
    198247        return found;
    199        
     248#else
     249        return 0;
     250#endif
    200251}
    201252
Note: See TracChangeset for help on using the changeset viewer.