Changeset f0348c8 in mainline for kernel/generic


Ignore:
Timestamp:
2012-07-10T13:03:10Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
97c7682, 9904eb90, ceafd1b, d9812b4, dfc07c1
Parents:
33fc3ae (diff), f4a8734 (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 kernel console completion and console interface clean-up

Kernel console completion (#50), thanks Sandeep Kumar

  • tab-completion uses symbol table
  • tab-completion display huge number of hints in user-friendly manner (display all?, more?)

Userspace console interface changes

  • console does not send special keys (arrows etc.) on its VFS interface
Location:
kernel/generic
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/debug.h

    r33fc3ae rf0348c8  
    3737
    3838#include <panic.h>
    39 #include <symtab.h>
     39#include <symtab_lookup.h>
    4040
    4141#define CALLER  ((uintptr_t) __builtin_return_address(0))
  • kernel/generic/include/symtab.h

    r33fc3ae rf0348c8  
    3636#define KERN_SYMTAB_H_
    3737
    38 #include <typedefs.h>
     38#include <symtab_lookup.h>
     39#include <console/chardev.h>
    3940
    40 #define MAX_SYMBOL_NAME  64
    41 
    42 struct symtab_entry {
    43         uint64_t address_le;
    44         char symbol_name[MAX_SYMBOL_NAME];
    45 };
    46 
    47 extern int symtab_name_lookup(uintptr_t, const char **, uintptr_t *);
    48 extern const char *symtab_fmt_name_lookup(uintptr_t);
    49 extern int symtab_addr_lookup(const char *, uintptr_t *);
    5041extern void symtab_print_search(const char *);
    51 extern int symtab_compl(char *, size_t);
    52 
    53 #ifdef CONFIG_SYMTAB
    54 
    55 /** Symtable linked together by build process
    56  *
    57  */
    58 extern struct symtab_entry symbol_table[];
    59 
    60 #endif /* CONFIG_SYMTAB */
     42extern int symtab_compl(char *, size_t, indev_t *);
    6143
    6244#endif
  • kernel/generic/src/console/kconsole.c

    r33fc3ae rf0348c8  
    4343#include <console/chardev.h>
    4444#include <console/cmd.h>
     45#include <console/prompt.h>
    4546#include <print.h>
    4647#include <panic.h>
     
    201202 *
    202203 */
    203 NO_TRACE static int cmdtab_compl(char *input, size_t size)
     204NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t * indev)
    204205{
    205206        const char *name = input;
    206207       
    207208        size_t found = 0;
     209        /* Maximum Match Length : Length of longest matching common substring in
     210           case more than one match is found */
     211        size_t max_match_len = size;
     212        size_t max_match_len_tmp = size;
     213        size_t input_len = str_length(input);
    208214        link_t *pos = NULL;
    209215        const char *hint;
    210216        char *output = malloc(MAX_CMDLINE, 0);
     217        size_t hints_to_show = MAX_TAB_HINTS - 1;
     218        size_t total_hints_shown = 0;
     219        bool continue_showing_hints = true;
    211220       
    212221        output[0] = 0;
     
    218227                pos = pos->next;
    219228                found++;
     229        }
     230       
     231        /* If possible completions are more than MAX_TAB_HINTS, ask user whether to display them or not. */
     232        if (found > MAX_TAB_HINTS) {
     233                printf("\n");
     234                continue_showing_hints = console_prompt_display_all_hints(indev, found);
    220235        }
    221236       
     
    225240                while (cmdtab_search_one(name, &pos)) {
    226241                        cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link);
    227                         printf("%s (%s)\n", hlp->name, hlp->description);
     242
     243                        if (continue_showing_hints) {
     244                                printf("%s (%s)\n", hlp->name, hlp->description);
     245                                --hints_to_show;
     246                                ++total_hints_shown;
     247
     248                                if (hints_to_show == 0 && total_hints_shown != found) { /* Time to ask user to continue */
     249                                        continue_showing_hints = console_prompt_more_hints(indev, &hints_to_show);
     250                                }
     251                        }
     252
    228253                        pos = pos->next;
    229                 }
     254                        for(max_match_len_tmp = 0; output[max_match_len_tmp] == hlp->name[input_len + max_match_len_tmp]
     255                                        && max_match_len_tmp < max_match_len; ++max_match_len_tmp);
     256                        max_match_len = max_match_len_tmp;
     257                }
     258                /* keep only the characters common in all completions */
     259                output[max_match_len] = 0;
    230260        }
    231261       
     
    294324                        if (beg == 0) {
    295325                                /* Command completion */
    296                                 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE));
     326                                found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev);
    297327                        } else {
    298328                                /* Symbol completion */
    299                                 found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE));
     329                                found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev);
    300330                        }
    301331                       
    302332                        if (found == 0)
    303333                                continue;
    304                        
    305                         if (found > 1) {
    306                                 /* No unique hint, list was printed */
    307                                 printf("%s> ", prompt);
    308                                 printf("%ls", current);
    309                                 print_cc('\b', wstr_length(current) - position);
    310                                 continue;
    311                         }
    312                        
    313                         /* We have a hint */
    314                        
     334
     335                        /* We have hints, may be many. In case of more than one hint,
     336                           tmp will contain the common prefix. */
    315337                        size_t off = 0;
    316338                        size_t i = 0;
     
    320342                                i++;
    321343                        }
     344                       
     345                        if (found > 1) {
     346                                /* No unique hint, list was printed */
     347                                printf("%s> ", prompt);
     348                                printf("%ls", current);
     349                                position += str_length(tmp);
     350                                print_cc('\b', wstr_length(current) - position);
     351                                continue;
     352                        }
     353                       
     354                        /* We have a hint */
    322355                       
    323356                        printf("%ls", current + position);
     
    540573/** Parse command line.
    541574 *
    542  * @param cmdline Command line as read from input device. 
     575 * @param cmdline Command line as read from input device.
    543576 * @param size    Size (in bytes) of the string.
    544577 *
  • kernel/generic/src/debug/symtab.c

    r33fc3ae rf0348c8  
    4343#include <typedefs.h>
    4444#include <errno.h>
     45#include <console/prompt.h>
    4546
    4647/** Get name of a symbol that seems most likely to correspond to address.
     
    209210 *
    210211 */
    211 int symtab_compl(char *input, size_t size)
     212int symtab_compl(char *input, size_t size, indev_t * indev)
    212213{
    213214#ifdef CONFIG_SYMTAB
     
    226227        const char *hint;
    227228        char output[MAX_SYMBOL_NAME];
     229        /* Maximum Match Length : Length of longest matching common substring in
     230           case more than one match is found */
     231        size_t max_match_len = size;
     232        size_t max_match_len_tmp = size;
     233        size_t input_len = str_length(input);
     234        char *sym_name;
     235        size_t hints_to_show = MAX_TAB_HINTS - 1;
     236        size_t total_hints_shown = 0;
     237        bool continue_showing_hints = true;
    228238       
    229239        output[0] = 0;
     240
     241        while ((hint = symtab_search_one(name, &pos))) {
     242                ++pos;
     243        }
     244
     245        pos = 0;
    230246       
    231247        while ((hint = symtab_search_one(name, &pos))) {
     
    235251                pos++;
    236252                found++;
     253        }
     254       
     255        /* If possible completions are more than MAX_TAB_HINTS, ask user whether to display them or not. */
     256        if (found > MAX_TAB_HINTS) {
     257                printf("\n");
     258                continue_showing_hints = console_prompt_display_all_hints(indev, found);
    237259        }
    238260       
     
    241263                pos = 0;
    242264                while (symtab_search_one(name, &pos)) {
    243                         printf("%s\n", symbol_table[pos].symbol_name);
     265                        sym_name = symbol_table[pos].symbol_name;
    244266                        pos++;
     267
     268                        if (continue_showing_hints) { /* We are still showing hints */
     269                                printf("%s\n", sym_name);
     270                                --hints_to_show;
     271                                ++total_hints_shown;
     272
     273                                if (hints_to_show == 0 && total_hints_shown != found) { /* Time to ask user to continue */
     274                                        continue_showing_hints = console_prompt_more_hints(indev, &hints_to_show);
     275                                }
     276                        }
     277
     278                        for(max_match_len_tmp = 0; output[max_match_len_tmp] == sym_name[input_len + max_match_len_tmp]
     279                                        && max_match_len_tmp < max_match_len; ++max_match_len_tmp);
     280                        max_match_len = max_match_len_tmp;
    245281                }
     282                /* keep only the characters common in all completions */
     283                output[max_match_len] = 0;
    246284        }
    247285       
Note: See TracChangeset for help on using the changeset viewer.