Changeset d4d8255 in mainline for kernel/generic/src/debug/symtab.c


Ignore:
Timestamp:
2016-03-09T20:01:43Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c1b8ad4
Parents:
df425da (diff), dc0e41c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~aurelio-x/helenos/kcon-devel

File:
1 edited

Legend:

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

    rdf425da rd4d8255  
    202202}
    203203
    204 /** Symtab completion
    205  *
    206  * @param input Search string, completes to symbol name
    207  * @param size  Input buffer size
    208  *
    209  * @return 0 - nothing found, 1 - success, >1 print duplicates
    210  *
    211  */
    212 int symtab_compl(char *input, size_t size, indev_t *indev)
    213 {
    214 #ifdef CONFIG_SYMTAB
    215         const char *name = input;
    216        
    217         /* Allow completion of pointers */
    218         if ((name[0] == '*') || (name[0] == '&'))
    219                 name++;
    220        
    221         /* Do not print all symbols */
    222         if (str_length(name) == 0)
    223                 return 0;
    224        
    225         size_t found = 0;
    226         size_t pos = 0;
    227         const char *hint;
    228         char output[MAX_SYMBOL_NAME];
    229        
    230         /*
    231          * Maximum Match Length: Length of longest matching common substring in
    232          * case more than one match is found.
    233          */
    234         size_t max_match_len = size;
    235         size_t max_match_len_tmp = size;
    236         size_t input_len = str_length(input);
    237         char *sym_name;
    238         size_t hints_to_show = MAX_TAB_HINTS - 1;
    239         size_t total_hints_shown = 0;
    240         bool continue_showing_hints = true;
    241        
    242         output[0] = 0;
    243        
    244         while ((hint = symtab_search_one(name, &pos)))
    245                 pos++;
    246        
    247         pos = 0;
    248        
    249         while ((hint = symtab_search_one(name, &pos))) {
    250                 if ((found == 0) || (str_length(output) > str_length(hint)))
    251                         str_cpy(output, MAX_SYMBOL_NAME, hint);
    252                
    253                 pos++;
    254                 found++;
    255         }
    256        
    257         /*
    258          * If the number of possible completions is more than MAX_TAB_HINTS,
    259          * ask the user whether to display them or not.
    260          */
    261         if (found > MAX_TAB_HINTS) {
    262                 printf("\n");
    263                 continue_showing_hints =
    264                     console_prompt_display_all_hints(indev, found);
    265         }
    266        
    267         if ((found > 1) && (str_length(output) != 0)) {
    268                 printf("\n");
    269                 pos = 0;
    270                 while (symtab_search_one(name, &pos)) {
    271                         sym_name = symbol_table[pos].symbol_name;
    272                         pos++;
    273                        
    274                         if (continue_showing_hints) {
    275                                 /* We are still showing hints */
    276                                 printf("%s\n", sym_name);
    277                                 --hints_to_show;
    278                                 ++total_hints_shown;
    279                                
    280                                 if ((hints_to_show == 0) && (total_hints_shown != found)) {
    281                                         /* Ask the user to continue */
    282                                         continue_showing_hints =
    283                                             console_prompt_more_hints(indev, &hints_to_show);
    284                                 }
    285                         }
    286                        
    287                         for (max_match_len_tmp = 0;
    288                             (output[max_match_len_tmp] ==
    289                             sym_name[input_len + max_match_len_tmp]) &&
    290                             (max_match_len_tmp < max_match_len); ++max_match_len_tmp);
    291                        
    292                         max_match_len = max_match_len_tmp;
     204/** Symtab completion enum, see kernel/generic/include/kconsole.h */
     205const char* symtab_hints_enum(const char *input, const char **help,
     206    void **ctx)
     207{
     208#ifdef CONFIG_SYMTAB
     209        size_t len = str_length(input);
     210        struct symtab_entry **entry = (struct symtab_entry**)ctx;
     211       
     212        if (*entry == NULL)
     213                *entry = symbol_table;
     214       
     215        for (; (*entry)->address_le; (*entry)++) {
     216                const char *curname = (*entry)->symbol_name;
     217               
     218                /* Find a ':' in curname */
     219                const char *colon = str_chr(curname, ':');
     220                if (colon == NULL)
     221                        continue;
     222               
     223                if (str_length(curname) < len)
     224                        continue;
     225               
     226                if (str_lcmp(input, curname, len) == 0) {
     227                        (*entry)++;
     228                        if (help)
     229                                *help = NULL;
     230                        return (curname + str_lsize(curname, len));
    293231                }
    294                
    295                 /* Keep only the characters common in all completions */
    296                 output[max_match_len] = 0;
    297         }
    298        
    299         if (found > 0)
    300                 str_cpy(input, size, output);
    301        
    302         return found;
    303        
    304 #else
    305         return 0;
     232        }
     233       
     234        return NULL;
     235       
     236#else
     237        return NULL;
    306238#endif
    307239}
Note: See TracChangeset for help on using the changeset viewer.