Skip to content

Commit 263e70b

Browse files
committed
kconfig: add a function to dump all menu entries in a tree-like format
This is useful for debugging purposes. menu_finalize() re-parents menu entries, and this function can be used to dump the final structure of the menu tree. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 6505648 commit 263e70b

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

scripts/kconfig/lkc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct menu *menu_get_menu_or_parent_menu(struct menu *menu);
102102
int get_jump_key_char(void);
103103
struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head);
104104
void menu_get_ext_help(struct menu *menu, struct gstr *help);
105+
void menu_dump(void);
105106

106107
/* symbol.c */
107108
void sym_clear_all_valid(void);

scripts/kconfig/menu.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,3 +788,77 @@ void menu_get_ext_help(struct menu *menu, struct gstr *help)
788788
if (sym)
789789
get_symbol_str(help, sym, NULL);
790790
}
791+
792+
/**
793+
* menu_dump - dump all menu entries in a tree-like format
794+
*/
795+
void menu_dump(void)
796+
{
797+
struct menu *menu = &rootmenu;
798+
unsigned long long bits = 0;
799+
int indent = 0;
800+
801+
while (menu) {
802+
803+
for (int i = indent - 1; i >= 0; i--) {
804+
if (bits & (1ULL << i)) {
805+
if (i > 0)
806+
printf("| ");
807+
else
808+
printf("|-- ");
809+
} else {
810+
if (i > 0)
811+
printf(" ");
812+
else
813+
printf("`-- ");
814+
}
815+
}
816+
817+
switch (menu->type) {
818+
case M_CHOICE:
819+
printf("choice \"%s\"\n", menu->prompt->text);
820+
break;
821+
case M_COMMENT:
822+
printf("comment \"%s\"\n", menu->prompt->text);
823+
break;
824+
case M_IF:
825+
printf("if\n");
826+
break;
827+
case M_MENU:
828+
printf("menu \"%s\"", menu->prompt->text);
829+
if (!menu->sym) {
830+
printf("\n");
831+
break;
832+
}
833+
printf(" + ");
834+
/* fallthrough */
835+
case M_NORMAL:
836+
printf("symbol %s\n", menu->sym->name);
837+
break;
838+
}
839+
if (menu->list) {
840+
bits <<= 1;
841+
menu = menu->list;
842+
if (menu->next)
843+
bits |= 1;
844+
else
845+
bits &= ~1;
846+
indent++;
847+
continue;
848+
}
849+
850+
while (menu && !menu->next) {
851+
menu = menu->parent;
852+
bits >>= 1;
853+
indent--;
854+
}
855+
856+
if (menu) {
857+
menu = menu->next;
858+
if (menu->next)
859+
bits |= 1;
860+
else
861+
bits &= ~1;
862+
}
863+
}
864+
}

0 commit comments

Comments
 (0)